0

New to systemd here - essentially I have 3 different scripts: activate.sh, toggle.sh, and deactivate.sh. I want to use a systemd service and timer in order to do the following:

  • When the service first starts, run activate.sh once
  • Using the timer, I want to continuously run toggle.sh until...
  • The service is stopped, in that case run deactivate.sh

I've tried experimenting with variations of ExecStart, ExecStartPre, ExecStop, RemainAfterExit, etc. but to no avail. Can someone point me in the right direction?

0

You should create three new unit files, something like these (untested):

mything.service:

[Unit]
Description=My custom thingy

[Service]
Type=service
ExecStart=/path/to/activate.sh
ExecStop=/path/to/deactivate.sh

[Install]
WantedBy=multi-user.target
Wants=togglemything.timer

togglemything.timer:

[Unit]
Description=My custom timer thingy

[Timer]
OnCalendar=hourly

togglemything.service:

[Unit]
Description=Toggle my custom thing

[Service]
Type=oneshot
ExecStart=/path/to/toggle.sh

The last two must have the same name, before the dot, or else the timer won't do anything.

You only need to do systemctl start mything to set the ball rolling.

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.