I am using an open source project (Traccar) and they provide a rc script to start and stop the service https://www.traccar.org/freebsd/
This script doesn't work, I can easily start the server if I do:
However, I want to have this application handled by FreeBSD, so I wrote a custom rc.d script:
Now, this script starts the service, and correctly starts it when the machine is powered on.
However, it doesn't show as running...
So I check the output of the PID files:
And if I can see those PID's here:
And if I run kill on 50137 (the java process, which is also the same number returned from /var/run/traccar.pid) the deamon correctly brings it back up.
So my new script *half* works, it brings the application up, but doesn't show it as running from the service command, and because of this I cannot use
Where as above, we know the PID returned from /var/run/traccar_daemon.pid is running and shows from ps output.
I think I am almost there, if anyone can help/advise what might be wrong, I would be very grateful, thanks.
This script doesn't work, I can easily start the server if I do:
Code:
# cd /usr/local/traccar
# java -jar tracker-server.jar conf/traccar.xml &
However, I want to have this application handled by FreeBSD, so I wrote a custom rc.d script:
Code:
#!/bin/sh
## Service for traccar.
# PROVIDE: traccar
# REQUIRE: DAEMON
# BEFORE:
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable `traccar':
#
# traccar_enable="YES"
#
. /etc/rc.subr
name="traccar"
rcvar=traccar_enable
pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"
traccar_chdir="/usr/local/traccar"
command="/usr/sbin/daemon"
start_precmd="${name}_prestart"
procname="traccar"
load_rc_config "$name"
: ${traccar_enable="NO"}
: ${traccar_root="/usr/local/traccar"} # standard root
: ${traccar_java="/usr/local/openjdk7-jre/bin/java"} # path to your JRE
: ${traccar_user="root"} # user to run as
: ${traccar_stdout="/var/log/traccar_running.log"}
: ${traccar_stderr="/var/log/traccar_error.log"}
traccar_chdir=${traccar_root} # will add a cd $traccar_root before launching
command_args="-jar ${traccar_root}/tracker-server.jar ${traccar_root}/conf/traccar.xml"
traccar_prestart() {
# set the daemon / java flags
rc_flags="-r -P ${pidfile} -p ${pidfile_child} ${traccar_java} ${command_args} >> ${traccar_stdout} 2>&1 ${rc_flags}"
#touch $pidfile
}
traccar_describe() {
echo "Traccar started..."
}
run_rc_command "$1"
Now, this script starts the service, and correctly starts it when the machine is powered on.
However, it doesn't show as running...
Code:
# service traccar status
traccar is not running.
So I check the output of the PID files:
Code:
# cat /var/run/traccar.pid
50137
# cat /var/run/traccar_daemon.pid
49060
And if I can see those PID's here:
Code:
root@traccar:~ # ps aux
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 48997 0.0 0.0 10492 2444 - IsJ 09:57 0:00.36 /usr/sbin/syslogd -s
root 49060 0.0 0.0 10468 2052 - IsJ 09:57 0:00.00 daemon: /usr/local/openjdk7-jre/bin/java[50137] (daemon)
root 49103 0.0 0.0 20628 6260 - SsJ 09:57 0:00.04 sendmail: accepting connections (sendmail)
smmsp 49114 0.0 0.0 20628 6072 - IsJ 09:57 0:00.00 sendmail: Queue runner@00:30:00 for /var/spool/clientmqueue (sendmail)
root 49122 0.0 0.0 12592 2340 - SsJ 09:57 0:00.01 /usr/sbin/cron -s
root 50137 0.0 1.3 4673476 418304 - IJ 10:47 0:15.86 /usr/local/openjdk7-jre/bin/java -jar /usr/local/traccar/tracker-server.jar /usr/local/traccar/conf/traccar.xml -jar /usr/local/traccar/tracker-serv
And if I run kill on 50137 (the java process, which is also the same number returned from /var/run/traccar.pid) the deamon correctly brings it back up.
So my new script *half* works, it brings the application up, but doesn't show it as running from the service command, and because of this I cannot use
Code:
# service traccar restart
traccar not running? (check /var/run/traccar_daemon.pid)
Where as above, we know the PID returned from /var/run/traccar_daemon.pid is running and shows from ps output.
I think I am almost there, if anyone can help/advise what might be wrong, I would be very grateful, thanks.