1

I would like to run a script after systemd loads some targets and halt/reboot the system after checking a condition.

My systemd service unit in /etc/systemd/system looks like this:

[Unit]
Description=My Service
After=local-fs.target
Before=basic.target

[Service]
ExecStart=/path/to/my-script

[Install]
WantedBy=local-fs.target

Inside my-script I have:

echo "script run $(date)" >> /home/kelvin/test.log

if [ condition ]; then
        reboot
        exit 0 
fi

exit 0

The scripts works if I run sudo systemctl start my-service, but it wont work on system startup.

Your Answer

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

Browse other questions tagged or ask your own question.