Startup script in /etc/rc.d/openhab
#! /bin/sh# PROVIDE: openhab# REQUIRE: DAEMON NETWORKING# KEYWORD: SHUTDOWN## Short-Description: OpenHAB Daemoncd "/opt/openhab-core"
. /etc/rc.subr name=openhab rcvar=openhab_enable pidfile="/var/run/$name.pid" eclipsehome="/opt/openhab-core/server" cp=$(find $eclipsehome -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1) httpport=8080 httpsport=8443 user=root command="/usr/local/openjdk7/bin/java" command_args="-Djava.net.preferIPv4Stack=true -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=$httpport -Djetty.port.ssl=$httpsport -Djetty.home=. -Dlogback.configurationFile=configurat load_rc_config $namerun_rc_command "$1"#!/bin/sh## $FreeBSD:$## PROVIDE: openhab# REQUIRE: LOGIN# KEYWORD: shutdown## Configuration settings for openhab in /etc/rc.conf:# Mandatory:# openhab_enable (bool):# Set to "NO" by default.# Set it to "YES" to enable openhab## Optional:# openhab_user (bool):# Set to "openhab" by default.## openhab_http_port (num):# Default to 8080## openhab_https_port (num):# Default to 8443## openhab_telnet_port (num):# Default to 5555## openhab_home (str):# Default to "/usr/local/openhab"#
. /etc/rc.subr
name="openhab"rcvar="${name}_enable"pidfile="/var/run/${name}.pid"
load_rc_config "${name}"
: ${openhab_enable="NO"}: ${openhab_user="openhab"}: ${openhab_http_port=8080}: ${openhab_https_port=8443}: ${openhab_telnet_port=5555}: ${openhab_home="/usr/local/openhab"}
required_files="${openhab_home}/configurations/openhab.cfg"
cp=$(find ${openhab_home}/server -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);
java_command="/usr/local/bin/java -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=${openhab_http_port} -Djetty.port.ssl=${openhab_https_port} -Djetty.home=${openhab_home} -Dlogback.configurationFile=${openhab_home}/configurations/logback.xml -Dfelix.fileinstall.dir=${openhab_home}/addons -Djava.library.path=${openhab_home}/lib -Djava.security.auth.login.config=${openhab_home}/etc/login.conf -Dorg.quartz.properties=${openhab_home}/etc/quartz.properties -Dequinox.ds.block_timeout=240000 -Dequinox.scr.waitTimeOnBlock=60000 -Dfelix.fileinstall.active.level=4 -Djava.awt.headless=true -jar $cp -console ${openhab_telnet_port}" command="/usr/sbin/daemon"command_args="-p ${pidfile} -u ${openhab_user} -f ${java_command}"
start_precmd="pid_touch"start_cmd="openhab_start"stop_cmd="openhab_stop"status_cmd="openhab_status"
pid_touch() { touch ${pidfile} chown ${openhab_user} ${pidfile}}
openhab_start() { cd ${openhab_home} echo "Starting ${name}..." exec ${command} ${command_args}}
openhab_stop() { rc_pid=$(openhab_check_pidfile ${pidfile}) if [ -z "${rc_pid}" ]; then [ -n "${rc_fast}" ] && return 0 echo "${name} not running? (check ${pidfile})." return 1 fi echo "Stopping ${name}..." kill -KILL ${rc_pid} 2> /dev/null && echo "Killed." rm -f ${pidfile} sleep 1} openhab_status() { rc_pid=$(openhab_check_pidfile $pidfile) if [ -n "${rc_pid}" ]; then echo "${name} is running as pid ${rc_pid}." else echo "${name} is not running." return 1 fi}
openhab_check_pidfile() { _pidfile=$1 if [ -z "${_pidfile}" ]; then err 3 'USAGE: openhab_check_pidfile pidfile' fi if [ ! -f ${_pidfile} ]; then debug "pid file (${_pidfile}): not readable." return fi read _pid _junk < ${_pidfile} if [ -z "${_pid}" ]; then debug "pid file (${_pidfile}): no pid in file." return fi if [ -n "`/usr/local/bin/jps -l | grep -e "^${_pid} ${cp}\$"`" ]; then echo -n ${_pid} fi}
run_rc_command "$1"
Shawn,
I’m glad that I could help you. But to be totally honest I wrote the script for myself. :-) I will also run OpenHAB on FreeNAS so I need it as much as you do. A tip for the next time you need something like this is to look for similar stuff already out there. My script is mostly based on the startup script for Tomcat. Let me know if it works out ok for you.
Enter code here...# mkdir /homeEnter code here...# pw groupadd openhab# pw useradd -n openhab -c "openhab user" -g openhab -m -s /usr/sbin/nologin
# chown -R openhab:openhab /path/to/openhab
#ps aux
root 59558 0.0 0.0 12088 1632 ?? IsJ 5:46PM 0:00.00 daemon: /usr/local/bin/java[59559] (daemon)
hab 59559 0.0 3.9 2352836 651476 ?? SJ 5:46PM 2:20.33 /usr/local/openjdk7/bin/java -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=8080 -Djetty.port.ssl=8443 -Djetty.home=/home/hab/runtime
#service openhab status
openhab is not running.
#ls -la /var/run/openhab.pid
-rw-r--r-- 1 hab wheel 5 Aug 22 17:46 /var/run/openhab.pid
# /usr/local/bin/jps -l
59559 -- process information unavailable
1002 sun.tools.jps.Jps