ghost-rc.d-script/pm2
Jordan Ostreff 57cf1f8a09
added status
Added status and reordered the script.
2022-10-21 19:44:48 +03:00

78 lines
1.5 KiB
Bash

#!/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
#
# Download this file
# cd /usr/local/etc/rc.d && fetch https://raw.githubusercontent.com/jostreff/ghost-rc.d-script/main/pm2 -o pm2
#
# Make the file executable with:
# /usr/local/etc/rc.d/pm2 (chmod +x)
#
# add to /etc/rc.conf
#
# pm2_enable="YES"
# pm2_user="ghost"
#
# KEYWORD: shutdown
#
. /etc/rc.subr
: ${pm2_user="ghost"}
: ${pm2_enable="NO"}
name=pm2
rcvar=pm2_enable
export PATH=$PATH:/usr/local/bin
export NODE_ENV="production"
PM2=/usr/local/lib/node_modules/pm2/bin/pm2
load_rc_config $name
extra_commands="status"
start_cmd="pm2_start"
stop_cmd="pm2_stop"
restart_cmd="pm2_reload"
describe_cmd="pm2_ls"
status_cmd="pm2_show"
pm2_start()
{
CMD="$PM2 resurrect"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
}
pm2_stop()
{
CMD="${PM2} dump"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
CMD="${PM2} delete all"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
CMD="${PM2} kill"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
}
pm2_ls()
{
CMD="${PM2} ls"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
}
pm2_show()
{
CMD="${PM2} show 0"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
}
pm2_reload()
{
CMD="$PM2 reload all"
/usr/local/bin/sudo -u ${pm2_user} -s ${CMD}
}
run_rc_command "$1"