Start and stop the Ghost CMS using the FreeBSD rc system.
Requirements:
1. You'll need sudo and forever:
pkg install -y sudo && npm install forever -g
2. You should use a non-root user:
pw useradd -n ghost -c "Ghost CMS" -s /usr/sbin/nologin
Here's a modified rc script to control Ghost on FreeBSD 11:
#!/bin/sh
# PROVIDE: ghost
# KEYWORD: shutdown
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
. /etc/rc.subr
name="ghost"
rcvar="ghost_enable"
extra_commands="status"
load_rc_config ghost
: ${ghost_enable:="NO"}
status_cmd="ghost_status"
start_cmd="ghost_start"
stop_cmd="ghost_stop"
restart_cmd="ghost_restart"
ghost="/usr/local/www/ghost"
log="/var/log/ghost/ghost.log"
ghost_start() {
sudo -u ghost sh -c "cd $ghost && NODE_ENV=production forever start -al $log current/index.js"
}
ghost_stop() {
sudo -u ghost sh -c "cd $ghost && NODE_ENV=production forever stop current/index.js"
}
ghost_status() {
sudo -u ghost sh -c "NODE_ENV=production forever list"
}
ghost_restart() {
ghost_stop;
ghost_start;
}
run_rc_command "$1"
Finally, to start on boot, add ghost to your rc.conf.local:
sysrc -f /etc/rc.conf.local ghost_enable="YES"