From bada4ecc1a09a3e4a98ae3449f6e6e7e6de19fef Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 2 Jan 2015 03:40:45 +0100 Subject: Initial commit --- mounting-music-dir-before-mpd.post | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 mounting-music-dir-before-mpd.post (limited to 'mounting-music-dir-before-mpd.post') diff --git a/mounting-music-dir-before-mpd.post b/mounting-music-dir-before-mpd.post new file mode 100644 index 0000000..789dda4 --- /dev/null +++ b/mounting-music-dir-before-mpd.post @@ -0,0 +1,39 @@ +;;;;; +title: Mounting music dir before MPD +tags: systemd, mpd, config +date: 2013-11-24 14:03 +format: md +;;;;; + +Systemd allows you to specify a program to run before running the main +daemon (or program) with `ExecStartPre`. This can, for instance, be +used to run a mount command before starting `mpd`. By adding under the +`[Service]` heading: + + ExecStartPre=/usr/bin/mount /mnt/music + +Now I have already setup my `fstab` to know what to mount on +`/mnt/music`, but of course that shouldn't be necessary. According to +the `systemd.service(5)` man page it uses the same syntax as +`ExecStart`, which tells us that one must use absolute file names +since no shell is used to start them. + +This also has the effect of stopping the `ExecStart` part from the +`.service` from being executed if the `ExecStartPre` doesn't finish +successfully. Which works out great in my case as I don't want to +start `mpd` if my music directory didn't mount. If you want to ignore +the exit status of (one of) the `ExecStartPre` commands you can prefix +it with a `-`, for example: + + ExecStartPre=-/usr/bin/mount /mnt/music + +Which would continue running the `ExecStart` even if mounting failed. + +Also know that there can be multiple `ExecStartPre` options and they +will be executed serially, so for example: + + ExecStartPre=/usr/bin/mount /mnt/music + ExecStartPre=-/usr/bin/mount /mnt/music2 + +This would fail if `/mnt/music` doesn't mount, but would continue just +fine if `/mnt/music` did and `/mnt/music2` didn't. -- cgit v1.2.3-54-g00ecf