Search code examples
ruby-on-railsraspbiansystemdrbenvruby-on-rails-6

Systemd Rails boot script fails with rbenv, (code=exited, status=1/FAILURE)


After creating a systemd service to launch a rails app, the service is failing with this error:

$ systemctl status evrserver
● evrserver.service - evr server boot
   Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Wed 2019-04-03 18:34:22 BST; 2min 51s ago
  Process: 425 ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66 (code=exited, status=1/FAILURE)
   CGroup: /system.slice/evrserver.service

Apr 03 18:34:22 raspberrypi systemd[1]: Failed to start evr server boot.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Unit entered failed state.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Failed with result 'exit-code'.

Setup based on other online tutorials for systemd starting a rails app in an rbenv managed environment as noted here:

https://gist.github.com/arteezy/5d53d99f6ee617fae1f0db0576fdd418

https://mikewilliamson.wordpress.com/2015/08/26/running-a-rails-app-with-systemd-and-liking-it/

Here is the service file:

[Unit]
Description=evr server boot
After=network.target
After=local-fs.target

[Service]
Type=forking
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always

[Install]
WantedBy=multi-user.target

This device has two other services that are custom implementations that are working with no issue, both non rails processes. What am I missing here to have the rails service run?


Solution

  • ah, kinda funny. it's always the little things yeah? forgot an exec before bundle and the type needs to be simple not forking.

    [Unit]
    Description=evr server boot
    After=network.target
    After=local-fs.target
    
    [Service]
    Type=simple
    User=pi
    Group=pi
    WorkingDirectory=/home/pi/evr
    ExecStart=/home/pi/.rbenv/bin/rbenv exec bundle exec rails s -b 192.168.1.66
    TimeoutSec=180
    RestartSec=180s
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    and successful logs:

    ● evrserver.service - evr server boot
       Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2019-04-04 04:05:45 BST; 8min ago
     Main PID: 460 (ruby)
       CGroup: /system.slice/evrserver.service
               └─460 puma 3.12.0 (tcp://192.168.1.66:3000) [evr]
    
    Apr 04 04:05:45 raspberrypi systemd[1]: Started evr server boot.
    Apr 04 04:06:08 raspberrypi rbenv[460]: => Booting Puma
    Apr 04 04:06:08 raspberrypi rbenv[460]: => Rails 6.0.0.beta3 application starting in development
    Apr 04 04:06:08 raspberrypi rbenv[460]: => Run `rails server --help` for more startup options
    Apr 04 04:13:51 raspberrypi rbenv[460]: Puma starting in single mode...
    Apr 04 04:13:51 raspberrypi rbenv[460]: * Version 3.12.0 (ruby 2.6.2-p47), codename: Llamas in Pajamas
    Apr 04 04:13:51 raspberrypi rbenv[460]: * Min threads: 5, max threads: 5
    Apr 04 04:13:51 raspberrypi rbenv[460]: * Environment: development
    Apr 04 04:13:51 raspberrypi rbenv[460]: * Listening on tcp://192.168.1.66:3000
    Apr 04 04:13:51 raspberrypi rbenv[460]: Use Ctrl-C to stop