On a specific machine I use a lot of RAM to serve websites really fast directly from RAM (which by the way is working amazingly well). For this I have mounted a ramdisk in /etc/fstab (in debian 7, via tmpfs) like so;
tmpfs /ramd tmpfs defaults,relatime,size=2G 0 0
I run a bunch of scripts in crontab to sync dirs from disk into /ramd when /ramd is empty, and from /ramd to disk when the dirs exist.
Now, obviously, I need to sync from RAMdisk to harddisk before a reboot, and back again in reverse at bootup.
I used to just run the sync from crontab every several minutes, but this is really overkill, since it has power backup and so it never shuts down unplanned, basically the only time it needs ram to sync back to disk.
I looked around and experimented for a while now, for the best ways to accomplish this without crontab. Just running sync scripts as init.d scripts seems awfully complex for the task. The only dependency for the syncjob would be that the ram is still mounted, so that would probably be
Required-stop: mountkernfs
and the only dependency at startup would be that nginx has not yet started, and of course that fstab has already been processed.
Any insight on how to best accomplish this, either with or without init script, is very welcome.
The reason init.d seems a bit odd is that it would not hold up after OS changes or upgrades. There's enough custom made in the system as it is.
find /webroot -type f -exec cat {} \; >/dev/null
might do it. Of course, this assumes there isn't sufficient memory pressure on the machine to cause pages to drop out of cache later. – Tom Hunt Dec 2 '15 at 17:37systemd
, you should be able to do this with aoneshot
service unit that requires a mount unit (for the tmpfs). You would put the copy from disk into tmpfs underExecStart
, and the copy from tmpfs into disk underExecStop
. If you configure the unit files under/etc/systemd
, they should survive any OS upgrades. – Tom Hunt Dec 2 '15 at 20:07