-
-
Save danielnieto/b8080bc1f55fdaf0b6c56eb6adc06e35 to your computer and use it in GitHub Desktop.
Run PM2 on a Synology , file need to be create in `/usr/local/etc/rc.d`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
: ${pm2_user="root"} | |
command="/usr/local/lib/node_modules/pm2/bin/pm2" | |
pidfile="/home/${pm2_user}/.pm2/${name}.pid" | |
super() { | |
su - "${pm2_user}" -c "$*" | |
} | |
pm2_start() { | |
unset "${rc_flags}_cmd" | |
if pm2_running; then | |
echo "Pm2 is already running, 'pm2 list' to see running processes" | |
else | |
echo "Starting pm2." | |
super $command resurrect | |
fi | |
} | |
pm2_stop() { | |
echo "Stopping ${name}..." | |
#super $command dump | |
super $command delete all | |
super $command kill | |
} | |
pm2_reload() { | |
echo "Reloading ${name}" | |
super $command reload all | |
} | |
pm2_status() { | |
super $command list | |
} | |
pm2_running() { | |
process_id=$(pgrep -F ${pidfile}) | |
if [ "${process_id}" -gt 0 ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
case "$1" in | |
start) | |
pm2_start | |
;; | |
stop) | |
pm2_stop | |
;; | |
restart) | |
pm2_reload | |
;; | |
status) | |
pm2_status | |
;; | |
*) | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment