First of all, there's an article in the official documentation explaining how to write rc scripts: Practical rc.d scripting in BSD.
It will probably answer most of your questions.
When it comes to your script:
The keywords like PROVIDE
, REQUIRE
, etc. have to be comments. See the rc(8) manual page and the rcorder(8) manual page for more details.
#!/bin/sh
#
# PROVIDE: test
# REQUIRE: LOGIN NETWORKING
I think you also miss setting test_enable
to a default value.
: "${test_enable:="NO"}"
You don't really want to just put the instructions to start your daemon in the global scope of the script. This part of your code is bad:
cd /home/deploy/projects/test
/usr/sbin/daemon -u deploy /usr/local/bin/node /home/deploy/projects/test/server.js
You should try to define a start_cmd
function (look for argument_cmd
in the rc.subr(8) manual page for more information) or define the command
variable.
All in all, the best idea is to look at other scripts in /etc/rc.d
and /usr/local/etc/rc.d
to see how people write those and what are the standards. This is how I've learnt it recently as I was developing a daemon for the Keybase filesystem (KBFS). You may look at the code here.
The manpages are also helpful. Start with rc(8) and then look at other manuals listed in the SEE ALSO section.