diff --git a/group_vars/all b/group_vars/all index f0ef0165..01b381cd 100644 --- a/group_vars/all +++ b/group_vars/all @@ -34,6 +34,12 @@ database_user: "{{ deploy_user }}" database_password: "{{ deploy_user }}" database_hostname: "localhost" +# Puma +puma_service_unit_name: "puma_{{ app_name }}_{{ env }}" +puma_config_file: "{{ release_dir }}/config/puma/{{ env }}.rb" +puma_access_log: "{{ shared_dir }}/log/puma_access.log" +puma_error_log: "{{ shared_dir }}/log/puma_error.log" + #SMTP smtp_address: "smtp.example.com" smtp_port: 25 diff --git a/roles/puma/tasks/main.yml b/roles/puma/tasks/main.yml index 41831f10..3e471591 100644 --- a/roles/puma/tasks/main.yml +++ b/roles/puma/tasks/main.yml @@ -7,26 +7,17 @@ - "pids" - "sockets" -- name: Check that puma is running - stat: - path: "{{ shared_dir }}/tmp/pids/puma.pid" - register: puma_process - -- name: Get running puma process - shell: "cat {{ shared_dir }}/tmp/pids/puma.pid" - register: running_process - when: puma_process.stat.exists == True - -- name: Kill running process - shell: "kill -QUIT {{ item }}" - with_items: "{{ running_process.stdout_lines }}" - when: puma_process.stat.exists == True +- name: Copy Puma service file to the systemd folder + template: + src: "{{ playbook_dir }}/roles/puma/templates/puma.service" + dest: "{{ home_dir }}/.config/systemd/user/puma.service" - name: Start puma - shell: "source {{ home_dir }}/.rvm/scripts/rvm && bundle exec puma -C {{ release_dir }}/config/puma/{{ env }}.rb -e {{ env }} -d" - args: - chdir: "{{ release_dir }}" - executable: /bin/bash + systemd: + name: "{{ puma_service_unit_name }}" + enabled: true + state: started + scope: user - name: Make sure Nginx has write access to the puma socket shell: "chmod o+w tmp/sockets/*" diff --git a/roles/puma/templates/puma.service b/roles/puma/templates/puma.service new file mode 100644 index 00000000..32f4c993 --- /dev/null +++ b/roles/puma/templates/puma.service @@ -0,0 +1,17 @@ +[Unit] +Description=Puma HTTP Server for {{ app_name }} ({{ env }}) +After=network.target + +[Service] +Type=simple +WorkingDirectory={{ release_dir }} +ExecStart=bundle exec --keep-file-descriptors puma -C {{ puma_config_file }} +ExecReload=/bin/kill -USR1 $MAINPID +StandardOutput=append: {{ puma_access_log }} +StandardError=append: {{ puma_error_log }} +Restart=always +RestartSec=1 +SyslogIdentifier=puma + +[Install] +WantedBy=default.target