[SOLVED] AutoStart OpenHab on Linux Chroot

  • Platform information:
    • Hardware: ARM
    • OS: Android 4.2.2 with Debian jessie chrooted
    • Java Runtime Environment: 1.8
    • openHAB version: 2
  • Issue of the topic: Can’ AutoStart Openhab automatically

Hi, i have an old Android TV box (Bluetimes MX5) with android 4.2.2
It has a locked bootloader, and so i can not install armbian or a native linux.

So i installed Linux Deploy with debain jessie chrooted.

I managed to install all prerequisites, including java 1.8 and all openhab services.

Because of the chroot enviroment, i cannot use systemctl to autostart open hub (Running in chroot, ignoring request.)

If i start openhab using

Openhab_cli start

, i have no problems and it works ok. but it stops as soon as i close the terminal.

I have tried to use rc.local with nohop, and init.d with no success.

Any suggestions?

Thanks in advance!!

Before I setup a service, I would use screen for starting OH. You can then attach/detach from the screen as needed.

Can you be more specific?

screen is a Linux application you can install using apt that can emulate a terminal. Many use it to keep a process running when starting it manually from a remote session.

  • Install screen
  • Run screen
  • Start openhab
  • Detach from screen (ctrl+a then ctrl+d)
  • Safely logout of your linux box
  • Use screen -r to get back into the session running out

Does the command:

nohup openhab-cli start &

work? I thought it would have…

Looks like Ben beat me to it, but I would run…

screen -S openhab

… then start.sh to start OH. ctrl+a then ctrl+d to detach. Then

screen -r openhab

… to reattach.

1 Like

Maybe that should be ctrl+a then d to detach?

Both versions should work :slight_smile:

root@localhost:/home/android# start.sh
.bash: start.sh: command not found
root@localhost:/home/android# cd ..
root@localhost:/home# cd ..
root@localhost:/# cd usr/
root@localhost:/usr# cd share/
root@localhost:/usr/share# cd openhab2/
root@localhost:/usr/share/openhab2# start.sh
bash: start.sh: command not found
root@localhost:/usr/share/openhab2# ls
LICENSE.TXT  addons  runtime  start.sh  start_debug.sh
root@localhost:/usr/share/openhab2# start.sh
bash: start.sh: command not found
root@localhost:/usr/share/openhab2# start
bash: start: command not found

it works ok from the terminal. i can close it and it keeps running

but how to make it autostart on boot?

I’m not sure where start.sh is located in an apt install. You should find it in one of these directories…

If I were to guess, I’d try /usr/share/openhab2/start.sh. Also, you’ll need to fully qualify the name. You could go to the direcotry and use ./start.sh, but I recall an issue with that because of how the DIRNAME variable is defined.

1 Like
root@localhost:/home/android# /usr/share/openhab2/start.sh
Launching the openHAB runtime...
mkdir: cannot create directory '/usr/share/openhab2/userdata/tmp': No such file or directory
KARAF_BASE is not valid: /usr/share/openhab2/userdata

root@localhost:/home/android# cd /usr/share/openhab2
root@localhost:/usr/share/openhab2# ls
LICENSE.TXT  addons  nohup.out  runtime  start.sh  start_debug.sh

Do you normally run OH as root? If not, change to that user.

1 Like

i logged in as another user and did

su root

then ran the entire installation process as root
and i am right now as root

changed to another used, and tryed


with same results

Strange… I’ve seen this reported before. I can’t reproduce it, but I use a manual install, so maybe it has to do with the apt install.

1 Like
root@localhost:/usr/share/openhab2# /usr/share/openhab2/start.sh
Launching the openHAB runtime...
mkdir: cannot create directory '/usr/share/openhab2/userdata/tmp': No such file                                or directory
KARAF_BASE is not valid: /usr/share/openhab2/userdata
root@localhost:/usr/share/openhab2# mkdir userdata
root@localhost:/usr/share/openhab2# /usr/share/openhab2/start.sh
Launching the openHAB runtime...
KARAF_ETC is not valid: /usr/share/openhab2/userdata/etc
root@localhost:/usr/share/openhab2# cd userdata
root@localhost:/usr/share/openhab2/userdata# ls
root@localhost:/usr/share/openhab2/userdata# mkdir etc
root@localhost:/usr/share/openhab2/userdata# /usr/share/openhab2/start.sh
Launching the openHAB runtime...
Error occurred shutting down framework: java.lang.NumberFormatException: null
java.lang.NumberFormatException: null
        at java.lang.Integer.parseInt(Integer.java:542)
        at java.lang.Integer.parseInt(Integer.java:615)
        at org.apache.karaf.main.ConfigProperties.<init>(ConfigProperties.java:2                               30)
        at org.apache.karaf.main.Main.updateInstancePidAfterShutdown(Main.java:2                               27)
        at org.apache.karaf.main.Main.main(Main.java:192)

will try manual install!


Have you tried running this in the screen?

1 Like

ok. i installed it manually

first problem,

if i do:

sudo su -s /bin/bash -c '/opt/openhab2/start.sh' openhab

as in the documentation it goes:

Launching the openHAB runtime...
java.net.SocketException: Permission denied
        at java.net.ServerSocket.createImpl(ServerSocket.java:307)
        at java.net.ServerSocket.getImpl(ServerSocket.java:257)
        at java.net.ServerSocket.bind(ServerSocket.java:375)
        at java.net.ServerSocket.<init>(ServerSocket.java:237)
        at org.apache.karaf.main.InstanceHelper.setupShutdown(InstanceHelper.jav                                             a:142)
        at org.apache.karaf.main.Main$KarafLockCallback.lockAcquired(Main.java:7                                             52)
        at org.apache.karaf.main.Main.doMonitor(Main.java:392)
        at org.apache.karaf.main.Main.access$100(Main.java:74)
        at org.apache.karaf.main.Main$3.run(Main.java:377)

                          __  _____    ____
  ____  ____  ___  ____  / / / /   |  / __ )
 / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  |
/ /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /
\____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/
    /_/                        2.4.0
                               Release Build

and website never starts

if i do:

sudo su -s /bin/bash -c '/opt/openhab2/start.sh' root

it start ok and website is ok.

Now, how can i set openhab to autostart with linux ?

if i edit /etc/rc.local

and add:

nohup /opt/openhab2/start.sh server &

it goes:

 Launching the openHAB runtime...
Error ocurred shutting down framework: java.lang.NumberFormatException: null

another alernative:


nohup sudo su -s /bin/bash -c '/opt/openhab2/start.sh' root &

it startup ok, website ok
after a couple minutes, it stops…

If i try:

screen -S openhab
ctrl+a then ctrl+d 

Website starts ok
when i close the terminal session the website keeps running ok,.

This seem to be the solution, how do i implement the last one in /etc/rc.local ?

i also tryied

/usr/bin/screen -dmS openhab /opt/openhab2/start.sh

And does nothing.

You could try putting this in rc.local to launch a screen session, and launches OH in the session (this is what we used before setting up the service)…

screen -d -m -S openhab
screen -S openhab -p 0 -X stuff "/opt/openhab2/start.sh$(printf \\r)"
1 Like

ok. if
placed in rc.local

screen -d -m -S openhab2
screen -S openhab2 -p 0 -X stuff2 "/opt/openhab2/start.sh$(printf \\r)"

nothing happens
websites doesn’t start
can’t see java on top

and i see this:

root@localhost:/home/android# screen -ls
There are screens on:
        5830.openhab    (01/09/19 05:23:54)     (Dead ???)
        6011.openhab    (01/09/19 05:23:54)     (Dead ???)
Remove dead screens with 'screen -wipe'.
2 Sockets in /var/run/screen/S-root.

if i do

screen -d -m -S openhab
screen -S openhab -p 0 -X stuff "/opt/openhab2/start.sh$(printf \\r)"

from the terminal, everything works. ok and keeps working even when i close it.

my god, it can’t be so dificut!!

maybe trying with a manual init.d ??

the only problem i have is that i cannot autostart openhab with linux,

Thanks for the patience.