functionPush(req, res, next) { /*-- 消息的解析拼接 --*/ let body = req.body; let ding = body.token; let count = body.commits.length; let whopush = body.commits[0].committer.name; let repourl = `${body.repository.owner.web_url}/p/${body.repository.name}/git/tree/${getbranch(body.ref)}`; let branch = `# [[${body.repository.name}/${getbranch(body.ref)}]](${repourl})`; let text = `${branch}${count} commit,push by ${whopush}\n ## commits:\n`; for (let i = 0; i < count; i++){ let com = body.commits[i]; let name = com.committer.name; let mes = com.short_message; let hash6 = com.sha.substring(0,6); let commit = `> </> ${name}: [[${hash6}]](${com.web_url})-${mes}\n`; text = text + commit; } console.log(text); /*-- 消息的解析拼接 --*/ // 钉钉消息格式等 body 设置 let rqbody = { msgtype: "markdown", markdown: { title:"仓库有新的代码更新咯!", text: text } }; let options = { url: ding, headers: { "Content-Type": "application/json" }, body: JSON.stringify(rqbody) // 消息体内容 }; // request 向钉钉发送消息 Webhook request.post(options, (err, res, body)=>{ if(!err && res.statusCode == 200){ let info = JSON.parse(body); console.log(info); } }); res.json({mes: 'ok'}); } functiongetbranch(str) { let arr = str.split('/'); return arr[arr.length-1]; }
-A 参数用来指定 USER-AGENGT curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17" http://localhost/learing-curl/show-server-info.php
application name (default to script filename without extension)
script
(string)
”./api/app.js”
script path relative to pm2 start
cwd
(string)
“/var/www/”
the directory from which your app will be launched
args
(string)
“-a 13 -b 12”
string containing all arguments passed via CLI to script
interpreter
(string)
“/usr/bin/python”
interpreter absolute path (default to node)
interpreter_args
(string)
”–harmony”
option to pass to the interpreter
node_args
(string)
alias to interpreter_args
Advanced features
Field
Type
Example
Description
instances
number
-1
number of app instance to be launched
exec_mode
string
“cluster”
mode to start your app, can be “cluster” or “fork”, default fork
watch
boolean or []
true
enable watch & restart feature, if a file change in the folder or subfolder, your app will get reloaded
ignore_watch
list
[”[/\]./”, “node_modules”]
list of regex to ignore some file or folder names by the watch feature
max_memory_restart
string
“150M”
your app will be restarted if it exceeds the amount of memory specified. human-friendly format : it can be “10M”, “100K”, “2G” and so on…
env
object
{“NODE_ENV”: “development”, “ID”: “42”}
env variables which will appear in your app
env_
object
{“NODE_ENV”: “production”, “ID”: “89”}
inject when doing pm2 restart app.yml –env
source_map_support
boolean
true
default to true, [enable/disable source map file]
instance_var
string
“NODE_APP_INSTANCE”
see documentation
Log files
Field
Type
Example
Description
log_date_format
(string)
“YYYY-MM-DD HH:mm Z”
log date format (see log section)
error_file
(string)
error file path
(default to $HOME/.pm2/logs/XXXerr.log)
out_file
(string)
output file path
(default to $HOME/.pm2/logs/XXXout.log)
combine_logs
boolean
true
if set to true, avoid to suffix
merge_logs
boolean
true
alias to combine_logs
pid_file
(string)
pid file path
(default to $HOME/.pm2/pid/app-pm_id.pid)
Control flow
Field
Type
Example
Description
min_uptime
(string)
min uptime of the app to be considered started
listen_timeout
number
8000
time in ms before forcing a reload if app not listening
kill_timeout
number
1600
time in milliseconds before sending a final SIGKILL
wait_ready
boolean
false
Instead of reload waiting for listen event, wait for process.send(‘ready’)
max_restarts
number
10
number of consecutive unstable restarts (less than 1sec interval or custom time via min_uptime) before your app is considered errored and stop being restarted
restart_delay
number
4000
time to wait before restarting a crashed app (in milliseconds). defaults to 0.
autorestart
boolean
false
true by default. if false, PM2 will not restart your app if it crashes or ends peacefully
cron_restart
string
“1 0 * * *”
a cron pattern to restart your app. Application must be running for cron feature to work
vizion
boolean
false
true by default. if false, PM2 will start without vizion features (versioning control metadatas)
post_update
list
[“npm install”, “echo launching the app”]
a list of commands which will be executed after you perform a Pull/Upgrade operation from Keymetrics dashboard
force
boolean
true
defaults to false. if true, you can start the same script several times which is usually not allowed by PM2