ralyodio / node-startup

Startup script for Linux-based systems for running node app when rebooting using an /etc/init.d script.
MIT License
781 stars 169 forks source link

Catch STDERR on stop_process #49

Closed FossPrime closed 6 years ago

FossPrime commented 6 years ago

If you use this script on a crontab, and the account has email forwarding enabled, you'll get spammed with terminated messages from bash, even though you are catching stdout with > /dev/null

-bash: line 1:  1675 Terminated              PORT=80 NODE_ENV=production NODE_CONFIG_DIR=/opt/web-hooks /usr/bin/node  /opt/web-hooks/bin/www &>>/var/log/td-web-hooks.log

I tried pkill, but that didn't work with wait. and we currently only store that paren't PID which will kill the bash running node, but not node. Hence the subshell to find the process group ID and use kill. It might be more elegant to just save the process group ID from the get go, but this works well without refactoring. https://stackoverflow.com/questions/5719030/bash-silently-kill-background-function-process