FreeBSD

Information on this page might be outdated.

Script (in /usr/local/etc/rc.d) to launch Traccar on FreeBSD:

#!/bin/sh
#

# PROVIDE: traccar
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable `traccar':
#
# traccar_enable="YES"
#

. /etc/rc.subr

name="traccar"
rcvar="traccar_enable"

# read configuration and set defaults
load_rc_config "$name"
: ${traccar_enable:="NO"}
: ${traccar_chdir:="/usr/local/traccar"}                  # standard root
: ${traccar_java:="/usr/local/openjdk11-jre/bin/java"}    # path to your JRE
: ${traccar_user:="traccar"}                              # user to run as
: ${traccar_group:="traccar"}                             # group to run as
: ${traccar_stdlog:="/dev/null"}
: ${traccar_javaflags:="-Djava.awt.headless=true -Xmx1024M"}

required_files="${traccar_chdir}/conf/traccar.xml"
pidfile="/var/run/traccar/${name}.pid"
procname="${traccar_java}"
command="/usr/sbin/daemon"
command_args="-f -p ${pidfile} -m 3 -o ${traccar_stdlog} ${traccar_java} -jar ${traccar_javaflags} tracker-server.jar conf/traccar.xml"
start_precmd=start_precmd
stop_precmd=stop_precmd
stop_postcmd=stop_postcmd

start_precmd()
{
        if [ ! -e /var/run/traccar ] ; then
                install -d -o ${traccar_user} -g ${traccar_group} /var/run/traccar;
        fi
}

stop_precmd()
{
        if [ -r ${pidfile} ]; then
                _TRACCARPID=$(check_pidfile ${pidfile} ${procname})
                export _TRACCAR_CHILDREN=$(pgrep -P ${_TRACCARPID})
        fi
}

stop_postcmd()
{
        if ! [ -z ${_TRACCAR_CHILDREN} ]; then
                echo "Cleaning up leftover child processes."
                kill $sig_stop ${_TRACCAR_CHILDREN}
                wait_for_pids ${_TRACCAR_CHILDREN}
        fi
}

run_rc_command "$1"

The rest of the installation instructions is like the OpenBSD version:

  1. Get the package
  2. sh traccar.run --noexec --target /usr/local/traccar (although there isn’t anything wrong with /opt/traccar if you’ve got a SYSV fetish. Or /var/www/traccar)
  3. Put the above script into /usr/local/etc/rc.d
  4. If you don’t want to run it as root you should add an appropriate user (just like OpenBSD, but not using ksh - this is a real BSD 8-), use a /bin/sh )
  5. Adapt traccar.cfg (I would use an editor instead of perl. But I’m riding a bike, not a tank)
  6. Edit /etc/rc.conf, adding at least:
traccar_enable="yes"

and maybe

traccar_root="/var/www/traccar"
traccar_user="my-traccar-user"
traccar_java="/usr/local/openjdk11-jre/bin/java"

if something is non-standard. You’ll find the variable names in the rc.d script further up.

If everything is ok,

/usr/local/etc/rc.d/traccar start

should launch it.