3

On EL7 (RedHat 7, CentOS 7, etc) I have a systemd unit file to mount a filesystem (/usr/lib/systemd/system/srv-data.mount) that looks like this:

[Unit]
After=sysinit.target

[Mount]
What=/dev/disk/by-uuid/68e9e9f7-3dbe-4c04-b1f8-f32fea773503
Where=/srv/data
Type=ext4
Options=noatime,nodiratime,journal_async_commit

[Install]
WantedBy=multi-user.target

This works well. However, I want to run a one shot script before this filesystem is mounted to ensure that the external journal for the filesystem has the correct device major and minor numbers. I have a working script to do this called journalfix. I have setup a one shot systemd service to run the script (/usr/lib/systemd/system/journalfix.service):

[Unit]
After=sysinit.target
Requires=sysinit.target

[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/bin/journalfix 68e9e9f7-3dbe-4c04-b1f8-f32fea773503

[Install]
WantedBy=multi-user.target

And changed srv-data.mount to depend on the oneshot service:

[Unit]
After=sysinit.target journalfix.service
Requires=journalfix.service

However, I can't get the one shot script to run reliably on reboot. What happens is that the script runs before /dev/disk/by-uuid is populated and my script fails to run correctly as a result. I understand that I need to find the correct target or service that populates this directory, but everything I have tried has not worked (sysinit.target, local-fs.target, basic.target).

One additional thing to note is that the srv-data.mount filesystem is on a an mdraid device. I think this is delaying the uuid from showing up in /dev/disk/by-uuid.

How can I get my oneshot service to reliably wait for /dev/disk/by-uuid/<uuid> to show up?

Kurt Miller
  • 131
  • 5
  • 2
    I don't have enough rep to post my own answer, but I found the solution. Use system.device dependency (http://www.freedesktop.org/software/systemd/man/systemd.device.html). The trick is that the dashes need to escaped so that '-' turns into '\x2d' and path slashes turn into '-'. For example the After line in 'journalfix.service' would look like this: After=dev-disk-by\x2duuid-68e9e9f7\x2d3dbe\x2d4c04\x2db1f8\x2df32fea773503.device – Kurt Miller Mar 24 '15 at 21:19

0 Answers0