Skip to content

Instantly share code, notes, and snippets.

@GManzato
Created September 3, 2017 09:59
Show Gist options
  • Save GManzato/43e6c8c67a3e87b2f1830d957036f5f6 to your computer and use it in GitHub Desktop.
Save GManzato/43e6c8c67a3e87b2f1830d957036f5f6 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`
#!/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