0

I'm attempting to write a systemd service file that will call a script to rollback a zfs dataset at startup and at shutdown. The startup part is working great, but I keep getting kernel panics on the shutdown process.

enter image description here

I think that systemd is going ahead and shutting down something important before zfs can complete the rollback.

Does anyone have any suggestions? Here is my current service file.

[Unit]
Description=Public Rollback Service
After=zfs.target
Requires=zfs.target

[Service]
Type=oneshot
ExecStart=/bin/sh /usr/local/bin/public_rollback.sh
RemainAfterExit=True
ExecStop=/bin/sh /usr/local/bin/public_rollback.sh

[Install]
WantedBy=multi-user.target

The script that it is calling is just:

 #!/bin/sh

 if zfs rollback $(zfs list -H -o name -t snapshot -r tank/public | tail -1); then
     exit 0
 else
     echo "Could not rollback public dataset! Aborting." 1>&2
     exit 1
 fi
1

So it looks like I was wrong about where the trouble was. Upon examining the logs, I was attempting to rollback the dataset while it was still busy (I'm assuming with the logoff procedure somehow).

I added an additional ExecStop=/bin/sleep 1 command before the main ExecStop command giving things time to be ready to be rolled back and I haven't had a problem since.

| improve this answer | |
0

Perhaps you can use two services: one for startup and one for shutdown. The one you have (minus the ExecStop directive) for startup. And something like this to trigger the script prior to shutdown:

[Unit]
Description=Public Rollback Shutdown Service
DefaultDependencies=no
Before=halt.target shutdown.target reboot.target

[Service]
Type=oneshot
ExecStart=/bin/sh /usr/local/bin/public_rollback.sh

[Install]
WantedBy=halt.target shutdown.target reboot.target 
| improve this answer | |
  • Thank you for your suggestion. I tried it out, but I'm still getting the error. I added a screenshot of the error in my original post. – chthonous Oct 3 '19 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.