-
-
Save dougluce/98d60f6386efe3ab863e8efbe54a2a3f to your computer and use it in GitHub Desktop.
node.js pm2 startup script for FreeBSD
This file contains hidden or 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 Startup script | |
| # Source: https://0x0a14.de/pm2-startup-script-for-freebsd/ | |
| # Made by: Johannes Tonn | |
| # | |
| # Download this file | |
| # cd /usr/local/etc/rc.d && fetch https://gist.github.com/457769f2090c6b69cd9d | |
| # | |
| # Make the file executable with: | |
| # /usr/local/etc/rc.d/pm2 (chmod +x) | |
| # | |
| # add to /etc/rc.conf | |
| # | |
| # pm2_enable="YES" | |
| # pm2_user="freebsd" | |
| # PROVIDE: pm2 | |
| # REQUIRE: NETWORK mongod | |
| # KEYWORD: shutdown | |
| # | |
| . /etc/rc.subr | |
| name=pm2 | |
| rcvar=pm2_enable | |
| PM2=/usr/local/lib/node_modules/pm2/bin/pm2 | |
| load_rc_config $name | |
| start_cmd="pm2_start" | |
| stop_cmd="pm2_stop" | |
| restart_cmd="pm2_restart" | |
| : ${pm2_user="freebsd"} | |
| : ${pm2_enable="NO"} | |
| pm2_start() | |
| { | |
| CMD="$PM2 resurrect" | |
| su -l ${pm2_user} -c "${CMD}" | |
| } | |
| pm2_stop() | |
| { | |
| CMD="${PM2} dump ; ${PM2} delete all ; ${PM2} kill" | |
| su -l ${pm2_user} -c "${CMD}" | |
| } | |
| pm2_restart() | |
| { | |
| CMD="pm2_stop ; pm2_start" | |
| su -l ${pm2_user} -c "${CMD}" | |
| } | |
| pm2_reload() | |
| { | |
| CMD="$PM2 reload all" | |
| su -l ${pm2_user} -c "${CMD}" | |
| } | |
| run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment