<div dir="auto">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.<div dir="auto"><br></div><div dir="auto">Another option is to usb attach an external drive and have /var or at least the postgres data on the external drive.</div><div dir="auto"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Feb 25, 2017 12:19 PM, "Joshua Kramer" <<a href="mailto:joskra42.list@gmail.com">joskra42.list@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am trying to create a long-running RasPi system that will not burn<br>
through SD cards. The way to do this is to make /var and /tmp into<br>
RAM disks. However, I would like persistence for some things under<br>
/var. (This all came about because I noted that Postgres is as fast<br>
or faster than SQLite, and the app I'm running- HomeAssistant- causes<br>
SQLite to choke sometimes due to multiple writes at the same time.<br>
Postgres requires negligible resources as far as RAM and CPU for this<br>
application.)<br>
<br>
What I have are two systemd units. One is supposed to run upon<br>
shutdown or reboot; it will create a tarfile of the important things<br>
under /var and put that tarfile on the SD card. The second script<br>
runs upon startup- it explodes the tar file into /var, after /var is<br>
mounted as a RAM disk.<br>
<br>
The problem I have is, I can't get SystemD to pause startup while<br>
either of those scripts is running. On startup, SystemD starts the<br>
un-tar job and merrily carries along starting everything else,<br>
including some jobs (i.e. Postgres) that depend on files under /var.<br>
On shutdown, the tar file is truncated because the tar job is not<br>
finished by the time the shutdown target cuts the power.<br>
<br>
This is Raspbian. Though eventually I want to do the same thing with<br>
RedSleeve (it's a RHEL6/7 clone that runs on Raspi). Here is what I<br>
have. (Note that I have tried changing the Type to simple.)<br>
<br>
/etc/systemd/system/explode-<wbr>perm-var.service:<br>
<br>
[Unit]<br>
Description=Explode the permanent VAR file into tmpfs VAR<br>
DefaultDependencies=false<br>
Before=multi-user.target<br>
<br>
[Service]<br>
Type=notify<br>
ExecStart=/srv/perm-var/bin/<wbr>sys-startup.sh<br>
NotifyAccess=all<br>
<br>
[Install]<br>
RequiredBy=local-fs.target<br>
<br>
/srv/perm-var/bin/sys-startup.<wbr>sh:<br>
<br>
#!/bin/bash<br>
<br>
# Startup script: Un-Tar the var file!<br>
<br>
cd /<br>
tar xf srv/perm-var/perm-var.tar<br>
<br>
sleep 20<br>
<br>
systemd-notify --ready --status="VAR directory is ready"<br>
<br>
/etc/systemd/system/compress-<wbr>perm-var.service:<br>
<br>
[Unit]<br>
Description=Compress the tmpfs VAR into the permanent VAR file<br>
<br>
[Service]<br>
Type=notify<br>
ExecStart=/srv/perm-var/bin/<wbr>sys-shutdown.sh<br>
NotifyAccess=all<br>
<br>
[Install]<br>
RequiredBy=reboot.target shutdown.target<br>
<br>
/srv/perm-var/bin/sys-<wbr>shutdown.sh:<br>
<br>
#!/bin/bash<br>
<br>
cd /<br>
<br>
rm srv/perm-var/perm-var.tar<br>
tar --xattrs --acls -cf srv/perm-var/perm-var.tar var/cache/postgresql<br>
var/lib/apt var/lib/dpkg var/lib/aptitude var/lib/systemd<br>
var/lib/bluetooth var/lib/postgresql<br>
<br>
systemd-notify --ready --status="VAR is tarred!"<br>
<br>
-----<br>
Thanks!<br>
______________________________<wbr>_________________<br>
colug-432 mailing list<br>
<a href="mailto:colug-432@colug.net">colug-432@colug.net</a><br>
<a href="http://lists.colug.net/mailman/listinfo/colug-432" rel="noreferrer" target="_blank">http://lists.colug.net/<wbr>mailman/listinfo/colug-432</a><br>
</blockquote></div></div>