Ruby app onetimesecret failing to start from systemd unit

user1540017 asked:

I’m trying to install ruby app onetimesecret on CentOS 7.4.1708 (Core)
by this manual: https://github.com/onetimesecret/onetimesecret.
Ruby is installed with rvm.

Everything is fine while running this command from shell:

/usr/local/rvm/rubies/ruby-2.3.8/bin/bundle exec thin -e dev -R config.ru -p 7143 -P /var/run/onetime/onetime.pid -l /var/log/onetime/onetime.log -d start

Server starts and works.

But it does not work with systemd unit.

[Unit]
Description=Onetime secret backend service
After=network.target
After=nginx.service

[Service]
Type=forking
RemainAfterExit=no
WorkingDirectory=/home/ots/onetimesecret
ExecStart=/usr/local/rvm/rubies/ruby-2.3.8/bin/bundle exec thin -e dev -R config.ru -p 7143 -P /var/run/onetime/onetime.pid -l /var/log/onetime/onetime.log -d start
TimeoutStopSec=10
PIDFile=/var/run/onetime/onetime.pid
Restart=on-failure
User=root
Group=root

[Install]
WantedBy=multi-user.target

Systemctl status onetime.service:

‚óŹ onetime.service - Onetime secret backend service
   Loaded: loaded (/etc/systemd/system/onetime.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Sun 2019-09-15 13:30:37 +04; 1s ago
  Process: 4296 ExecStart=/usr/local/rvm/rubies/ruby-2.3.8/bin/bundle exec thin -e dev -R config.ru -p 7143 -P /var/run/onetime/onetime.pid -l /var/log/onetime/onetime.log -d start (code=exited, status=1/FAILURE)
 Main PID: 2306 (code=exited, status=1/FAILURE)

Sep 15 13:30:36 vm-web-01 systemd[1]: onetime.service: control process exited, code=exited status=1
Sep 15 13:30:36 vm-web-01 systemd[1]: Failed to start Onetime secret backend service.
Sep 15 13:30:36 vm-web-01 systemd[1]: Unit onetime.service entered failed state.
Sep 15 13:30:36 vm-web-01 systemd[1]: onetime.service failed.
Sep 15 13:30:37 vm-web-01 systemd[1]: onetime.service holdoff time over, scheduling restart.
Sep 15 13:30:37 vm-web-01 systemd[1]: start request repeated too quickly for onetime.service
Sep 15 13:30:37 vm-web-01 systemd[1]: Failed to start Onetime secret backend service.
Sep 15 13:30:37 vm-web-01 systemd[1]: Unit onetime.service entered failed state.
Sep 15 13:30:37 vm-web-01 systemd[1]: onetime.service failed.

journalctl -xe:

Sep 15 13:30:36 vm-web-01 bundle[4296]: /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler [LoadError]
Sep 15 13:30:36 vm-web-01 bundle[4296]: from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
Sep 15 13:30:36 vm-web-01 bundle[4296]: from /usr/local/rvm/rubies/ruby-2.3.8/bin/bundle:10:in `<main>'
Sep 15 13:30:36 vm-web-01 bundle[4296]: from /usr/local/bin/ruby_executable_hooks:24:in `eval'
Sep 15 13:30:36 vm-web-01 bundle[4296]: from /usr/local/bin/ruby_executable_hooks:24:in `<main>'
Sep 15 13:30:36 vm-web-01 systemd[1]: onetime.service: control process exited, code=exited status=1
Sep 15 13:30:36 vm-web-01 systemd[1]: Failed to start Onetime secret backend service.

My answer:


You should call thin directly using the wrapper that RVM has provided for you. Without this, the system may end up running the wrong ruby, which indeed appears to be what happened.

For example:

ExecStart=/usr/bin/bash /usr/local/rvm/wrappers/%i/thin start <your options>

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.