Can't get openhab to run under a differnet user with ubuntu and systemd

Hi All,

I’m brand new to openhab, still trying to install it.
I don’t know if it matters but I installed openhab with apt

I want to run openhab under a different user than openhab.
From what I can tell all I should have to do is

  • edit /etc/default/openhab to

USER_AND_GROUP=newuser:newuser

  • then ensure newuser is part or openhab group

usermod -a -G openhab newuser

but when i run

systemctl restart openhab.service
systemctl status openhab.service

I get

Invalid Configuration LocationThe configuration area at '/var/lib/openhab/workspace' is not writable. Please choose a writable location using the '-configuration' command line option.

I get the same when I try

USER_AND_GROUP=newuser:openhab

It seems to work fine if i leave it as openhab:openhab, or if i run it through command line.

Is there something I’m missing?

I’m assuming this is openHAB 1.8. That folder right now has only read permissions on the workspace folder. You should be able to make it work if you give the group write permissions:

sudo chmod -R g+w /var/lib/openhab/workspace

But be careful. There is a script /user/share/openhab/bin/setpermissions.sh which gets run every time OH starts which changes the permissions on a bunch of files, possibly include this folder. You will want to review this script if after restarting OH the error persists and comment out the lines that reset the workspace folder.

Thanks for the reply,

Yes I am on openhab 1.8

The setpermissions.sh script definitely sets all directories and files defined in in openhab.in.sh to have group permissions r-x (755).

I changed setpermissions.sh to use 775 instead of 755 in setPermRecursive()

Unfortunately I still get the same error.

Invalid Configuration LocationThe configuration area at ‘/var/lib/openhab/workspace’ is not writable. Please choose a writable location using the ‘-configuration’ command line option.

After restarting the service I confirmed the permissions under /var/lib/openhab/workspace are 775.

Looking at openhab.sh it looks like the jar is being run with -configuration ${OPENHAB_WORKSPACE_DIR} and openhab.in.sh is defining OPENHAB_WORKSPACE_DIR as /var/lib/openhab/workspace

So all the code I can see looks to be setup correctly now but it still fails.

Anything else I can try?

Make sure everything under that folder has group write as well. Beyond that I’ve no ideas.

I checked that, no luck :frowning:

Anyone have any ideas short of filing a bug?

Found my problem.

Ubuntu is using systemd now so /etc/init.d/openhab is irrelevant

systemd uses /usr/lib/systemd/system/openhab.service

In there it’s hardcoded to use openhab as user and group for the service regardless of /etc/default/openhab

So to get it to work I had to modify both /usr/lib/systemd/system/openhab.service and /etc/default/openhab to use the correct users.