You are not logged in.

#1 2015-08-17 02:13:22

stbinan
Member
Registered: 2013-11-18
Posts: 8

[solved] Problem about running systemd unit for ruby gem bundler

According to Archwiki https://wiki.archlinux.org/index.php/Ru … ystem-wide , it's not recommended to install ruby gem system wide. I try to run a ruby service called puma.service. It looks like

[Unit]
Description=Puma application server
After=network.target

[Service]
WorkingDirectory=/var/www/my_app
Environment=RAILS_ENV=development
PIDFile=/var/www/my_app/shared/pids/puma.pid
ExecStart=/home/rails/.gem/ruby/2.2.0/bin/bundle exec \
         /home/rails/.gem/ruby/2.2.0/bin/puma \
         -b unix:///var/www/my_app/shared/sockets/puma.sock \
         --pidfile /var/www/my_app/shared/pids/puma.pid

[Install]
WantedBy=multi-user.target

I put it into /usr/lib/systemd/system/ and run the service with

# systemctl start puma.service

But when checking service status, it returns

Aug 17 09:32:25 pi1 systemd[1]: Started Puma application server.
Aug 17 09:32:25 pi1 systemd[1]: Starting Puma application server...
Aug 17 09:32:26 pi1 bundle[2452]: /usr/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 9 total gem(s) (Gem::LoadError)
Aug 17 09:32:26 pi1 bundle[2452]: Checked in 'GEM_PATH=/.gem/ruby/2.2.0:/usr/lib/ruby/gems/2.2.0', execute `gem env` for more information
Aug 17 09:32:26 pi1 bundle[2452]: from /usr/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
Aug 17 09:32:26 pi1 bundle[2452]: from /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
Aug 17 09:32:26 pi1 bundle[2452]: from /home/rails/rails/.gem/ruby/2.2.0/bin/bundle:22:in `<main>'
Aug 17 09:32:26 pi1 systemd[1]: puma.service: Main process exited, code=exited, status=1/FAILURE
Aug 17 09:32:27 pi1 systemd[1]: puma.service: Unit entered failed state.
Aug 17 09:32:27 pi1 systemd[1]: puma.service: Failed with result 'exit-code'.

Then with

# gem env

it returns

  - GEM PATHS:
     - /home/rails/.gem/ruby/2.2.0
     - /root/.gem/ruby/2.2.0
     - /usr/lib/ruby/gems/2.2.0

So why does systemd specify GEM_PATH to /.gem/ and what should I do?

[solved]

After I add

User=rails

in [Service], the service doesn't report error again.

[solved ver. 2]

Figure out that I don't need root privilege to run my service, then according to archwiki https://wiki.archlinux.org/index.php/Sy … w_it_works, I should put my own service into ~/.config/systemd/user/. Now the service can run without add user in [Service].

Last edited by stbinan (2015-08-17 15:40:25)

Offline

Board footer

Powered by FluxBB