I have a systemd service where I have an issue with stopping the service at the time of reboot.
The script /home/user1/bin/myscript-shutdown relies on filesystem to be up. But it looks like the file system is shutdown (disks unmounted) before completion of /home/user1/bin/myscript-shutdown.
How can I correct the following so the ExecStop script completes first before shutting down any system related services like Storage, Network etc. Likewise, when the system is restarted I want all the system services (storage, Network) started before my service comes up.
I am guessing the trick is in After/Before/Wants but I don't know the correct values.
This is what I currently have:
[Unit]
Description=My Service
After=syslog.target network.target
Wants=network.target
Before=shutdown.target reboot.target halt.target kexec.target
[Service]
RemainAfterExit=yes
User=user1
Group=group1
LimitNOFILE=65536
LimitMEMLOCK=infinity
ExecStart=/home/user1/bin/myscript-startup
ExecStop=/home/user1/bin/myscript-shutdown
TimeoutStopSec=15min
[Install]
WantedBy=multi-user.target