Skip to content

Instantly share code, notes, and snippets.

@fzrhrs
Created August 27, 2024 09:47
Show Gist options
  • Save fzrhrs/f6866e1074fee231ce9a6143d7b3c82d to your computer and use it in GitHub Desktop.
Save fzrhrs/f6866e1074fee231ce9a6143d7b3c82d to your computer and use it in GitHub Desktop.
WIP - Setup service and socket

Assume the name of the application is "website":

For socket: sudo vi /etc/systemd/system/website_puma_production.socket

[Unit]
Description=Puma Socket for website (production)

[Socket]
ListenStream=/home/deploy/website/shared/sockets/puma.sock

[Install]
WantedBy=sockets.target

Then, enable and start the socket: sudo systemctl enable website_puma_production.socket sudo systemctl start website_puma_production.socket

Enabling the socket will create a symlink in the folder: /etc/systemd/system/sockets.target.wants/

To setup both sudo systemctl daemon-reload sudo systemctl enable website_puma_production.service sudo systemctl enable website_puma_production.socket

Start socket first, as it needs to be up before Puma starts: sudo systemctl start website_puma_production.socket

Now start the Puma service: sudo systemctl start website_puma_production.service

Ensure both the socket and the service are running without issues: sudo systemctl status website_puma_production.socket sudo systemctl status website_puma_production.service

Check if the puma.sock file is created and properly recognized as a socket: ls -l /home/deploy/website/shared/sockets/puma.sock

The file should have a srwxr-xr-x permission with an s at the beginning, indicating it is a socket file.

Check Puma's logs to confirm that it's running without issues: journalctl -u website_puma_production.service -e

Finally, visit your application in the browser to ensure it’s working correctly. If everything is set up properly, your site should load without the 502 error.

In the future, if you make changes to your Puma or systemd configuration, you can restart or reload the services: sudo systemctl restart website_puma_production.service sudo systemctl restart website_puma_production.socket

To restart: sudo systemctl reload website_puma_production.service

Check the status of both the socket and service to ensure they are active: sudo systemctl status website_puma_production.socket

Enabling the Socket and Service Enable the Socket: sudo systemctl enable website_puma_production.socket

Enable the Service:

sudo systemctl enable website_puma_production.service

Verify They Are Enabled You can check if they are enabled using: systemctl is-enabled website_puma_production.socket systemctl is-enabled website_puma_production.service sudo systemctl status website_puma_production.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment