OH2 and FreeBSD

Hello,

Just to let you know, procedure to make OH2 work in FreeBSD is the same as OH1.

Just add this on “start.sh” before “DIRNAME”

JAVA_HOME="/usr/local/openjdk8"; export JAVA_HOME

and I’m still trying to figure the best way to start the server and have access to it without using “screen” :slight_smile:

Also how to secure it for external :confused:

Hi,

Can you please help to provide all the steps (sequential commands and download sources). I have tried to install OH on FreeNAS without success. The documentation at that time was very scattered and required source code compilation.

If you can provide the NOOB step by step process, then that will be highly appreciated.

1 Like

I’m really having problems istalling it on FreeNAS,too. A step by step tutorial would be really cool!

I modified the rc.d script for openhab2 as follows:

#!/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="openhab2"
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="/home/openhab/openhab2"}

required_files="${openhab_home}/conf/services/runtime.cfg"


java_command="/usr/local/bin/java
         -Dopenhab.home=${openhab_home}
         -Dopenhab.conf=${openhab_home}/conf
         -Dopenhab.runtime=${openhab_home}/runtime
         -Dopenhab.userdata=${openhab_home}/userdata
         -Dopenhab.logdir=${openhab_home}/userdata/logs
         -Dfelix.cm.dir=${openhab_home}/userdata/config
         -Djetty.host=0.0.0.0
         -Dorg.ops4j.pax.web.listening.addresses=0.0.0.0
         -Dorg.osgi.service.http.port=${openhab_http_port}
         -Dorg.osgi.service.http.port.secure=${openhab_https_port}
         -Djava.awt.headless=true -XX:+UseG1GC
         -Djava.endorsed.dirs=/usr/local/openjdk8/jre/lib/endorsed:/usr/local/openjdk8/lib/endorsed:${openhab_home}/runtime/lib/endorsed
         -Djava.ext.dirs=/usr/local/openjdk8/jre/lib/ext:/usr/local/openjdk8/lib/ext:${openhab_home}/runtime/lib/ext
         -Dkaraf.instances=${openhab_home}/runtime/instances
         -Dkaraf.home=${openhab_home}/runtime
         -Dkaraf.base=${openhab_home}/userdata
         -Dkaraf.data=${openhab_home}/userdata
         -Dkaraf.etc=${openhab_home}/userdata/etc
         -Dkaraf.restart.jvm.supported=true
         -Djava.io.tmpdir=${openhab_home}/userdata/tmp
         -Djava.util.logging.config.file=${openhab_home}/userdata/etc/java.util.logging.properties
         -Dkaraf.startLocalConsole=false
         -Dkaraf.startRemoteShell=false
         -classpath ${openhab_home}/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.0.8.jar:${openhab_home}/runtime/lib/boot/org.apache.karaf.jaas.boot-4.0.8.jar:${openhab_home}/runt
ime/lib/boot/org.apache.karaf.main-4.0.8.jar:${openhab_home}/runtime/lib/boot/org.osgi.core-6.0.0.jar org.apache.karaf.main.Main"

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 < ${_pidfile}
    if [ -z "${_pid}" ]; then
        debug "pid file (${_pidfile}): no pid in file."
        return
    fi
        echo -n ${_pid}
}

run_rc_command "$1"