Installing openHAB 2 as a service on an ODROID-XU4

Hi, I installed OH 2 on my ODROID-XU4 with Ubuntu 15.04 and it was running smoothly. Then I tried to get it running as a service. The installation process (openhab:install-service) runs smoothly with just 2 warnings. When I try to start it that darn syntax error showed up again!

Syntax error: “(” unexpected

Couldn’t get it running as a service. I decided to write my own bash script for running it as a background service. I made a copy of the /etc/init.d/skeleton file and named it openhab. I will put my script below because it might be useful to others.

#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi

### BEGIN INIT INFO
# Provides:          OpenHAB 2
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenHAB 2 runtime service
# Description:       To start the OpenHAB service: openhab start
#                    To stop the OpenHAB service: openhab stop
#                    To restart the OpenHAB service: openhab restart
### END INIT INFO

# Author: Vincent Broeke

PIDFILE=/var/run/openhab.pid

start() {
    if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) ; then
        echo "OpenHAB already running!"
        return 1
    fi
    echo "Starting OpenHAB..."
    /opt/openhab/runtime/karaf/bin/karaf > /dev/null &echo $! > $PIDFILE
    echo "OpenHAB started."
}

stop() {
    if [ ! -f $PIDFILE ] || ! kill -0 $(cat $PIDFILE) ; then
        echo "OpenHAB is not running."
        return 1
    fi
    echo "Stopping OpenHAB..."
    kill -15 $(cat $PIDFILE) && rm -f $PIDFILE
    echo "OpenHAB stopped."
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
esac
exit 0

UPDATE 1:

I found out that the above script is a depricated way of running services on a linux machine. The script for Raspberry PI’s is working fine for ODROID’s too! See the documentation for getting started with openHAB 2.

The ODRIOD is an ARM based device, which is not supported by the service installation. The same issue exists for the raspberry pi.

Could you create a PR to add your solution to the documentation?

Never mind. This script is working but is a depricated way of running a service on linux machines. I found out that the script for Raspberry PI is working great for ODROID’s too.

Should we update the link to specify ARM instead of Raspberry Pi?

My quess is that this solution works for almost all up-to-date linux distributions and is not processor bound.