There's a certain node application called Foundry that I run on a server, and I've prepared the below script located in /usr/local/etc/rc.d to manage it. The script itself I adapted from another one I found elsewhere and I'm still in the process of making it perfect for my needs, but it works fine as-is for starting and stopping the service.
However, the problem I don't understand is that when I run
According to what I'm reading in the Handbook here, the presence of the
So yeah. I'm not really seeing what I'm doing wrong here. What can I do to get
However, the problem I don't understand is that when I run
service foundry status
, it always says foundry is not running, even if I'm confirming that it is in fact running. If I stop the service the .pid file goes away, so I know it's being used:
Code:
root@foundry:/usr/local/etc/rc.d # service foundry status
foundry is not running.
root@foundry:/usr/local/etc/rc.d # cat /var/run/foundry.pid
69169
root@foundry:/usr/local/etc/rc.d # service foundry stop
Stopping Foundry...
root@foundry:/usr/local/etc/rc.d # cat /var/run/foundry.pid
cat: /var/run/foundry.pid: No such file or directory
According to what I'm reading in the Handbook here, the presence of the
$pidfile
variable sounds like the only thing that's needed. Though the status command didn't even do anything but throw an error until I added extra_commands="status"
to the script: /usr/local/etc/rc.d/foundry: unknown directive 'status'.
So yeah. I'm not really seeing what I'm doing wrong here. What can I do to get
service foundry status
to actually return the status of the running process?
Code:
#!/bin/sh
. /etc/rc.subr
name="foundry"
node="/usr/local/bin/node"
foundry_app_dir="/usr/local/www/foundry/foundryvtt/resources/app"
foundry_data_dir="/usr/local/www/foundry/foundrydata"
executable="main.js"
foundry_user="foundry"
log_file="/var/log/foundry.log"
foundry="${node} ${foundry_app_dir}/${executable}"
rcvar="foundry_enable"
pidfile="/var/run/${name}.pid"
extra_commands="status"
sig_stop=-KILL
start_cmd=foundry_start
stop_cmd=foundry_kill
restart_cmd=foundry_restart
load_rc_config ${name}
command_args="--dataPath=${foundry_data_dir}"
foundry_restart() {
if [ -n "$(cat ${pidfile} 2>/dev/null)" ];then
printf "Restarting Foundry...\n"
foundry_kill
sleep 5
foundry_start
fi
}
foundry_start() {
printf "Starting Foundry...\n"
daemon -f -o ${log_file} -p ${pidfile} -u ${foundry_user} ${node} ${foundry_app_dir}/${executable} $command_args
if [ $? -ne 0 ]; then
printf "Error starting Foundry. See ${log_file} for details.\n"
exit 1
fi
}
foundry_kill() {
printf "Stopping Foundry...\n"
kill $sig_stop `cat $pidfile`
}
run_rc_command "$1"