This apparently caused the shutdown to hang, and - of course - I did not have any consoles to debug exactly why the shutdown was hung. I was very tired, and wanted to get on with it, so I punched the power button on the workstation. My hardware changes (actually, a firmware change and fix for my SSDs) took about 3 hours, and during that time another computer was streaming videos from that NAS.
When I brought my workstation back up, and tried to connect to the NAS, the NAS crashed and wound up with a substantially damaged filesystem. In fact, I had to do a partial restore from backup.
I have observed in the past that rebooting this workstation without dismounting from the NAS can cause the NAS problems, but this time the fact that I was using the NAS from another computer after it got tangled up by losing my workstation made things bad.
Normally, the workstation has an iscsi share mounted from the NAS, and an NFS share, and a webdav share. I think the iscsi share is the one that tangles things up, but I am not certain of that. The other computer that was accessing the NAS was using CIFS to access the same NAS directory that the workstation mounts using NFS.
So, to deal with the fact that I often forget to dismount the NAS, I wrote a systemd service to handle all of that for me.
Here is the service, which I located in /etc/systemd/system):
- Code: Select all
[Unit]
Description = Unmount jssnas before shutdown
Before = final.target
After = shutdown.target
DefaultDependencies = no
[Service]
ExecStart = /usr/bin/unmountNAS
[Install]
WantedBy = shutdown.target
and here is the script unmountNAS that I wrote. Because I often have sshfs mounts running as well, I decided this would be a good place to unmount those too:
- Code: Select all
#! /bin/bash
# Unmount the JSS NAS and also any fuser filesystems that are mounted
# which is likely to include a webdav mount
# After all, we are shutting down so should clean things up.
#
umount /mnt/NAS
iscsiadm -m node --logout all
umount -f /mnt/Video
toggle=0
for fuse in fuse fuse.sshfs
do
Mnts=`mount -t $fuse`;
if [ -n "$Mnts" ]; then
for Mnt in $Mnts
do
if [ "$Mnt" == "on" ]; then
toggle=1;
elif [ "$toggle" -eq 1 ]; then
toggle=0;
fusermount -u $Mnt;
fi
done
fi
done
So, OK. I enabled my unmountnas.service, and this all works fine. I can unmount all this stuff by executing "systemctl start unmountnas.service".
My problem is that I am not quite sure where I want this located in the shutdown sequence. I am pretty sure that where I have placed it is too late in the shutdown sequence. It needs to run before stopping the network.
However, I am still wrapping my head around this systemd stuff, and I don't have a good handle about how the shutdown actually proceeds. Also, given that I can wind up with a damaged NAS if I get it wrong (hence, debugging is painful), I decided to ask here.
What should I put in the service definition for the Before and After parameters? Also, is my WantedBy correct?