rc script issues

I'm having two issues with following rc script (some commands trimmed for brevity):

Code:
#!/bin/sh

# PROVIDE: sfile
# REQUIRE: NETWORKING SERVERS DAEMON LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name=sfile
rcvar=sfile_enable

load_rc_config $name

: ${sfile_enable=NO}
: ${sfile_user=synthmeat}
: ${sfile_group=synthmeat}

sfile_node=/usr/local/bin/node
sfile_workdir=/home/synthmeat/work/showdown-file
sfile_script=build/main.js
sfile_logfile=/home/synthmeat/logs/showdown-file.log
sfile_pidfile=/home/synthmeat/pids/showdown-file.pid

start_cmd=sfile_start

sfile_start()
{
    if [ -e ${sfile_pidfile} ]
    then
        if [ `pgrep -F ${sfile_pidfile}` ]
        then echo 'showdown file server is already running'
        else
            echo 'starting showdown file server'
            cd ${sfile_workdir}
            nohup ${sfile_node} ${sfile_script} > ${sfile_logfile} 2>&1 &
        fi
    else
        echo 'starting showdown file server'
        cd ${sfile_workdir}
        nohup ${sfile_node} ${sfile_script} > ${sfile_logfile} 2>&1 &
    fi
}

run_rc_command "$1"

First is that processes started from it are always by the user that started the service (say, "sudo service sfile start" will start processes as root). I thought ${name}_user in script or in rc.conf should override the user running it?

Second is at boot, in that, though it does start the script, no processes get started by it, unlike when ran in some login shell. sfile_enable="YES" is set in /etc/rc.conf as well as rc_debug, which gives me no particular relevant information.
 
From what I can tell now, I'm:
- not using "command", which is required for {$name}_user
- overriding start, which basically leaves me out of any goodies of _user or command

I appear to have fundamental misunderstandings here, I'll RTFM. Thanks though.
 
I've used this as a boilerplate. It's not proper right, but works, sort of.

Juha

Code:
#!/bin/sh

# PROVIDE: arvuutin
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="arvuutin"
user="nobody"

pidfile="/var/run/${name}.pid"
rcvar="${name}_enable"
start_cmd=${name}_start
command="daemon"

arvuutin_start()
{
  /usr/sbin/daemon -cf -P $pidfile -u $user some random command line
}

load_rc_config $name
run_rc_command "$1"
 
Back
Top