13 March 2017

I run some servers that use a ramdisk to increase performance for recording audio files. Since ramdisks evaporate on a reboot, and I have services that depend on the ramdisk to operate properly, I needed a way to:

  • Automatically create the ramdisk on boot
  • Ensure it’s set up prior to the services that depend on it
  • Perform cleanup on the ramdisk when the server is shut down

The set of scripts below accomplish this nicely by leveraging systemd. Here’s a quick rundown of what each does:

  • ramdisk: The script is written as a System V init script, and would be placed at /etc/init/ramdisk. Does the work of:
    • Creating the ramdisk
    • Calling an optionally configured script to perform cleanup prior to tearing down the ramdisk
  • customize: This is an optional file to override the default settings of the first script. Place it at /etc/default/ramdisk with any customizations you like.
  • ramdisk.service: systemd service file that calls the start/stop functions of ramdisk. Place this anywhere systemd recognizes service scripts, and run systemctl daemon-reload.

The nice thing about this setup through systemd is that any other systemd services that depend on the ramdisk being set up can simply include this in their service description:

Requires=ramdisk.service
After=ramdisk.service