Unit puma_app_production.service has a bad unit file setting

Viewed 1511

When I start manually puma on the server - everything works as expected. But when I try to do it within Capistrano - I receive this error. Failed to restart puma_app_production.service: Unit puma_app_production.service has a bad unit file setting

to start puma I use also rbenv

these are my files puma_app_production.service

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


[Service]
Type=simple
User=rails_api
WorkingDirectory=/home/rails_api/apps/app/current
# Support older bundler versions where file descriptors weren't kept
# See https://github.com/rubygems/rubygems/issues/3254
ExecStart=RBENV_ROOT=/home/rails_api/.rbenv RBENV_VERSION=3.0.2 /home/rails_api/.rbenv/bin/rbenv exec bundle exec --keep-file-descriptors puma -C /home/rails_api/apps/app/shared/puma.rb
ExecReload=/bin/kill -USR1 $MAINPID
StandardOutput=append:/home/rails_api/apps/app/current/log/puma.access.log
StandardError=append:/home/rails_api/apps/app/current/log/puma.error.log




Restart=always
RestartSec=1

SyslogIdentifier=puma

[Install]
WantedBy=multi-user.target

I was trying to deal with this problem so I also added this line to deploy.rb file: append :rbenv_map_bins, 'puma', 'pumactl'

Any suggestions?

1 Answers

I'm not an expert, but I'm also fighting this at the moment.

The underlying problem is the inclusion of environment variables in ExecStart.

So extract RBENV_ROOT and RBENV_VERSION from ExecStart and include it into two separate Environment variables.

ExecStart=/home/rails_api/.rbenv/bin/rbenv exec bundle exec --keep-file-descriptors puma -C /home/rails_api/apps/app/shared/puma.rb
Environment=RBENV_ROOT=/home/rails_api/.rbenv
Environment=RBENV_VERSION=3.0.2 
Related