A systemd script for s3ql remote FUSE mounting

1

I find systemd very exciting, but how would I use it to write a script to mount an s3ql filesystem? For example, the s3ql developer provides an upstart config that does the job.

Specifically, on startup mount.s3ql must be run (as the desired user as this is a FUSE filesystem), and on shutdown umount.s3ql must be run. In addition, what if we want to fsck.s3ql the filesystem before mounting, or run a Unison synchronization step after startup and before shutdown (all modifications I have made on my own personal upstart).

At first glance I would think I would want to setup a mount unit on systemd, but it appears that the service unit actually fits better with pre and post exec startup commands. (All the man pages are available here.)

And what .target do I depend on to encode the dependency on a network connection?

JKnight

Posted 2012-02-15T19:47:01.100

Reputation: 113

Answers

1

At first, it seems that for mount.s3ql and umount.s3ql, a generic .mount unit might be appropriate. Both the mount command and systemd support mount.fstype helpers when mounting. However, the helper must support the standard -o options method of passing options, which s3ql does not. Also, the same limitations apply as with /etc/fstab.

So you might actually be better with a .service unit that calls the desired commands:

[Unit]
Wants=unison@s3ql.service
After=unison@s3ql.service

[Service]
Type=forking
Environment=AUTHFILE=/path/to/authinfo2
ExecStart=/usr/sbin/mount.s3ql --authfile ${AUTHFILE} ${BUCKET} ${MOUNTPOINT}
ExecStop=/usr/sbin/umount.s3ql ${MOUNTPOINT}
TimeoutSec=5min

Since there is no standard way of configuring networks, much less one that actually checks whether the connection is actually working, there is no standard systemd target for what you want. There is network.target, though, but it might consider itself started when the connection is not available yet.

If you are using NetworkManager, your distribution might have included a unit that runs nm-online – for example, Arch calls it NetworkManager-wait-online.service.

[Unit]
Require=NetworkManager-wait-online.service
After=NetworkManager-wait-online.service

user1686

Posted 2012-02-15T19:47:01.100

Reputation: 283 655

1mount.s3ql supports -o options (and always has). Recent versions also come with systemd notification support, so Type=forking is no longer correct. – Nikratio – 2016-03-16T16:36:46.087