* install
npm install --save express --registry=https://registry.npm.taobao.org
* trigger.js
// curl -i http://172.16.0.224:8088/ -d '' // throw new Error('Can\'t set headers after they are sent.'); var express = require('express'); var app = express(); var exec = require('child_process').exec; app.all('*', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type"); res.header("Access-Control-Allow-Credentials", "true"); res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); res.header("X-Powered-By",' Express 4.17.1'); res.header("Content-Type", "application/json;charset=utf-8"); next(); }); app.post("/", function(req, res) { var cmd = "gatsby build"; exec(cmd, { cwd: "/usr/ET/project/zktWeb", timeout: 300000, }, function(err, stdout, stderr) { if (err) { return res.send({ code: 1, data: null, message: stderr }); } console.log(stdout); res.end(); }); return res.json({ code: 0, data: null, message: "success" }) }); var server = app.listen("8088", function() { var host = server.address().address; var port = server.address().port; console.log("app is listening http://%s:%d", host, port) });
* run:
sudo yum install supervisor
sudo emacs /etc/supervisord.d/zktWebTrigger.ini
[program:zktWebTrigger] command = /usr/local/node/10.16.0/bin/node /usr/ET/project/zktWeb/trigger.js directory = /usr/ET/project/zktWeb stdout_logfile = /var/local/logs/zktWebTrigger-info.log stderr_logfile = /var/local/logs/zktWebTrigger-error.log environment = PORT=8088
sudo /usr/bin/supervisorctl reload
sudo /usr/bin/supervisorctl restart zktWebTrigger
sudo lsof -i:8088
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 4889 root 19u IPv6 9476295 0t0 TCP *:radan-http (LISTEN)