Solved Help creating an rc script using daemon

Hello all,

I have an application I developed for internal use that runs in the foreground. After looking through the handbook I thought I got a handle on how to create the rc script (seen below):

Code:
#!/bin/sh

# PROVIDE: platform-worker
# REQUIRE: LOGIN NETWORKING netif named
# KEYWORD: shutdown

. /etc/rc.subr

name="platform-worker"
rcvar="platform_worker_enable"
required_dirs="/home/mylanc/platform"
logfile="/var/log/platform-worker.log"
pidfile="/var/run/${name}.pid"

load_rc_config "$name"

: ${platform_worker_enable:="NO"}
: ${platform_worker_user:="mylanc"}
: ${platform_worker_group:="mylanc"}
: ${platform_worker_config:="/home/mylanc/.platform.toml"}

command="/home/mylanc/platform/platform --config ${platform_worker_config} worker"
start_cmd="/usr/sbin/daemon -P ${pidfile} -r -u ${platform_worker_user} ${command} >> ${logfile} 2>&1"

run_rc_command "$1"

The issue I'm running in to is when I want to stop the service (for example, to upgrade the released application) it complains with the following message:

Code:
platform-worker not running? (check /var/run/platform-worker.pid).

When I cat the file in question as root, I can see a pid that matches a daemon process:

Code:
# cat /var/run/platform-worker.pid
63991

# ps ax | grep 63991
63991  -  Is       0:00.00 daemon: /home/mylanc/platform/platform[67545] (daemon)
10064  0  S+       0:00.00 grep --color=auto 63991

Checking permissions of the pidfile indicates that it has the rw permission for root only (no extra permissions set).

Does anyone see an issue with my rc script? I've been checking through the documentation and it seems like it should be relatively straightforward but obviously I have something messed up here.

Thanks for any assistance!
 
I'm not sure but I think you need to use -p instead of -P on the daemon(8) command.

When I run into situations like this I tend to look for other ports that use the same principles and see how it's done there.
 
Okay I found some other examples, and got a working example. Will probably have to clean it up some in time, but for now I have a working starting point. Thanks!

Code:
#!/bin/sh

# PROVIDE: platform-worker
# REQUIRE: LOGIN NETWORKING netif named
# KEYWORD: shutdown

. /etc/rc.subr

name="platform_worker"
rcvar="platform_worker_enable"
command="/home/mylanc/platform/platform"
command_args="--config /home/mylanc/.platform.toml worker"
platform_user="mylanc"
pidfile="/var/run/platform-worker.pid"

load_rc_config $name
: ${platform_worker_enable:=no}

start_cmd="/usr/sbin/daemon -p $pidfile -P /var/run/platform-worker-daemon.pid -u $platform_user $command $command_args >> /var/log/platform-worker 2>&1"

run_rc_command "$1"
 
Back
Top