0

I'm really getting crazy trying to figure out why my systemd service won't start at boot, or whenever the ruby script associated fails (like what should do in my intention). I'm running it on a EC2 Ubuntu instance.

Here's the code of the service:

[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

I tried changing the target, or the user name, or the type...nothing happens. And the journal doesn't give me any particular info. The service works smoothly if I start it.

But if the script fails, or whenever I kill it to test it, it just ignore the restart thing.

1
  • 1
    Did you enable the service? Also what do you get when using sudo systemctl status yourservice? A Jan 9, 2023 at 17:58

1 Answer 1

0

This sounds like a dependence issue.

Systemd is running and your script needs Ruby running beforehand to execute. So on startup this service could be running before Ruby loads/finishes. And that's why you can run it after the box is up and running.

Look at adding under [Unit] 'After=' whatever the service name is for the Ruby environment. (I'm not sure what that would be.)

Then Systemd should wait for Ruby to load before trying to load up the service.

Look at your Ruby script and see what dependencies it may need. For example, maybe it needs the network up and running beforehand. Under [Unit] you can add 'After=' and then the needed dependence.

After=network.target

This is why after the box is up and running you can start the service, the needed dependencies have loaded.

2
  • but Ruby is not a daemon that needs to be running. Ruby is just the interpreter for that ruby script. Jan 9, 2023 at 17:51
  • Well, that's true, but without knowing what's inside the Ruby file, it could be another dependence issue. Maybe the script needs the network and that hasn't finished loading up. That's just my guess on what's going on here, as to why it runs after the box is up.
    – TechLoom
    Jan 9, 2023 at 17:55

You must log in to answer this question.

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