[colug-432] SystemD: long-running NON-forking units?
Joshua Kramer
joskra42.list at gmail.com
Sat Feb 25 12:16:47 EST 2017
Hello,
I am trying to create a long-running RasPi system that will not burn
through SD cards. The way to do this is to make /var and /tmp into
RAM disks. However, I would like persistence for some things under
/var. (This all came about because I noted that Postgres is as fast
or faster than SQLite, and the app I'm running- HomeAssistant- causes
SQLite to choke sometimes due to multiple writes at the same time.
Postgres requires negligible resources as far as RAM and CPU for this
application.)
What I have are two systemd units. One is supposed to run upon
shutdown or reboot; it will create a tarfile of the important things
under /var and put that tarfile on the SD card. The second script
runs upon startup- it explodes the tar file into /var, after /var is
mounted as a RAM disk.
The problem I have is, I can't get SystemD to pause startup while
either of those scripts is running. On startup, SystemD starts the
un-tar job and merrily carries along starting everything else,
including some jobs (i.e. Postgres) that depend on files under /var.
On shutdown, the tar file is truncated because the tar job is not
finished by the time the shutdown target cuts the power.
This is Raspbian. Though eventually I want to do the same thing with
RedSleeve (it's a RHEL6/7 clone that runs on Raspi). Here is what I
have. (Note that I have tried changing the Type to simple.)
/etc/systemd/system/explode-perm-var.service:
[Unit]
Description=Explode the permanent VAR file into tmpfs VAR
DefaultDependencies=false
Before=multi-user.target
[Service]
Type=notify
ExecStart=/srv/perm-var/bin/sys-startup.sh
NotifyAccess=all
[Install]
RequiredBy=local-fs.target
/srv/perm-var/bin/sys-startup.sh:
#!/bin/bash
# Startup script: Un-Tar the var file!
cd /
tar xf srv/perm-var/perm-var.tar
sleep 20
systemd-notify --ready --status="VAR directory is ready"
/etc/systemd/system/compress-perm-var.service:
[Unit]
Description=Compress the tmpfs VAR into the permanent VAR file
[Service]
Type=notify
ExecStart=/srv/perm-var/bin/sys-shutdown.sh
NotifyAccess=all
[Install]
RequiredBy=reboot.target shutdown.target
/srv/perm-var/bin/sys-shutdown.sh:
#!/bin/bash
cd /
rm srv/perm-var/perm-var.tar
tar --xattrs --acls -cf srv/perm-var/perm-var.tar var/cache/postgresql
var/lib/apt var/lib/dpkg var/lib/aptitude var/lib/systemd
var/lib/bluetooth var/lib/postgresql
systemd-notify --ready --status="VAR is tarred!"
-----
Thanks!
More information about the colug-432
mailing list