Skip to content

Instantly share code, notes, and snippets.

@choyno
Created June 11, 2019 01:48
Show Gist options
  • Save choyno/7869b8f382dae60aff31cf2c4ac63f13 to your computer and use it in GitHub Desktop.
Save choyno/7869b8f382dae60aff31cf2c4ac63f13 to your computer and use it in GitHub Desktop.
Adding Nginx and Puma To Service Registrar
"""" FOR NGINX """"
Create new file for register as service on Amazon Linux2
file path: /usr/lib/systemd/system/nginx.service
----------------------- code start
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
----------------------- code end
Create new symbolic file after create above file.
file path: /etc/systemd/system/multi-user.target.wants/nginx.service
cd /etc/systemd/system/multi-user.target.wants/
ln -s /usr/lib/systemd/system/nginx.service nginx.service
-----------------------
"""" FOR PUMA """
Create new file for register as service on Amazon Linux2
file path:/usr/lib/systemd/system/puma.service
----------------------- code start
[Unit]
Description=Puma Application Server
After=network.target
[Service]
Type=simple
User=ec2-user
WorkingDirectory=/home/ec2-user/app_backend_app/current
Environment="RBENV_ROOT=/home/ec2-user/.rbenv"
Environment="RBENV_VERSION=2.5.1"
Environment="RACK_ENV=staging"
ExecStart= /home/ec2-user/.rbenv/bin/rbenv exec bundle exec puma -C /home/ec2-user/app_backend_app/shared/puma.rb
TimeoutSec=300
Restart=always
[Install]
WantedBy=multi-user.target
Create new symbolic file after create above file.
file path: /etc/systemd/system/puma.service
----------------------- code end
Create new symbolic file after create above file.
file path: /etc/systemd/system/puma.service
cd /etc/systemd/system/multi-user.target.wants/
ln -s /usr/lib/systemd/system/puma.service puma.service
RESTART
PUMA AND NGINX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment