openhab / openhab-linuxpkg

Repo for Linux packages
Eclipse Public License 2.0
18 stars 33 forks source link

Manage presence of zram on openHAB mount points when installing/upgrading openHAB #161

Closed shutterfreak closed 4 years ago

shutterfreak commented 4 years ago

The install/upgrade script doesn't check the presence of zram or whether folders are (will become) under control of zram.

Blindly installing / upgrading openHAB without considering zram status can lead to undesired side-effects.

See this thread for instructions and the discussion.

A simple option is to stop the installation or upgrade if the zram service has been detected as running, and display a warning + reference to documentation (e.g. the openHAB forum discussion)

A more fine-grained scenario would implement (parts of ) the upgrade process depicted in the same openHAB forum discussion (steps 1-6, then 9 and 10).

BClark09 commented 4 years ago

Hi @shutterfreak, (also @mstormi)

I don't think it's quite right to do anything about the issues related to a zram implementation in this repository. The packages built here have no knowledge of openHABian or individual setups, and so it should not contain patches or scripts to accommodate it. Think of this as an upstream library, it's only responsible for itself.

However, I do think I can offer a solution that may resolve the issue:

openHABian works on operating systems using systemd and would therefore use the openhab2.service file provided by these packages. This can be overridden (see here) in a new /etc/systemd/system/openhab2.service.d/zram.conf file. You can override here what happens when openHAB stops.

Likewise, you can add a dependancy in zram on openhab by adding an override for zram-config's service file:

[Unit]
PartOf=openhab2.service

The above should make zram stop (and thus, sync) whenever you stop the openHAB2 service.

mstormi commented 4 years ago

@BClark09 thanks for your input. I've updated ZRAM unit as follows for now. @shutterfreak please test (you can edit your local /etc/systemd/system/zram-config.service don't forget systemctl daemon-reload) It's not 100% as we would still need to remember to manually shutdown OH(+ZRAM to follow) after an OH upgrade so the cache files are generated but synced back to disk.

[18:27:42] openhabian@openhabianpi:~/openhabian-zram$ cat zram-config.service [Unit] Description=zram-config After=local-fs.target Before=reboot.target halt.target smbd.service openhab2.service PartOf=openhab2.service

[Service] Type=oneshot ExecStartPre=-/bin/rm -f /usr/local/share/zram-config/zram-device-list /usr/local/share/zram-config/zram-device-list.rev ExecStart=/usr/local/bin/zram-config start ExecStop=/usr/local/bin/zram-config stop TimeoutSec=180 RemainAfterExit=yes

[Install] WantedBy=basic.target

shutterfreak commented 4 years ago

Okay. Here's the original zram-config.service file:

$ cat /etc/systemd/system/zram-config.service 
[Unit]
Description=zram-config
After=local-fs.target
Before=reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/zram-config start
ExecStop=/usr/local/bin/zram-config stop
TimeoutSec=180
RemainAfterExit=yes

[Install]
WantedBy=basic.target

And now the new zram-config.service file is identical to yours.

I then did sudo systemctl daemon-reload

It's not 100% as we would still need to remember to manually shutdown OH(+ZRAM to follow) after an OH upgrade so the cache files are generated but synced back to disk.

Wouldn't these 2 operations be addressed by the edits to zram-config.service when issuing sudo systemctl restart openhab2 ?

mstormi commented 4 years ago

Wouldn't these 2 operations be addressed by the edits to zram-config.service when issuing sudo systemctl restart openhab2 ?

Restarting openhab2 would stop OH - stop ZRAM - start ZRAM - start OH, that's right. But what I meant is that we need this restart twice. OH has to run for a couple of minutes to generate the cache files, then if shutdown the current unit files will also cause ZRAM to shutdown, effectively syncing cache files to disk, then to restart. From then on it no longer has the synced cache files in memory but will only be storing changes into (Z)RAM.

mstormi commented 4 years ago

I've put that live https://github.com/mstormi/openhabian-zram/blob/master/zram-config.service so anyone to install ZRAM from now on will get this changed dependency declarations.

Would you mind testing please ? A little late I know given my statement it's live now. You can uninstall+(re)install from openhabian-config or edit the zram-config.service file + systemctl daemon-reload so you don't have to mess with your existing ZRAM install.

shutterfreak commented 4 years ago

I can now make some time to test this one.

Please correct me if I am wrong.

Init: sudo systemctl status openhab2.service

Test 1: run sudo systemctl stop openhab2.service Check: zram-config.service is also stopped

Test 2: run sudo systemctl start openhab2.service Check: zram-config.service is also started

Test 3: run sudo systemctl restart openhab2.service Check: zram-config.service is also started

Here's the output. I have SSH issues with the latest RPi kernel, making it difficult to perform long terminal sessions. Here's a transcription, and as you'll see, there's something wrong with zram-config (/usr/local/bin/zram-config: line 157: echo: write error: Device or resource busy):

[10:54:12] openhabian@openhab:~$ sudo systemctl daemon-reload
[sudo] password for openhabian: 
[10:54:21] openhabian@openhab:~$ sudo systemctl status openhab2.service
● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/openhab2.service.d
           └─override.conf
   Active: active (running) since Mon 2020-04-13 10:25:26 CEST; 29min ago
     Docs: https://www.openhab.org/docs/
           https://community.openhab.org
 Main PID: 666 (java)
    Tasks: 222 (limit: 2319)
   Memory: 438.5M
   CGroup: /system.slice/openhab2.service
           └─666 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.logdir=/var/log/openhab2 -Dfelix.cm.dir=/var/l

Apr 13 10:23:12 openhab systemd[1]: Starting openHAB 2 - empowering the smart home...
Apr 13 10:23:44 openhab karaf[666]: org.ops4j.pax.url.wrap [org.ops4j.pax.url.commons.handler.HandlerActivator] DEBUG : Handler for protocols [wrap] started
Apr 13 10:25:26 openhab systemd[1]: Started openHAB 2 - empowering the smart home.
[10:54:36] openhabian@openhab:~$ sudo systemctl status zram-config.service
● zram-config.service - zram-config
   Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
   Active: active (exited) since Mon 2020-04-13 10:23:01 CEST; 31min ago
 Main PID: 319 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 2319)
   Memory: 0B
   CGroup: /system.slice/zram-config.service

Apr 13 10:22:59 openhab systemd[1]: Starting zram-config...
Apr 13 10:23:01 openhab systemd[1]: Started zram-config.
[10:55:55] openhabian@openhab:~$ sudo systemctl stop openhab2.service
[10:56:48] openhabian@openhab:~$ sudo systemctl daemon-reload
[10:57:07] openhabian@openhab:~$ sudo systemctl status zram-config.service
● zram-config.service - zram-config
   Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2020-04-13 10:57:07 CEST; 3s ago
  Process: 5079 ExecStop=/usr/local/bin/zram-config stop (code=exited, status=0/SUCCESS)
 Main PID: 319 (code=exited, status=0/SUCCESS)

Apr 13 10:22:59 openhab systemd[1]: Starting zram-config...
Apr 13 10:23:01 openhab systemd[1]: Started zram-config.
Apr 13 10:56:48 openhab systemd[1]: Stopping zram-config...
Apr 13 10:56:48 openhab zram-config[5079]: umount: /var/log: target is busy.
Apr 13 10:56:48 openhab zram-config[5079]: Warning: Stopping rsyslog.service, but it can still be activated by:
Apr 13 10:56:48 openhab zram-config[5079]:   syslog.socket
Apr 13 10:56:51 openhab zram-config[5079]: /usr/local/bin/zram-config: line 157: echo: write error: Device or resource busy
Apr 13 10:56:52 openhab zram-config[5079]: umount: /var/lib/openhab2 (overlay1) unmounted
Apr 13 10:57:07 openhab systemd[1]: zram-config.service: Succeeded.
Apr 13 10:57:07 openhab systemd[1]: Stopped zram-config.
[10:57:13] openhabian@openhab:~$ sudo systemctl status openhab2.service
● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/openhab2.service.d
           └─override.conf
   Active: inactive (dead) since Mon 2020-04-13 10:56:48 CEST; 46s ago
     Docs: https://www.openhab.org/docs/
           https://community.openhab.org
 Main PID: 666 (code=exited, status=0/SUCCESS)

Apr 13 10:56:32 openhab karaf[666]:         at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule.asyncStop(EquinoxBundle.java:156)
Apr 13 10:56:32 openhab karaf[666]:         at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle.stop(EquinoxBundle.java:262)
Apr 13 10:56:32 openhab karaf[666]:         at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle.stop(EquinoxBundle.java:267)
Apr 13 10:56:32 openhab karaf[666]:         at org.eclipse.osgi.launch.Equinox.stop(Equinox.java:123)
Apr 13 10:56:32 openhab karaf[666]:         at org.apache.karaf.main.Main$2.run(Main.java:354)
Apr 13 10:56:32 openhab karaf[666]: Caused by: java.util.concurrent.TimeoutException: Timeout after waiting 5 seconds to acquire the lock.
Apr 13 10:56:32 openhab karaf[666]:         at org.eclipse.osgi.container.Module.lockStateChange(Module.java:334)
Apr 13 10:56:32 openhab karaf[666]:         ... 5 more
Apr 13 10:56:48 openhab systemd[1]: openhab2.service: Succeeded.
Apr 13 10:56:48 openhab systemd[1]: Stopped openHAB 2 - empowering the smart home.
[10:57:36] openhabian@openhab:~$ sudo systemctl start openhab2.service
[10:59:56] openhabian@openhab:~$ sudo systemctl status openhab2.service
● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/openhab2.service.d
           └─override.conf
   Active: active (running) since Mon 2020-04-13 10:59:56 CEST; 10s ago
     Docs: https://www.openhab.org/docs/
           https://community.openhab.org
  Process: 5342 ExecStartPre=/bin/bash -c /usr/bin/find ${OPENHAB_CONF} -name "*.rules" -exec /usr/bin/rename.ul .rules .x {} \; (code=exited, status=0/SUCCESS)
  Process: 5345 ExecStartPost=/bin/sleep 120 (code=exited, status=0/SUCCESS)
  Process: 5930 ExecStartPost=/bin/bash -c /usr/bin/find ${OPENHAB_CONF} -name "*.x" -exec /usr/bin/rename.ul .x .rules {} \; (code=exited, status=0/SUCCESS)
 Main PID: 5344 (java)
    Tasks: 260 (limit: 2319)
   Memory: 426.0M
   CGroup: /system.slice/openhab2.service
           └─5344 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.logdir=/var/log/openhab2 -Dfelix.cm.dir=/var/

Apr 13 10:57:56 openhab systemd[1]: Starting openHAB 2 - empowering the smart home...
Apr 13 10:58:02 openhab karaf[5344]: org.ops4j.pax.url.wrap [org.ops4j.pax.url.commons.handler.HandlerActivator] DEBUG : Handler for protocols [wrap] started
Apr 13 10:59:56 openhab systemd[1]: Started openHAB 2 - empowering the smart home.
[11:00:11] openhabian@openhab:~$ sudo systemctl status zram-config.service
● zram-config.service - zram-config
   Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2020-04-13 10:57:07 CEST; 3min 7s ago
  Process: 5079 ExecStop=/usr/local/bin/zram-config stop (code=exited, status=0/SUCCESS)
 Main PID: 319 (code=exited, status=0/SUCCESS)

Apr 13 10:22:59 openhab systemd[1]: Starting zram-config...
Apr 13 10:23:01 openhab systemd[1]: Started zram-config.
Apr 13 10:56:48 openhab systemd[1]: Stopping zram-config...
Apr 13 10:56:48 openhab zram-config[5079]: umount: /var/log: target is busy.
Apr 13 10:56:48 openhab zram-config[5079]: Warning: Stopping rsyslog.service, but it can still be activated by:
Apr 13 10:56:48 openhab zram-config[5079]:   syslog.socket
Apr 13 10:56:51 openhab zram-config[5079]: /usr/local/bin/zram-config: line 157: echo: write error: Device or resource busy
Apr 13 10:56:52 openhab zram-config[5079]: umount: /var/lib/openhab2 (overlay1) unmounted
Apr 13 10:57:07 openhab systemd[1]: zram-config.service: Succeeded.
Apr 13 10:57:07 openhab systemd[1]: Stopped zram-config.
mstormi commented 4 years ago

Apr 13 10:56:51 openhab zram-config[5079]: /usr/local/bin/zram-config: line 157: echo: write error: Device or resource busy

Well not how it should be ... there's always one or two 'busy' zram devices you cannot remove. AFAIK it does not have any impact, zramctl shows more and higher numbered zram devices after one or more restarts but that's about it. I've added a second command (zramctl -r) on stop that seems to catch some but not all instances. Seems to be a problem with the zram/kernel implementation so not much I can do about it.

Did I correctly understand that except for that error, things seem to be fine ?

BClark09 commented 4 years ago

Hi all, did you manage to resolve this openHABian end?