I'd like to run a jar as a daemon on FreeBSD 11.0-RELEASE-p8. This is the service file which I have:


## Service for the camp web site.

# PROVIDE: tabor-web
# REQUIRE: SERVERS mysql-server nginx

# Add the following line to /etc/rc.conf to enable camp web site:
# taborweb_enable (bool): Set to "NO" by default.
#           Set to "YES" to enable camp web site.

. /etc/rc.subr


#command="/usr/local/bin/java" #no, try daemon


load_rc_config $name
: ${taborweb_enable:=no}

taborweb_prestart() {

    # set the daemon / java flags
    rc_flags="-f -p ${pidfile} /usr/local/bin/java -jar ./tabor-web.jar >> ${logfile} 2>&1 ${rc_flags}"

    touch $pidfile

taborweb_describe() {
    echo "Service for running a camp web site."

run_rc_command "$1"

The daemon really creates a PID file at the start with the correct PID, however when I try to run

service tabor-web status

I got response

taborweb is not running.

When I check it with

# ps -aux | grep java

I can see that it is running (and the web service is accessible).

 root  2654   0.0  0.2   10428   2132  -  Is   17:12    0:00.00 daemon: /usr/local/bin/java[2655] (daemon)
 root  2655   0.0 17.1 1707364 172744  -  I    17:12    0:20.07 /usr/local/openjdk8-jre/bin/java -jar ./tabor-web.jar
 root  2943   0.0  0.0     404    316  0  R+   17:45    0:00.00 grep java

cat /var/run/taborweb.pid



This is of course not very good for automatic watching - it looks like the website is down even it's up. The good news is that the daemon program runs as should (it restarts the web service if I kill it).

But what am I missing in the script to show correct service status, please?


Well, I found a simple mistake. The service was looking for the PID file of the java service. But it should have been looking for the PID file of the daemon instead.


and then

rc_flags="-r -P ${pidfile} -p ${pidfile_child} /usr/local/bin/java -jar ./tabor-web.jar >> /var/log/taborweb.log 2>&1 ${rc_flags}"

now it works as intended.

  • I have a very similar problem forums.freebsd.org/threads/custom-rc-d-script-trouble.67196 I don't suppose you could take a look? I re-worked my rc.d script to a simmilar style to yours, and now I can start the service, but freeBSD doesn't show it as running (when it is) – crooksey Aug 20 '18 at 13:40
  • Also I believe that "procname" should be changed to "daemon" – marceloneil Dec 27 '18 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.