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 Answers 2

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>
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'
1
  • 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. Sep 17, 2019 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.