[Unit]
Description=openHAB 2 - empowering the smart home
Documentation=http://docs.openhab.org
Documentation=https://community.openhab.org
Wants=network-online.target
After=network-online.target
[Service]
EnvironmentFile=/etc/default/openhab2
User=openhab
Group=openhab
WorkingDirectory=/usr/share/openhab2
PermissionsStartOnly=true
ExecStartPre=/usr/share/openhab2/start_pre.sh
ExecStart=/usr/share/openhab2/start.sh server
ExecStop=/usr/share/openhab2/runtime/bin/stop
# Shutdown delay in seconds, before process is tried to be killed with KILL (if configured)
TimeoutStopSec=120
Restart=on-failure
[Install]
WantedBy=multi-user.target
start_pre.sh
#!/bin/sh
test -d /var/lib/openhab2/cache || mkdir /var/lib/openhab2/cache
mountpoint -q /var/lib/openhab2/cache || mount -t tmpfs tmpfs /var/lib/openhab2/cache
test -d /var/lib/openhab2/tmp || mkdir /var/lib/openhab2/tmp
mountpoint -q /var/lib/openhab2/tmp || mount -t tmpfs tmpfs /var/lib/openhab2/tmp
test -d /var/lib/openhab2/log || mkdir /var/lib/openhab2/log
mountpoint -q /var/lib/openhab2/log || mount -t tmpfs tmpfs /var/lib/openhab2/log
Good, progress. Now check your logfile for openhab2 at /var/log/openhab2/openhab.log. There’s probably an error there that’s causing openhab to shutdown. Also run journalctl -xn that might give a clue
I have done, yes. Though I find that openhab2 can be a little temperamental if it’s not got everything where it likes it… How did you install openhab2 and which version?
If you installed via the apt repository can you try (I assume you don’t have any openhab configuration you need to keep?):
Hmmm looks like I didn’t remove openHAB 1 like it should. The old service still exists… When stopping the service it looks like it keeps trying to re-activate.
pi@emonpi(rw):/$ sudo service openhab start
Job for openhab.service failed. See 'systemctl status openhab.service' and 'journalctl -xn' for details.
pi@emonpi(rw):/$ sudo service openhab stop
pi@emonpi(rw):/$ sudo service openhab status
● openhab.service - Starts and stops the openHAB Home Automation Bus
Loaded: loaded (/usr/lib/systemd/system/openhab.service; disabled)
Active: failed (Result: exit-code) since Mon 2017-02-27 22:41:42 UTC; 11s ago
Docs: http://www.openhab.org
Process: 1169 ExecStartPre=/usr/share/openhab/bin/setpermissions.sh (code=exited, status=217/ USER)
Feb 27 22:41:42 emonpi systemd[1]: openhab.service: control process exited, code=exited s...217
Feb 27 22:41:42 emonpi systemd[1]: Failed to start Starts and stops the openHAB Home Auto...us.
Feb 27 22:41:42 emonpi systemd[1]: Unit openhab.service entered failed state.
Feb 27 22:41:51 emonpi systemd[1]: Stopped Starts and stops the openHAB Home Automation Bus.
Hint: Some lines were ellipsized, use -l to show in full.
pi@emonpi(rw):/$ sudo service openhab2 status
● openhab2.service
Loaded: not-found (Reason: No such file or directory)
Active: failed (Result: exit-code) since Mon 2017-02-27 22:35:36 UTC; 6min ago
Main PID: 31662 (code=exited, status=255)
Feb 27 22:35:32 emonpi start.sh[31662]: Launching the openHAB runtime...
Feb 27 22:35:34 emonpi start.sh[31662]: /var/log/openhab2/openhab.log (No such file or directory)
Feb 27 22:35:34 emonpi systemd[1]: openhab2.service: main process exited, code=exited, status=255/n/a
Feb 27 22:35:34 emonpi stop[31828]: stop: Ignoring predefined value for KARAF_HOME
Feb 27 22:35:35 emonpi systemd[1]: Stopping openHAB 2 - empowering the smart home...
Feb 27 22:35:36 emonpi stop[31828]: /var/lib/openhab2/tmp/port shutdown port file doesn't exist. The container is not running.
Feb 27 22:35:36 emonpi systemd[1]: openhab2.service: control process exited, code=exited status=3
Feb 27 22:35:36 emonpi systemd[1]: Stopped openHAB 2 - empowering the smart home.
Feb 27 22:35:36 emonpi systemd[1]: Unit openhab2.service entered failed state.
Feb 27 22:36:36 emonpi systemd[1]: Stopped openhab2.service.
How did you clean the emonSD image from openHAB 1?
Since /var/log is mounted as tmpfs on the emonSD the logs are non-persistent and the dirs must be created on each boot.
We do this in /etc/rc.local which is symlinked to ~/emonpi/rc.local_jessieminimal
Thanks for your help @mattwire, I’m watching this thread closely. I’m keen to get OH2 running on emonSD and to release and upgrade. I started documenting my process here:
I need to revisit, to remember how far I got. Sorry, I’ve been busy today.
Using rc.local isn’t a good idea, not only is rc.local dependent on zero errors from all it’s entries to complete, it also doesn’t run untill after all the services are started, so then you have to restart any that have failed to start prior to the rc.local running, it undermines the whole purpose of the start up processes, dependencies and order etc.
Either the init.d script should create the folders as emonhub does or if using systemctl adding something like
before the ExecStart line in the service unit, or as in this case you already have an “ExecStartPre=/usr/share/openhab2/start_pre.sh” line in there you could simply add the log file creation to that additional file, although IMO I would possibly consider moving the contents of that script directly into the service unit to avoid the need for a separate script (and whether it’s executable) and to maximize on the systemctl error logging.
although IMO I would possibly consider moving the contents of that script directly into the service unit to avoid the need for a separate script (and whether it’s executable) and to maximize on the systemctl error logging.
@pb66 I like that idea, so you’d just add multiple ExecStartPre= lines to the systemctl script? What was the purpose of the “-” in the ExecStartPre=-/bin/mkdir… line in your example?
Once you have got it working, it would be a good idea to modify the logging config so you don’t run out of memory:
Edit /etc/openhab/etc/org.ops4j.pax.logging.cfg and change the maxFileSize and maxBackupIndex to match the entries below: