0

I have written a bash script which I want to run every 60s (don't worry, I have tried the Script out, it runs perfectly).

Now I wanted to implement it in systemd .service file, but so far it doesn't restart. The script is beeing executed one time and ends with returncode 0 and then the service stops (for ever). So, it just runs ones, but then it ends.

It won't restart. I tried out many different things with RemainAfterExit, StartLimitIntervalSec or StartLimitBurst, but nothing worked.

Here is my .service-file:

[Unit]
Description=ExampleScript

[Service]
User=myuser
Restart=allways
RestartSec=60s
ExecStart=/bin/bash /home/myuser/start.sh
StartLimitIntervalSec=0

[Install]
WantedBy=multi-user.target

Maybe someone of you guys know about System.d and could help me? Thank you very much!



PS:

service-status while running the script:

* examplescript.service - ExampleScript
   Loaded: loaded (/usr/lib/systemd/system/examplescript.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-06-29 23:58:04 CEST; 1s ago
 Main PID: 31860 (bash)
   Memory: 15.6M
   CGroup: /system.slice/examplescript.service
           |-31860 /bin/bash /home/myuser/start.sh
           |-31862 /bin/bash /home/myuser/script/subscript.sh
           `-31871 python /home/myuser/script/subscript.py

Jun 29 23:58:04 mysystem systemd[1]: Started ExampleScript.

service-status after script is finish with rc0:

* examplescript.service - ExampleScript
   Loaded: loaded (/usr/lib/systemd/system/examplescript.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2018-06-29 23:58:48 CEST; 2min 42s ago
  Process: 31860 ExecStart=/bin/bash /home/myuser/start.sh (code=exited, status=0/SUCCESS)
 Main PID: 31860 (code=exited, status=0/SUCCESS)

Jun 29 23:58:04 mysystem  systemd[1]: Started ExampleScript.

...systemd is so freaking complicated, cron-job was so much easier

  • You do not have to install units system wide in /usr. There can be user units, ~/.local/share/systemd/user/ for "packages" or ~/.config/systemd/user/ for your personal units or overrides. – John Mahowald Jun 30 '18 at 16:22
3
[Service]
User=myuser
Restart=allways   # << fix that
RestartSec=60s
ExecStart=/bin/bash /home/myuser/start.sh
StartLimitIntervalSec=0

You've misspelled "always" on "Restart=".

  • Ohh, no!!!! Why didn't I see that?! ........ such a stupid mistake..... THANK YOU VERY MUCH!!!!! – hans2020dieter Jun 30 '18 at 10: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.