[colug-432] SystemD: long-running NON-forking units?

Mike Plemmons mikeplemmons at gmail.com
Sat Feb 25 13:16:02 EST 2017


This may not be an answer you are looking for but one option could be to
add execstartpre and execstartpost entires to the postgres unit file that
does the tar and untar of /var.

Another option is to usb attach an external drive and have /var or at least
the postgres data on the external drive.


On Feb 25, 2017 12:19 PM, "Joshua Kramer" <joskra42.list at gmail.com> wrote:

> 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!
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20170225/dd68ca57/attachment.html 


More information about the colug-432 mailing list