HOWTO? Application startup script controlled by service in rc.d?

csjjpm

Contributor
Joined
Feb 16, 2015
Messages
126
Hi,
I'm learning new stuff all the time and have installed an application, Karaoke-Forever-Server, into a jail. I can get it to run in console but when it doesn't run as a daemon so when the console is closed the application stops.
I want to run it at startup in the background. It is a node.js application so I'm not sure what I have to include as path values etc..
I've tried this but when I type "service karaoke start" I get "env: /usr/local/etc/rc.d/karaoke: No such file or directory"

#!/bin/sh
#
# PROVIDE: karaoke
# REQUIRE: networking
# KEYWORD:

. /etc/rc.subr

name="karaoke"
rcvar="karaoke_enable"
command="/usr/local/lib/node_modules/karaoke-forever/server/main.js"
karaoke_args=" --port 80"
karaoke_user="nobody"
pidfile="/var/run/${name}.pid"

start_cmd="karaoke_start"
stop_cmd="karaoke_stop"
status_cmd="karaoke_status"

karaoke_start() {
/usr/sbin/daemon -P ${pidfile} -r -f -u $karaoke_user $command $karaoke_args
}

karaoke_stop() {
if [ -e "${pidfile}" ]; then
kill -s TERM 'cat ${pidfile}'
else
echo "${name} is not running"
fi

}

karaoke_status() {
if [ -e "${pidfile}" ]; then
echo "${name} is running as pid 'cat ${pidfile}'"
else
echo "${name} is not running"
fi
}

load_rc_config $name
: ${karaoke_enable:=no}

run_rc_command "$1"
 

catnas

Explorer
Joined
Dec 12, 2015
Messages
57
Did you ever get an answer?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I guess there will be a writeup for this soon:
 
Top