bobafetthotmail / folder2ram

mount those folders to ram without losing access to their counterpart on disk!
GNU General Public License v3.0
110 stars 21 forks source link

Systemd unit OpenMediaVault #2

Closed subzero79 closed 8 years ago

subzero79 commented 8 years ago

The current systemd unit

[Unit]
Description=folder2ram systemd service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/folder2ram -mountall
ExecStop=/sbin/folder2ram -umountall
[Install]
WantedBy=local-fs.target

At the moment in OMV 3.0 the mounting of /var/log overlaps with the start of nginx, nginx is very strict, so checks existence of files in configuration, so it checks at /var/log/nginx/access.log the service fails completely leaving you with no webGUI. Same happens with syncthing plugin checking for the folder is suppose to store the logs. This was discovered using my home server, i tested and confirmed this also in a VM.

reading mail lists and systemd documentation I changed the systemd unit to this.

[Unit]
Description=folder2ram systemd service
DefaultDependencies=no
After=local-fs.target
Before=basic.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/folder2ram -mountall
ExecStop=/sbin/folder2ram -umountall

[Install]
WantedBy=basic.target

The folder2ram package should include the file service file in this folder /lib/systemd/system/

When enabled is required just systemctl enable folder2ram.service then the file will be placed at the corresponding target

bobafetthotmail commented 8 years ago

Yeah, I fixed that in my own private build already. Since you seem interested in doing some beta testing, can you test again with folder2ram 0.1.9 (just uploaded in git) + latest flashmemory plugin from the branch working with systemd? It should be good to go now.

"When enabled is required just systemctl enable folder2ram.service then the file will be placed at the corresponding target"

Can you systemctl enable that unit? I can't get systemctl to like my unit, so I had to generate the symlink (all systemctl does is making a symlink) through the script.

Is the DefaultDependencies=no that did the trick?

subzero79 commented 8 years ago

Can you systemctl enable that unit? I can't get systemctl to like my unit, so I had to generate the symlink (all systemctl does is making a symlink) through the script.

If I understand you need to ship your .service file in /lib/systemd/system or in your case as I look in the script, pipe the EOF script to /lib/systemd/system/folder2ram.service instead of /etc/folder2ram then when you do systemctl enable it should symlink properly from /etc/systemd/system/basic.target.wants/folder2ram.service

Is the DefaultDependencies=no that did the trick?

My understand is that installing to WantedBy=basic.target did the trick. Also added Before= which is I think more strict than Requires=. Anyway i got a basic idea from here http://lists.freedesktop.org/archives/systemd-devel/2010-September/000225.html

You can run systemd-analyze plot > plot.svg with the old unit, then run again the same with the new unit you'll will see that folder2ram takes less time and nginx is much further below. With old unit you can clearly see the start overlapping

subzero79 commented 8 years ago

Works fine with new version (tested in VM), but i don't know why you change the code to rsync.

This with the new folder2ram with rsync https://dl.dropboxusercontent.com/u/54639/plot.svg

This is the old folder2ram but with the changed systemd unit you provided now (not mine) https://dl.dropboxusercontent.com/u/54639/plot1.svg

Almost doubles the time with rsync.

bobafetthotmail commented 8 years ago

"pipe the EOF script to /lib/systemd/system/folder2ram.service"

I already tried that with my own unit file, either placing it in /lib/systemd/system OR placing it in /etc/systemd/system (the place where admins can place their custom modifications and that overrides what is in /lib/systemd/system ).

systemctl enable (all possible arguments, just "folder2ram", "folder2ram.service", the full path)

And it kept giving the same error about wrong syntax or something. I did post in the systemd mailing list, but none had any clue.

"My understand is"

thanks for the hint, will do some more testing about that later, it'd be cool to have my script enabled without having to do weird tricks.

Also, the plot is nifty. Didn't know about that.

"i don't know why you change the code to rsync."

rsync deletes stuff that was there at boot but was deleted in the tmpfs folder. with cp (older method) there is no such check.

For example: -day 1 I shutdown and in the folder there is file loggggggXXX.log -day 2 I boot, and folder2ram loads that, a program renames the log into loggggggYYYYY.log. -on shutdown in the system drive I get both loggggggXXX.log AND loggggggYYYYY.log.

This can go on and on until I get a folder full of trash in both system drive and tmpfs.

The other choice is simply doing a rm -rf /folder/on/system/drive/* before doing the cp thing which isn't terribly safe nor fast, if the process is terminated before I can sync, the system is wasted (OMV mostly, debian does not terribly care about logs or nginx) and I lose all logs of various things...

No wait a sec. Hmmmmm....

On startup there is no need for rsync's advanced delete features as the tmpfs folder is always empty in any case.... reverting startup code back to using cp.... :|

subzero79 commented 8 years ago

And it kept giving the same error about wrong syntax or something. I did post in the systemd mailing list, but none had any clue.

I found it. I don't know why but EOF puts this <feff> at the end of local-fs.target, nano won't display, only i'll show with vi

Edit: it comes actually from your /sbin/folder2ram script screen shot 2016-02-01 at 10 07 55 am

bobafetthotmail commented 8 years ago

Thanks. I always edited that file from Linux Mint Debian, with gedit. I have no idea about why a feff is in there. :/

Anyway, updated the script, now using your systemd service and all is fine.

Closing this issue.