Skip to content

Commit

Permalink
Enable puma socket activation
Browse files Browse the repository at this point in the history
  • Loading branch information
Senen committed Feb 2, 2024
1 parent 4076398 commit 5ce1152
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
17 changes: 16 additions & 1 deletion roles/puma/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
src: "{{ playbook_dir }}/roles/puma/templates/puma.service"
dest: "{{ home_dir }}/.config/systemd/user/{{ puma_service_unit_name }}.service"

- name: Copy Puma socket file to the systemd folder
template:
src: "{{ playbook_dir }}/roles/puma/templates/puma.socket"
dest: "{{ home_dir }}/.config/systemd/user/{{ puma_service_unit_name }}.socket"

- name: Get distribution codename
shell: lsb_release -c --short
register: distro_codename
Expand All @@ -36,9 +41,19 @@
shell: "id -u"
register: current_uid

- name: Enable puma socket activation
systemd:
name: "{{ puma_service_unit_name }}.socket"
daemon_reload: true
enabled: true
state: started
scope: user
environment:
XDG_RUNTIME_DIR: "/run/user/{{ current_uid.stdout }}"

- name: Start puma
systemd:
name: "{{ puma_service_unit_name }}"
name: "{{ puma_service_unit_name }}.service"
daemon_reload: true
enabled: true
state: started
Expand Down
1 change: 1 addition & 0 deletions roles/puma/templates/puma.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Unit]
Description=Puma HTTP Server for {{ app_name }} ({{ env }})
After=network.target
Requires={{ puma_service_unit_name }}.socket

[Service]
Type=simple
Expand Down
20 changes: 20 additions & 0 deletions roles/puma/templates/puma.socket
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Puma HTTP Server Accept Sockets for {{ app_name }} ({{ env }})

[Socket]
ListenStream={{ shared_dir }}/tmp/sockets/puma.sock

# Don't let systemd accept the request, wait for Puma to do that.
# Systemd will start the puma service upon first request if it wasn't started.
#
# You might also want to set your Nginx upstream to have a fail_timeout large enough to accomodate your app's
# startup time.
Accept=no

ReusePort=true
Backlog=1024

SyslogIdentifier=puma_socket

[Install]
WantedBy=sockets.target

0 comments on commit 5ce1152

Please sign in to comment.