2
0
I just want to share a few thoughts about my first systemd configuration. So far I just used commands like start and stop this time I want more.
I have a raspberry-pi running arch. I have a external USB HDD to store data. I want to run samba to share folders on that external drive.
Problem: If the HDD is not attached, samba should not start. If the HDD is attached later samba should start then. If the HDD is detached during operation, samba should stop (possible data loss, I think there nothing I can do).
After reading examples and systemd manuals I got that:
/etc/fstab
UUID="6509-D18E" /storage vfat defaults,nofail,x-systemd.device-timeout=20 0 2
/etc/systemd/system/smbd.service:
[Unit]
Description=Samba SMB/CIFS server
After=network.target nmbd.service winbindd.service
BindsTo=storage.mount
RequiresMountsFor=/storage
[Service]
Type=forking
PIDFile=/var/run/smbd.pid
ExecStart=/usr/bin/smbd -D
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target storage.mount
The key elements are nofail in fstab, if it is missing my whole systems locked up during boot. I think it tells systemd to continue if the hdd is not connected.
The WantedBy is used to start samba if the hdd is connected and BindsTo is responsible to stop samba if the mount point vanished.
Am I missing something or is there even a more elegant solution?
cheers