1

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.

2 Answers2

1

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>
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

I've googled right answer: https://mikewilliamson.wordpress.com/2015/08/26/running-a-rails-app-with-systemd-and-liking-it/

So, I have to add "/usr/bin/bash -lc" to command in ExecStart. It will be:

ExecStart = /usr/bin/bash -lc '/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'
  • That should also work, though it's very strange that he used `-l`. This should not be necessary and might open up a security problem in some contexts. – Michael Hampton Sep 17 '19 at 22:10