OH2 does not start. Under-priviledged?

Hey there,
just trying to get my hands dirty with OH2, so I installed the offline distro snapshot from the apt repos.
Unfortunately running sudo /etc/init.d/openhab2 start gives an error in /var/log/openhab2/openhab.log which is:

2016-10-31 22:12:07.351 [SCHWERWIEGEND] [org.apache.karaf.main.Main] - Could not launch framework
java.lang.RuntimeException: Error initializing storage.
        at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:77)
        at org.eclipse.osgi.launch.Equinox.<init>(Equinox.java:31)
        at org.eclipse.osgi.launch.EquinoxFactory.newFramework(EquinoxFactory.java:24)
        at org.apache.karaf.main.Main.launch(Main.java:250)
        at org.apache.karaf.main.Main.main(Main.java:175)
Caused by: java.io.IOException: Unable to create lock manager.
        at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:698)
        at org.eclipse.osgi.storage.Storage.getChildStorageManager(Storage.java:1749)
        at org.eclipse.osgi.storage.Storage.getInfoInputStream(Storage.java:1766)
        at org.eclipse.osgi.storage.Storage.<init>(Storage.java:126)
        at org.eclipse.osgi.storage.Storage.createStorage(Storage.java:85)
        at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:75)
        ... 4 more

Then tried running the start_debug.sh with openhab user privs like this:

swa@bpro:/etc/openhab2$ sudo -u openhab /usr/share/openhab2/start_debug.sh
Launching the openHAB runtime...
Listening for transport dt_socket at address: 5005
!SESSION 2016-11-01 12:12:42.550 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_111
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=arm, WS=gtk, NL=de_DE

!ENTRY org.eclipse.osgi 4 0 2016-11-01 12:12:42.553
!MESSAGE Error reading configuration: Unable to create lock manager.
!STACK 0
java.io.IOException: Unable to create lock manager.
        at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:698)
        at org.eclipse.osgi.storage.Storage.getChildStorageManager(Storage.java:1749)
        at org.eclipse.osgi.storage.Storage.getInfoInputStream(Storage.java:1766)
        at org.eclipse.osgi.storage.Storage.<init>(Storage.java:126)
        at org.eclipse.osgi.storage.Storage.createStorage(Storage.java:85)
        at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:75)
        at org.eclipse.osgi.launch.Equinox.<init>(Equinox.java:31)
        at org.eclipse.osgi.launch.EquinoxFactory.newFramework(EquinoxFactory.java:24)
        at org.apache.karaf.main.Main.launch(Main.java:250)
        at org.apache.karaf.main.Main.main(Main.java:175)

When executing with root privs, OH2 starts as expected:
swa@bpro:/etc/openhab2$ sudo /usr/share/openhab2/start_debug.sh
Launching the openHAB runtime…
Listening for transport dt_socket at address: 5005

                          __  _____    ____
  ____  ____  ___  ____  / / / /   |  / __ )
 / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  |
/ /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /
\____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/
    /_/                        2.0.0-SNAPSHOT
                               Build #560

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.

openhab>

Any idea where to check for permission issues? Already checked PID file, logging and /usr/share/openhab2/runtime/karaf/instances/instance.properties.
Thanks for your ideas.

Hello!
There are a few things you have to pay attention to in regards to permissions. All steps needed to get openHAB2 running are described here. Did you follow these instructions, where do think you might have done something differently?

http://docs.openhab.org/installation/linux.html

Hey Tom,
Thanks for your reply. Thats exactly the the HowTo I used. The only difference I can see was the Java installation which went a bit different. But at the end java is properly running.

swa@bpro:~$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Client VM (build 25.111-b14, mixed mode)

The was exactly as written in the HowTo. It started when systemctl start service did not start the app.

Hmm… looks good to me.
You need to check a few users and permissions. First make sure you are using the openhab user:
ps -aux | grep "karaf server"
Next look at the owner and write permissions of the openhab folders (listed in the linux article). Pay special attention to the lock file as your error seems to be related to it. I think the file should be located at /var/lib/openhab2/lock

Ok, I changed the setup that openhab user was able to login by:

  • changing shell in /etc/passwd from bin/flase to bin/bash
  • sudo passwd openhab
  • sudo usermod -a -G sudo openhab

Then I did some more permission troubleshooting as user openhab and compared with my 1.8.3 setup. Found some inconsistencies in openhab’s home:

openhab@bpro:~$ ls -al
insgesamt 9764
drwxr-xr-x 13 openhab openhab    4096 Nov  3 11:22 .
drwxr-xr-x 22 root    root       4096 Okt 31 22:07 ..
-rw-------  1 openhab openhab     296 Nov  3 11:22 .bash_history
drwxrwxr-x  4 openhab openhab    4096 Nov  2 11:49 cache
drwxrwxr-x  2 openhab openhab    4096 Nov  2 11:38 deploy
-rw-r--r--  1 root    root    9933379 Nov  1 13:30 dump-2016-11-01_132958-741.zip
drwxrwxr-x  2 openhab openhab    4096 Nov  2 11:38 etc
drwxr-xr-x  2 root    root       4096 Nov  1 12:13 generated-bundles
drwxr-xr-x  2 root    root       4096 Nov  2 08:26 hueemulation
drwxr-xr-x  2 root    root       4096 Nov  1 12:14 kar
-rw-r--r--  1 openhab openhab       0 Nov  3 11:20 lock
drwxr-xr-x  2 root    root       4096 Nov  1 12:57 log
drwxr-xr-x  2 root    root       4096 Nov  1 12:14 mapdb
drwxrwxr-x  2 openhab openhab    4096 Okt 31 22:09 .oracle_jre_usage
drwxr-xr-x  5 openhab openhab    4096 Okt 31 22:07 persistence
-rw-r--r--  1 root    root          5 Nov  2 11:53 port
drwxr-xr-x  2 root    root       4096 Nov  2 15:55 tmp

After changing ownership from root to openhab I crosschecked the logs folder and found events.log also owned by root instead of openhab.

openhab@bpro:/var/log/openhab2$ ls -al
insgesamt 1336
drwxr-xr-x 2 openhab openhab    4096 Nov  1 12:13 .
drwxr-xr-x 6 root    root       4096 Nov  3 06:25 ..
-rw-r--r-- 1 root    root    1216771 Nov  2 15:55 events.log
-rw-rw-r-- 1 openhab openhab  127743 Nov  2 15:55 openhab.log

After fixing this as well OH2 was able to start by start.sh exectuted as openhab user.
Will continue checking if init scripts do work now and OH2 is working from functional point of new.
Thanks for your input Tom