1

If I run this command from terminal, it works fine:

bundle exec /home/ubuntu/.rbenv/shims/puma -C /var/www/html/mysite/config/puma.rb

But if I was to put that in ExecStart in a systemd service unit file:

[Unit]
Description=Puma Application HTTP Server
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/www/html/mysite

ExecStart=bundle exec /home/ubuntu/.rbenv/shims/puma -C /var/www/html/mysite/config/puma.rb


Restart=always

[Install]
WantedBy=multi-user.target

I will get error:

Executable path is not absolute: bundle exec /home/ubuntu/.rbenv/sh

I think it's complaining that the command must begin with absolute path instead of 'bundle exec'. So I try this:

ExecStart=/bin/bash -lc 'bundle exec /home/ubuntu/.rbenv/shims/puma -C /var/www/html/mysite/config/puma.rb'

Now when I run systemctl daemon-reload and systemctl start puma-mysite, I get this error:

Jan 03 00:07:53 ip-10-0-1-133 systemd[1]: puma-mysite.service: Start request repeated too quickly.

Jan 03 00:07:53 ip-10-0-1-133 systemd[1]: puma-mysite.service: Failed with result 'exit-code'.

Jan 03 00:07:53 ip-10-0-1-133 systemd[1]: Failed to start Puma Application HTTP Server.

It seems to be an issue with SystemD, for the command works outside of SystemD.

2 Answers 2

1

I got it working by giving bundle command an absolute path too:

ExecStart=/home/ubuntu/.rbenv/shims/bundle exec /home/ubuntu/.rbenv/shims/puma -C /var/www/html/mysite/config/puma.rb

2
  • Makes sense. “bundle” wasn’t in root’s $PATH so systemd couldn’t exec it, so the bash shell just exited.
    – jsbillings
    Jan 3, 2020 at 3:21
  • I found this question while experiencing the start request too quickly problem. I'm using python virtual env and already have the full path to the python virtual env and full path to the python file. Oddly I can start the service and run the script, it will write to the log files in the same dir as the python script during startup and for days after startup. I'm going to try a time.sleep(120) within the python script. I can't see any config option in systemctl .service files to configure a delay during startup ?? maybe this? askubuntu.com/questions/711535/delay-startup-service Aug 17, 2022 at 1:54
1

I found this while researching solution to a similar problem.

another forum suggested this as a solution.

[Service]
ExecStartPre=-/bin/sleep 5
EnvironmentFile=/etc/default/bind9

https://askubuntu.com/questions/711535/delay-startup-service https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

also

https://stackoverflow.com/questions/43001223/how-to-ensure-that-there-is-a-delay-before-a-service-is-started-in-systemd

solutions offered here include

ExecStartPost=/bin/sleep 30

and

[Timer]
OnActiveSec=5sec
AccuracySec=1s

[Install]
WantedBy=timers.target

https://askubuntu.com/questions/1144764/sleep-not-working-in-service

[service] 
TimeoutSec=infinity

You must log in to answer this question.

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