Autostart after reboot Raspberry

Hi,
can I use the same script as on below link for openhab 1.x to autostart openhab 2?

Thanks, Alex.

No. openHAB2 has a different folder structure. eg the runtime has its own folder

   /opt/openhab/runtime/server

Have a look at the start.sh that comes with openHAB2, for hints on what need to be updated and the arguments passed to the java command and then update DAEMON_ARGS= accordingly in the script.

I will do this myself in the next day or so, and will update with my version (unless you post your working version first).

Hello,

try to replace first part of startup script with this one:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          openhab
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenHAB Daemon
### END INIT INFO

# Author: Thomas Brettinger

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin

DESC="Open Home Automation Bus Daemon"
NAME=openhab
DAEMON=/usr/bin/java
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
ECLIPSEHOME="/opt/openhab2";
HTTP_PORT=1090
HTTPS_PORT=1091
TELNETPORT=5555
RUN_AS=openhab

# get path to equinox jar inside $eclipsehome folder
cp=$(find $ECLIPSEHOME/runtime/server -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);

DAEMON_ARGS="-Dlogback.configurationFile=./runtime/etc/logback.xml -Dgnu.io.rxtx.SerialPorts=/dev/plugwise:/dev/zwave -DmdnsName=openhab -Dopenhab.logdir=./userdata/logs -Dsmarthome.servicecfg=./runtime/etc$

keep in mind in daemon args there is serial path provided to plugwise and zwave device so you might want to remove it or update.

Hi, I’ve tried to find a solution on this for me. I can’t get it working. Has anyone a working example?

Hi,

I had the problem myself a couple of days ago. That’s the script I’m currently using (adapted from the ones above). You just need to replace the top half of the script provided in the Sample Tricks.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          openhab
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenHAB Daemon
### END INIT INFO

# Author: Thomas Brettinger

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin

DESC="Open Home Automation Bus Daemon"
NAME=openhab
DAEMON=/usr/bin/java
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
ECLIPSEHOME="/opt/openhab";
HTTP_PORT=8080
HTTPS_PORT=8443
TELNETPORT=5555
RUN_AS=root

# get path to equinox jar inside $eclipsehome folder
cp=$(find $ECLIPSEHOME/runtime/server -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);

DAEMON_ARGS="-Dlogback.configurationFile=./runtime/etc/logback.xml -DmdnsName=openhab -Dopenhab.logdir=./userdata/logs -Dsmarthome.servicecfg=./runtime/etc/services.cfg -Dsmarthome.servicepid=org.openhab -Dsmarthome.userdata=./userdata -Dorg.quartz.properties=./runtime/etc/quartz.properties -Djetty.etc.config.urls=etc/jetty.xml,etc/jetty-ssl.xml,etc/jetty-deployer.xml,etc/jetty-https.xml,etc/jetty-selector.xml"

JAVA_ARGS=" -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.home.bundle=org.openhab.io.jetty -Djetty.keystore.path=./runtime/etc/keystore -Dorg.osgi.service.http.port=$HTTP_PORT -Dorg.osgi.service.http.port.secure=$HTTPS_PORT -Dfelix.fileinstall.dir=addons -Djava.library.path=lib -Dequinox.ds.block_timeout=240000     -Dequinox.scr.waitTimeOnBlock=60000 -Dfelix.fileinstall.active.level=4 -Djava.awt.headless=true -jar $cp $* -console"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --chdir $ECLIPSEHOME --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --chdir $ECLIPSEHOME --exec $DAEMON -- $DAEMON_ARGS $JAVA_ARGS \
        || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
    log_daemon_msg "0"
    return 0
}

I have to say I’m not sure if it’s a 100% correct, but it seems to work without a problem.

2 Likes

Hi Jan,
Thanks a lot you made my day! Works perfectly now.
Br
Thomas

I tried the script but it does not work, not with recent OH2 snapshot.
First of thing, org.eclipse.equinox.launcher_*.jar does not exist anymore. That might be the problem…
Anyone that could propose a working systemV script for RPI running Wheezy ?

Hello,
the information in this thread is outdated due to the constant improvement of OH2.
Where are you stuck when following http://docs.openhab.org/installation/linux.html ?

The doc only proposes a service script for systemd which is ok for raspbian Jessie but my old RPI runs raspbian Wheezy and so I need a SystemV start script.

I will try the script proposed here openhab2 Startup script raspberry pi version not working