How to Run Rails App Server with Systemd and Ansible

Create a systemd service to run your rails app server. 

Ansible tasks to create the service:



    rails_root: "/myapp"
    rails_user: "webuser"

    - name: Setup Rails Web Service
        dest: /usr/lib/systemd/system/rails-web.service
        src: templates/rails-web.systemd.j2

    - name: Enable Rails Web Service
        name: rails-web
        daemon_reload: yes
        enabled: yes
        masked: no

The ansible template "rails-web.systemd.j2":

Description=Rails Web

User={{ rails_user }}
PIDFile={{ rails_root }}/tmp/pids/
WorkingDirectory={{ rails_root }}
ExecStart=/bin/bash -l -c "{{ rails_root }}/bin/rails s -b -p 3000"
ExecReload=/bin/kill -s USR2 $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID


But you can also do this manually by creating the file `/usr/lib/systemd/system/rails-web.service` and then runninh `systemctl daemon-reload` to let systemd know about your service. Now you can start it up with systemctl start rails-web!

Did you like this post? Let me know by sending me a message. Is there a topic you would like me to cover? Let me know about that too. I look forward to hearing from you!

Let's Connect!