# Custom rc startup script, how?



## parcival (Feb 4, 2013)

Hi all,

*I* need to start this Perl program as a service/daemon. Unfortunately, *I*'m not a "rc script" specialist. I have here the start/stop script on Gentoo, *b*ut how do *I* do this in FreeBSD?


```
#!/sbin/runscript
NAME="zbxlog"
PIDFILE="/var/run/$NAME.pid"
PERL="/usr/bin/perl"
ZBXLOG="/bin/zbxlog.pl"

depend() {
        need net
}

start() {
        ebegin "Stating syslog collector for Zabbix"
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $PERL $ZBXLOG --test > /dev/null || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --background --make-pidfile --exec $PERL $ZBXLOG || return 2
#or use
#       start-stop-daemon --start --background --exec $PERL $ZBXLOG --pidfile $PIDFILE
        eend
}
stop() {
        ebegin "Stopping zbxlog"
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $PERL $ZBXLOG
        [ "$?" = 2 ] && return 2
        rm -f $PIDFILE
        return "$RETVAL"
#or use
#       start-stop-daemon --stop  --exec $PERL $ZBXLOG --pidfile $PIDFILE
        eend
}
```

Thanks for any help here,
parcival


----------



## Orum (Feb 4, 2013)

Practical rc.d scripting in BSD

Also just look at any of the actual scripts as examples, in /etc/rc.d/.  You should put your own custom scripts in /usr/local/etc/rc.d/.


----------

