Skip to content

Instantly share code, notes, and snippets.

@akloeber
Created March 7, 2015 19:59
Show Gist options
  • Save akloeber/d18147f903353a11178b to your computer and use it in GitHub Desktop.
Save akloeber/d18147f903353a11178b to your computer and use it in GitHub Desktop.
PM2 watch issue
Running tests:
#####################
# Watch for changes #
#####################
>server-watch.js
$pm2 kill
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Stopping PM2...
[PM2] [WARN] No process found
[PM2] All processes has been stopped and deleted
[PM2] PM2 stopped
cp server-watch.bak.js server-watch.js
$pm2 start server-watch.js --watch
[PM2] Spawning PM2 daemon
[PM2] Success
[PM2] Process server-watch.js launched
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0 │ fork │ 4711 │ online │ 0 │ 0s │ 10.473 MB │ enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
Use `pm2 info <id|name>` to get more details about an app
should 'process should be watched' 'watch: true' 1
$pm2 prettylist | grep -o "$2" | wc -l
------------> ✔ process should be watched
echo "console.log('test');" >> server-watch.js
sleep 1
cat server-watch.js
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200);
res.end('hey');
}).listen(8000);
console.log('test');
$pm2 list
┌──────────────┬────┬──────┬──────┬────────┬───────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
├──────────────┼────┼──────┼──────┼────────┼───────────┼────────┼─────────────┼──────────┤
│ server-watch │ 0 │ fork │ 4711 │ online │ 0 │ 2s │ 10.473 MB │ enabled │
└──────────────┴────┴──────┴──────┴────────┴───────────┴────────┴─────────────┴──────────┘
Use `pm2 info <id|name>` to get more details about an app
should 'process should have been restarted' 'restart_time: 1' 1
$pm2 prettylist | grep -o "$2" | wc -l
######## ✘ process should have been restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment