Shell Configurable rc.d Script Template?

Is this a reasonable template for a configurable rc.d script that utilizes daemon(8)?
Code:
#!/bin/sh
#
# PROVIDE: my_service
# REQUIRE: networking syslog
# KEYWORD:

. /etc/rc.subr

name="my_service"
rcvar="${name}_enable"
command="/usr/local/bin/$name"

start_cmd="${name}_start"

load_rc_config $name
: ${my_service_enable:=no}
: ${my_service_user:="my_service"}
: ${my_service_option_a:="a"}
: ${my_service_option_b:="b"}

my_service_start()
{
        /usr/sbin/daemon -f -u "$my_service_user" "$command" -a "$my_service_option_a" --option_b "$my_service_option_b"
}

run_rc_command "$1"
 
If you haven't already seen it, there is an excellent article on rc(8) scripting: Practical rc.d scripting in BSD.

Your script is fine. An alternative to using daemon(8) would be to write your service to manage its own fork(2)ing, setsid(2)ing and closing of file descriptors. rc(8) supports running a service as a user (and group) other than root; see the rc.subr(8) man page. If it were a service I had written I would also want to be confident that I was handling stop and restart actions safely.
 
Back
Top