[SOLVED] Having trouble with startup as service in Ubuntu

Hi i am not a big Linux guy so please be gentle i am trying to switch from windows to Linux so maybe i missed some Prerequisites
i have set up a VM with 16.04 with all the good stuff node-red, sql,openhab Mosquito
but i am not able to start OH with the service and Docs are getting me nowhere, so please help :slight_smile:

  1. my username is openhab for the linux install!(little confusing)
  2. i have nothing in ```WorkingDirectory=/opt/openhab2
  3. when i do changes should i do sudo or sudo bash
  4. when i try i get service erros like this
    Sep 01 09:01:18 ubuntu systemd[1]: [/lib/systemd/system/openhab2.service:12] Exe

Well you should go step by step.

  1. how did you install openHAB?
  2. You did not mention Java (you have to install Java 8, either Zulu or Oracle)
  3. Can you startup openHAB manually (this would fail if no Java is installed yet)

Even if you are no Linux guy :wink: I recommend to use debian (stretch) in favor of Ubuntu, especially when running it as a VM. You don’t want to use a graphic interface, do you? As openHAB should be run on a headless system, don’t install all that graphical overhead, you won’t need it and it won’t give you any benefit.

If starting from scratch, the commonly used user for login to the machine should be a real user (e.g. gadofir or uhartmann or whatever fits) The user openhab is registered when installing openHAB2, and this user should not be able to use a bash, so there is no password set and bash is /bin/false

If installing openHAB2 through apt (and this is the recommended way), there is no directory /opt/openhab2 at all

ubuntu prevents to login as root, and therefor makes use of sudo to provide a way to do things as user root. The command is

sudo command

and this is the same as doing that:

su       //login as user root
command  //execute the command
exit     //leave the root bash

If you want a root bash to work with, you should use

sudo su -

which is: “Login as user root and change to it’s home directory.”

1 Like

oh man ok let me try to answer :slight_smile:

  1. i did Package Repository Installation
  2. zulu java as recommended in docs
  3. yes i am able to start oh
  4. i need the UI , as i said i am not linux guy

if it helps i am using this to start sudo /etc/init.d/openhab2 start
and after all that i did not understand if i need to change something in my home or working directory

:smile: But there is no UI … In fact, it’s way more complex to use the GUI packet manager as to use

apt install <the-packet>

In question of openHAB, the UI comes through the web browser, no need for any GUI.
In ubuntu as in every other *nix-like OS, you always need some console commands.

sudo /etc/init.d/openhab2 start

well, this is the old init script for system-v-startup system. I’m not sure if ubuntu 16.04 comes with systemd or upstart as startup-system. A possible solution could be to use upstart, but this is command line only configuration, and I doubt that there is an official upstart script (upstart is deprecated, ubuntu comes with systemd since ~ 17.04, afaik). another solution could be to use the init script by using

sudo update-rc.d openhab2 defaults

but I don’t know if ubuntu will accept this to startup openHAB at boot.

Maybe you want to try

openHABian as installation method:

  1. Setup a VM with debian netinst iso 1GByte RAM, 1CPU, 10GByte HD, Bridged Network
  2. start the vm, install with standard options (i.e. only chose a root password, a standard user (not openhab) and a password for the standard user.
  3. login to the new VM by using the user root
  4. apt update && apt -y full-upgrade
  5. apt install sudo git
  6. adduser <standarduser> sudo
  7. ip a
    remember the ip for the ethernet (commonly 192.168.x.y)
  8. logout
  9. login to the vm by using putty and the standard user.
  10. Then install openhabian-config:
# download and link
sudo git clone https://github.com/openhab/openhabian.git /opt/openhabian
sudo ln -s /opt/openhabian/openhabian-setup.sh /usr/local/bin/openhabian-config

# execute
sudo openhabian-config
  1. Chose 60 | manual/fresh setup, execute all entries one after the other (you can omit 61 | update as we did it in step 4)

You may say “Oh, this is far too complex!”, but in fact this is really step-by-step and it’s really easy.

If you don’t want to use putty, you can use the VM console instead, but be aware that you can’t adjust the resolution (with putty just change width and hight of the putty window) and you can’t use the clipboard (in putty just mark text to get it in clipboard or right-click to paste the contents of the clipboard).

1 Like

It can use both, but defaults to systemd. It would be better to use the systemd commands:

sudo systemctl enable openhab2
sudo systemctl start openhab2

As long as Java 8 is installed, openHAB’s interface should be available on the web-browser.

Lets try to fix this OS pleaseee :slight_smile:
i am using the gui for more stuff like mysql workbench, node red
i can do all this remotely but i want to be able to do it on site also(if no network is available )

please tell me if i got you right

sudo update-rc.d openhab2 defaults
if you can please explain…
sudo systemctl enable openhab2
sudo systemctl start openhab2

this should do the trick?

either or, not both!

But as you wrote in your first posting

I’m quite sure that systemctl start openhab2 won’t work, so I recommended the init script.

It won’t work, but this is because the default service file has been replaced by something non-standard, /lib/systemd/system/openhab2.service isn’t provided by the package but /usr/lib/systemd/system/openhab2.service is.

Somewhere along the line, instructions were followed meant for another system, but this is not a problem. We can get openHAB working again with systemd by:

sudo systemctl disable openhab2.service
sudo rm /lib/systemd/system/openhab2.service
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service
sudo systemctl restart openhab2.service

I would recommend avoiding the init.d start scripts on a systemd default OS.

1 Like

Ah. didn’t see this…

maybe you have to reload the daemon:

sudo rm /lib/systemd/system/openhab2.service
sudo systemctl daemon-reload    <--- add this line
sudo systemctl enable openhab2.service

Yeah, forgot that line. That’ll do the trick, edited the post above just to be clear on what needs to be done.


thanks so much guys i will try this once i get home :slight_smile: great day for now

It worked , thanks!

1 Like