capistrano-puma: systemd: Neither a valid executable name nor an absolute path error because of ExecStart

Capistrano::Puma::Systemd is generating a systemd file for Puma with the below ExecStart value which uses the $HOME env var:

ExecStart=$HOME/.rbenv/bin/rbenv exec bundle exec puma -C /home/ubuntu/app/shared/puma.rb

This is causing the following error:

systemd/system/puma.service:9: Neither a valid executable name nor an absolute path: $HOME/.rbenv/bin/rbenv
service: Unit configuration has fatal error, unit will not be started.

Going through systemd’s manpage, it does say we need to use an absolute path for ExecStart: (https://man7.org/linux/man-pages/man5/systemd.service.5.html)

For each of the specified commands, the first argument must be either an absolute path...

Systemd version:

ubuntu@ip-172-31-86-176:/etc/systemd$ systemctl --version
systemd 245 (245.4-4ubuntu3.2)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid

Ubuntu version: Linux ip-172-31-86-176 5.4.0-1029-aws #30-Ubuntu SMP Tue Oct 20 10:06:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Hi, I finally solved my issue by modifying the systemd unit file /etc/systemd/system/puma_rasylva-web_production.service manually on my server. However, I think it’s a temporary solution, it may be better if the template can generate a more accurate systemd unit file.

GENERATED BY TEMPLATE (lib/capistrano/templates/puma.service.erb):

[Unit]
Description=Puma HTTP Server for rasylva-web (production)
After=network.target

[Service]
Type=simple
User=
WorkingDirectory=/home/rasylva/apps/rasylva-web/current
ExecStart=~/.rvm/bin/rvm 3.0.1 do bundle exec puma -C /home/rasylva/apps/rasylva-web/shared/puma.rb
ExecReload=/bin/kill -TSTP $MAINPID
StandardOutput=append:/home/rasylva/apps/rasylva-web/current/log/puma.error.log
StandardError=append:/home/rasylva/apps/rasylva-web/current/log/puma.access.log
Restart=always
RestartSec=1
SyslogIdentifier=puma

[Install]
WantedBy=multi-user.target

MODIFIED:

[Unit]
Description=Puma HTTP Server for rasylva-web (production)
After=network.target

[Service]
Type=simple
User=rasylva
Environment=RAILS_ENV=production PATH=/usr/local/bin:/home/rasylva/.rvm/rubies/ruby-3.0.1/bin:/home/rasylva/.nvm/versions/node/v14.17.0/bin
WorkingDirectory=/home/rasylva/apps/rasylva-web/current
ExecStart=/home/rasylva/apps/rasylva-web/current/sbin/puma -C /home/rasylva/apps/rasylva-web/shared/puma.rb /home/rasylva/apps/rasylva-web/current/config.ru > /home/rasylva/apps/rasylva-web/current/log/puma.access.log 2>/home/rasylva/apps/rasylva-web/current/log/puma.error.log
ExecReload=/bin/kill -TSTP $MAINPID
Restart=always
RestartSec=1
SyslogIdentifier=puma

[Install]
WantedBy=multi-user.target

Here are some notes of what makes it works and I think it may help others and improve capistrano-puma template:

  1. I need to specify User manually because I don’t specify puma_systemctl_user config (I just upgraded from the capistrano3-puma v3.1.1 and puma v3.11 to capistrano3-puma v5.0.4 and puma 5.3.0, and the previous config doesn’t have puma_systemctl_user)
  2. I need to add the rvm Environment so that it can run ruby command
  3. I need to add nvm Environment so that it can run node related command
  4. The config.ru file is needed, otherwise, it will show ERROR: No application configured, nothing to run
  5. I cannot use StandardOutput and StandardError because my systemd version somehow doesn’t recognize the append command, it shows an error: Failed to parse output specifier, ignoring: append:/home/rasylva/apps/rasylva-web/current/log/puma.error.log. The alternative way is using stdout and stderr redirection: <THE_PUMA_COMMAND> > /home/rasylva/apps/rasylva-web/current/log/puma.access.log 2>/home/rasylva/apps/rasylva-web/current/log/puma.error.log

For debugging the systemd, it may also be helpful for others: https://containersolutions.github.io/runbooks/posts/linux/debug-systemd-service-units/

Try putting set :rbenv_custom_path, "/home/ubuntu/.rbenv" into your deploy.rb

Thx to the @rizqirizqi I could fix the same problem using RVM too.

I just added the path to RVM instead of using the ~ to solve it. I didn’t need to add environment or other things

In my case changing the ~/.rvm to /home/deploy on line 9.