diff --git a/webkit/Dockerfile b/webkit/Dockerfile index cd864a3..10c5c07 100644 --- a/webkit/Dockerfile +++ b/webkit/Dockerfile @@ -7,7 +7,7 @@ MAINTAINER kev RUN echo "Asia/Shanghai" > /etc/timezone RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -RUN apt-get update && apt-get install -y supervisor haproxy libfontconfig1 libfreetype6 nginx monit +RUN apt-get update && apt-get install -y supervisor haproxy libfontconfig1 libfreetype6 nginx RUN mkdir -p /data/ /webkit/includes/ ADD ./*.js /webkit/ @@ -16,7 +16,7 @@ ADD ./bin/ /usr/local/bin/ ADD ./etc/haproxy.cfg /etc/haproxy/ ADD ./etc/supervisor/supervisord.conf /etc/supervisor/ ADD ./etc/supervisor/conf.d/ /etc/supervisor/conf.d/ -ADD ./etc/monit/conf.d/ /etc/monit/conf.d/ +ADD ./etc/monitrc /etc/ ADD ./etc/nginx.cfg /etc/nginx/sites-enabled/default VOLUME /data/ diff --git a/webkit/bin/monit b/webkit/bin/monit index aa86037..06eb28b 100755 Binary files a/webkit/bin/monit and b/webkit/bin/monit differ diff --git a/webkit/client.js b/webkit/client.js index c091891..3c084de 100644 --- a/webkit/client.js +++ b/webkit/client.js @@ -188,9 +188,11 @@ function urlopen(req, callback) { case 'jpg': case 'png': case 'gif': - data = '/data/' + req.requestId; - page.render(data, {format: req.requestType}); - break; + var name = req.requestId + '.' + req.requestType; + page.render('/data/' + name, {format: req.requestType}); + result.pageCapture = name; + data = page.content; + break case 'script': data = page.evaluate(function() { return window.pjsc_output; diff --git a/webkit/etc/monit/conf.d/cleanup.cfg b/webkit/etc/monit/conf.d/cleanup.cfg deleted file mode 100644 index b323c45..0000000 --- a/webkit/etc/monit/conf.d/cleanup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -check program cleanup with path "/usr/bin/find /data -type f -cmin +60 -delete" - every 5 cycles - if status != 0 then alert diff --git a/webkit/etc/monit/conf.d/setting.cfg b/webkit/etc/monit/conf.d/setting.cfg deleted file mode 100644 index 01530d9..0000000 --- a/webkit/etc/monit/conf.d/setting.cfg +++ /dev/null @@ -1,4 +0,0 @@ -set httpd port 2812 and - use address 0.0.0.0 - allow 0.0.0.0/0 - diff --git a/webkit/etc/monit/conf.d/webkit.cfg b/webkit/etc/monitrc similarity index 59% rename from webkit/etc/monit/conf.d/webkit.cfg rename to webkit/etc/monitrc index cd6a4bf..f45e48b 100644 --- a/webkit/etc/monit/conf.d/webkit.cfg +++ b/webkit/etc/monitrc @@ -1,60 +1,87 @@ +############################################################################### +## Monit control file +############################################################################### + +############################################################################### +## Global section +############################################################################### + +set daemon 60 + with start delay 240 + +set httpd port 2812 and + use address 0.0.0.0 + allow 0.0.0.0/0 + +############################################################################### +## Service (cleanup) +############################################################################### + +check program cleanup with path "/usr/bin/find /data -type f -cmin +60 -delete" + every 5 cycles + if status != 0 then alert + +############################################################################### +## Services (webkit) +############################################################################### + check process webkit-8080 with pidfile /var/run/webkit-8080.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8080" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8081 with pidfile /var/run/webkit-8081.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8081" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8082 with pidfile /var/run/webkit-8082.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8082" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8083 with pidfile /var/run/webkit-8083.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8083" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8084 with pidfile /var/run/webkit-8084.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8084" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8085 with pidfile /var/run/webkit-8085.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8085" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8086 with pidfile /var/run/webkit-8086.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8086" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8087 with pidfile /var/run/webkit-8087.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8087" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8088 with pidfile /var/run/webkit-8088.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8088" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert check process webkit-8089 with pidfile /var/run/webkit-8089.pid restart program = "/usr/bin/supervisorctl restart webkit:webkit-8089" if uptime > 1 hour then restart - if total memory > 100 MB for 5 cycles then restart + if total memory > 50 MB for 5 cycles then restart if total cpu > 10% for 5 cycles then alert diff --git a/webkit/etc/supervisor/conf.d/monit.conf b/webkit/etc/supervisor/conf.d/monit.conf index f19052b..ab0b485 100644 --- a/webkit/etc/supervisor/conf.d/monit.conf +++ b/webkit/etc/supervisor/conf.d/monit.conf @@ -1,2 +1,2 @@ [program:monit] -command = /usr/local/bin/monit -I -c /etc/monit/monitrc +command = /usr/local/bin/monit -I -c /etc/monitrc diff --git a/webkit/parser.js b/webkit/parser.js index 3bd0cd7..c54f0e8 100644 --- a/webkit/parser.js +++ b/webkit/parser.js @@ -14,7 +14,7 @@ var setDefaults = function(req) { req.isDebug = checkBoolean('isDebug', req.isDebug, false); req.loadImages = checkBoolean('loadImages', req.loadImages, false); req.outputAsJson = checkBoolean('outputAsJson', req.outputAsJson, true); //FIXME: it is ignored - req.requestId = checkString('requestId', req.requestId, utils.guid()); + req.requestId = checkString('requestId', utils.guid()); // ignore user input req.requestType = checkString('requestType', req.requestType, 'text'); req.resourceUrlBlacklist = checkArray('resourceUrlBlacklist', req.resourceUrlBlacklist, []); //HINT: set it to ['.*\.css.*'] to block stylesheet req.resourceUrlWhitelist = checkArray('resourceUrlWhitelist', req.resourceUrlWhitelist, []); //FIXME: not implemented