1

I'm running a service on a EC2 instance that should boot at start and whenever the script associated fails.

So I wrote the service like this:

[Unit]
Description=Test

[Service]
User=ubuntu
Type=simple
ExecStart=/usr/bin/ruby /home/ubuntu/main/test.rb
Restart=on-failure
RestartSec=1s

[Install]
WantedBy=multi-user.target

But when I kill the process or reboot the server, the service won't start. The service is enabled, and when I manually start it, it works as expected.

4
  • What does journelctl --unit=Test give you?
    – turtle
    Jan 9, 2023 at 15:52
  • Nothing. It runs smoothly if I start it, but it simply won't start both at boot or if i kill the process.
    – Voley Betz
    Jan 9, 2023 at 16:53
  • For example now I killed it and it gives me this: test.service - Test Loaded: loaded (/etc/systemd/system/test.service; enabled; vendor preset: enabled) Active: inactive (dead) since Mon 2023-01-09 16:49:21 UTC; 1min 32s ago Process: 35430 ExecStart=/usr/bin/ruby /home/ubuntu/main/test.rb (code=killed, signal=TERM) Main PID: 35430 (code=killed, signal=TERM) CPU: 20.558s
    – Voley Betz
    Jan 9, 2023 at 16:54
  • try testing it with Restart=always, take a look at the exit status documentation here freedesktop.org/software/systemd/man/systemd.service.html
    – turtle
    Jan 9, 2023 at 17:22

1 Answer 1

0

Restart=on-failure will not consider a 'killed process' a failure. Change Restart=on-failure to Restart=always to instruct systemd to always restart the process. See https://www.freedesktop.org/software/systemd/man/systemd.service.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .