Git Product home page Git Product logo

puma-nginx-systemd-itamae-recipe's Introduction

Itamae recipe for configuring Puma and Nginx with systemd.

Requirements

Build Docker image

COMPOSE_DOCKER_CLI_BUILD=1 docker-compose build

Build infra

dip terraform init
dip terraform plan
dip terraform apply

Save SSH private key to your machine.

Provision

export RAILS_MASTER_KEY=(cat config/master.key)

# All
itamae ssh -h puma-nginx -y itamae/nodes/centos.yml itamae/bootstrap.rb

# Nginx
itamae ssh -h puma-nginx -y itamae/nodes/centos.yml itamae/cookbooks/nginx/default.rb

# Rails
itamae ssh -h puma-nginx -y itamae/nodes/centos.yml itamae/cookbooks/rails/default.rb

Create Deploy key

export EC2_PUB_KEY=(ssh puma-nginx cat .ssh/authorized_keys)
export GITHUB_API_TOKEN=xxx

curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  -H "Authorization: token $GITHUB_API_TOKEN" \
  https://api.github.com/repos/shgtkshruch/puma-nginx-systemd-itamae-recipe/keys \
  -d '{ "title": "EC2_PUB_KEY", "key": " '"$EC2_PUB_KEY"' ", "read_only": "true" }'

ref: https://docs.github.com/en/rest/reference/repos#create-a-deploy-key

Deploy Rails

dip bash

eval `ssh-agent`
ssh-add puma-nginx-systemd.pem

cap production puma:nginx_config
cap production deploy

# optional
cap production puma:restart

Puma

register puma service to sytemd.

itamae ssh -h puma-nginx -y itamae/nodes/centos.yml itamae/cookbooks/puma/default.rb
# reload systemd unit files
sudo systemctl daemon-reload

# auto start
sudo systemctl enable puma

# commands
sudo systemctl start puma
sudo systemctl stop puma
sudo systemctl status -l puma

# check sytemd logs
$ journalctl -xe

SELinux

  1. raise SELinux error
  2. generate policy file
$ sudo grep nginx /var/log/audit/audit.log | audit2allow -m nginx
$ sudo checkmodule -M -m -o nginx.mod nginx.te
$ sudo semodule_package -o nginx.pp -m nginx.mod
  1. apply policy
$ sudo semodule -i nginx.pp

ref: https://nts.strzibny.name/allowing-nginx-to-use-a-pumaunicorn-unix-socket-with-selinux/

puma-nginx-systemd-itamae-recipe's People

Contributors

shgtkshruch avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.