How to use systemd to restart your Rails App at start up

There are many posts out there that talk about deploying your Rails App on any Linux distro and how to get it to start at boot, none of them worked for me, so I thought I would document here what I've tried.

Firstly create a file called <appname>.service in /etc/systemd/system with the following contents:

[Unit]
Description=Puma HTTP Server
After=network.target

[Service]
Type=simple

User=deployer

WorkingDirectory=/var/www/apps/appname/current

ExecStart=/bin/bash -lc 'bundle exec puma -C /var/www/apps/appname/shared/puma.rb

Restart=always

[Install]
WantedBy=multi-user.target

Don't forget to replace appname with your App's actual name. Then issue the following commands:

sudo systemctl enable <appname>.service

In order to enable the service
sudo systemctl start .service To start your App and finally
sudo systemctl status .service To check the status of your App.

Hope this will be helpful to you.