{"action":"closed","issue":{"url":"https://api.github.com/repos/Unitech/PM2/issues/937","labels_url":"https://api.github.com/repos/Unitech/PM2/issues/937/labels{/name}","comments_url":"https://api.github.com/repos/Unitech/PM2/issues/937/comments","events_url":"https://api.github.com/repos/Unitech/PM2/issues/937/events","html_url":"https://github.com/Unitech/PM2/issues/937","id":54181865,"number":937,"title":"`pm2 stop` starts the god daemon","user":{"login":"jussi-kalliokoski","id":547186,"avatar_url":"https://avatars.githubusercontent.com/u/547186?v=3","gravatar_id":"","url":"https://api.github.com/users/jussi-kalliokoski","html_url":"https://github.com/jussi-kalliokoski","followers_url":"https://api.github.com/users/jussi-kalliokoski/followers","following_url":"https://api.github.com/users/jussi-kalliokoski/following{/other_user}","gists_url":"https://api.github.com/users/jussi-kalliokoski/gists{/gist_id}","starred_url":"https://api.github.com/users/jussi-kalliokoski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jussi-kalliokoski/subscriptions","organizations_url":"https://api.github.com/users/jussi-kalliokoski/orgs","repos_url":"https://api.github.com/users/jussi-kalliokoski/repos","events_url":"https://api.github.com/users/jussi-kalliokoski/events{/privacy}","received_events_url":"https://api.github.com/users/jussi-kalliokoski/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Unitech/PM2/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/Unitech/PM2/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-13T11:35:58Z","updated_at":"2015-04-29T16:53:52Z","closed_at":"2015-04-29T16:53:52Z","body":"The following reduced test case running on a Ubuntu machine (AWS EC2): https://gist.github.com/jussi-kalliokoski/ccb2e0b7708bfebb8155\r\n\r\nI get the following results:\r\n\r\n(first shell)\r\n\r\n```\r\n$ npm start\r\n\r\n> pm2-daemon-starting-on-stop@ start /home/jussi\r\n> pm2 start --no-daemon -x --name $npm_package_name $npm_package_main\r\n\r\npm2 launched in no-daemon mode (you can add DEBUG=\"*\" env variable to get more messages)\r\n2015-01-13 11:11:15: [PM2][WORKER] Started with refreshing interval: 30000\r\n2015-01-13 11:11:15: [[[[ PM2/God daemon launched ]]]]\r\n2015-01-13 11:11:15: BUS system [READY] on port /home/jussi/.pm2/pub.sock\r\n2015-01-13 11:11:15: RPC interface [READY] on port /home/jussi/.pm2/rpc.sock\r\n2015-01-13 11:11:15: Starting execution sequence in -fork mode- for app name:pm2-daemon-starting-on-stop id:0\r\n2015-01-13 11:11:15: App name:pm2-daemon-starting-on-stop id:0 online\r\n2015-01-13 11:11:15: [PM2] Process index.js launched\r\n2015-01-13 11:11:15: ┌─────────────────────────────┬────┬──────┬──────┬────────┬───────────┬────────┬────────────┬──────────┐\r\n│ App name                    │ id │ mode │ PID  │ status │ restarted │ uptime │     memory │ watching │\r\n├─────────────────────────────┼────┼──────┼──────┼────────┼───────────┼────────┼────────────┼──────────┤\r\n│ pm2-daemon-starting-on-stop │ 0  │ fork │ 3502 │ online │         0 │ 0s     │ 8.176 MB   │ disabled │\r\n└─────────────────────────────┴────┴──────┴──────┴────────┴───────────┴────────┴────────────┴──────────┘\r\n2015-01-13 11:11:15:  Use `pm2 info <id|name>` to get more details about an app\r\n2015-01-13 11:11:15: --no-daemon option enabled = do not exit pm2 CLI\r\n2015-01-13 11:11:15: PM2 dameon PID = 3496\r\n2015-01-13 11:11:15: PM2: Log file \"/home/jussi/.pm2/pm2.log\" does not exist.\r\n```\r\n\r\n(second shell)\r\n\r\n```\r\n$ ps ax | grep -i \"node\\|pm\"\r\n 3489 pts/1    Sl+    0:00 npm\r\n 3495 pts/1    S+     0:00 sh -c pm2 start --no-daemon -x --name $npm_package_name $npm_package_main\r\n 3496 pts/1    Sl+    0:00 node /home/jussi/node_modules/.bin/pm2 start --no-daemon -x --name pm2-daemon-starting-on-stop index.js\r\n 3502 ?        Ssl    0:00 node /home/jussi/index.js\r\n 3509 pts/2    S+     0:00 grep -i node\\|pm\r\n$ rm -rf ~/.pm2\r\n$ npm stop; npm start\r\n\r\n> pm2-daemon-starting-on-stop@ stop /home/jussi\r\n> pm2 stop $npm_package_name || true\r\n\r\n[PM2] Spawning PM2 daemon\r\n[PM2] Success\r\n[PM2] Stopping pm2-daemon-starting-on-stop\r\n[PM2] [ERROR] Process pm2-daemon-starting-on-stop not found\r\n\r\n> pm2-daemon-starting-on-stop@ start /home/jussi\r\n> pm2 start --no-daemon -x --name $npm_package_name $npm_package_main\r\n\r\npm2 launched in no-daemon mode (you can add DEBUG=\"*\" env variable to get more messages)\r\n>> pm2 is already daemonized ! You should kill it before launching it in no-daemon mode\r\n[PM2] Process index.js launched\r\n┌─────────────────────────────┬────┬──────┬──────┬────────┬───────────┬────────┬────────────┬──────────┐\r\n│ App name                    │ id │ mode │ PID  │ status │ restarted │ uptime │     memory │ watching │\r\n├─────────────────────────────┼────┼──────┼──────┼────────┼───────────┼────────┼────────────┼──────────┤\r\n│ pm2-daemon-starting-on-stop │ 0  │ fork │ 3543 │ online │         0 │ 0s     │ 8.172 MB   │ disabled │\r\n└─────────────────────────────┴────┴──────┴──────┴────────┴───────────┴────────┴────────────┴──────────┘\r\n Use `pm2 info <id|name>` to get more details about an app\r\n--no-daemon option enabled = do not exit pm2 CLI\r\nPM2 dameon PID = 3528\r\nPM2: 2015-01-13 11:12:08: [PM2][WORKER] Started with refreshing interval: 30000\r\nPM2: 2015-01-13 11:12:08: [[[[ PM2/God daemon launched ]]]]\r\nPM2: 2015-01-13 11:12:08: BUS system [READY] on port /home/jussi/.pm2/pub.sock\r\nPM2: 2015-01-13 11:12:08: RPC interface [READY] on port /home/jussi/.pm2/rpc.sock\r\nPM2: 2015-01-13 11:12:08: Starting execution sequence in -fork mode- for app name:pm2-daemon-starting-on-stop id:0\r\nPM2: 2015-01-13 11:12:08: App name:pm2-daemon-starting-on-stop id:0 online\r\n```\r\n\r\n(third shell)\r\n```\r\n$ ps ax | grep -i \"node\\|pm\"\r\n 3489 pts/1    Sl+    0:00 npm\r\n 3495 pts/1    S+     0:00 sh -c pm2 start --no-daemon -x --name $npm_package_name $npm_package_main\r\n 3496 pts/1    Sl+    0:00 node /home/jussi/node_modules/.bin/pm2 start --no-daemon -x --name pm2-daemon-starting-on-stop index.js\r\n 3502 ?        Ssl    0:00 node /home/jussi/index.js\r\n 3528 ?        Ssl    0:00 PM2 v0.12.3: God Daemon\r\n 3530 pts/2    Sl+    0:00 npm\r\n 3536 pts/2    S+     0:00 sh -c pm2 start --no-daemon -x --name $npm_package_name $npm_package_main\r\n 3537 pts/2    Sl+    0:00 node /home/jussi/node_modules/.bin/pm2 start --no-daemon -x --name pm2-daemon-starting-on-stop index.js\r\n 3543 ?        Ssl    0:00 node /home/jussi/index.js\r\n 3549 pts/2    S+     0:00 tail -f -n 20 /home/jussi/.pm2/pm2.log\r\n 3639 pts/4    S+     0:00 grep -i node\\|pm\r\n```\r\n\r\nSo as you can see, when `pm2 stop` gets run after the `~/.pm2` folder gets removed, the stop command doesn't find the `pid` of the PM2 instance running in `--no-daemon` mode, but what happens next is the weird part: it starts a new useless daemon. Why is this?"}}