wiki/HowtoPuma.md

112 lines
1.9 KiB
Markdown
Raw Normal View History

2017-07-04 18:15:31 +02:00
---
categories: web
title: Howto Puma
...
2016-12-29 11:25:39 +01:00
2017-07-04 18:15:31 +02:00
[Puma](http://puma.io/) est un serveur d'application Ruby on rails.
2016-12-29 11:25:39 +01:00
2017-07-04 18:45:23 +02:00
## Prérequis
Installation de ruby :
~~~
apt install ruby
~~~
2016-12-29 11:25:39 +01:00
Installation de Puma :
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
~~~
gem install puma
~~~
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
Création du dossier de configuration :
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
~~~
2017-07-04 18:15:31 +02:00
mkdir -m 0750 /etc/puma
2016-12-29 11:25:39 +01:00
~~~
2017-01-14 00:06:38 +01:00
2017-07-04 18:45:23 +02:00
Création d'un service SystemD en mode utilisateur :
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
~~~
2017-07-04 18:15:31 +02:00
cat > /etc/systemd/user/puma.service <<EOF
2016-12-29 11:25:39 +01:00
[Unit]
2017-07-04 18:15:31 +02:00
Description=Puma HTTP server for Ruby Apps : %u
2016-12-29 11:25:39 +01:00
After=network.target
[Service]
2017-07-04 18:15:31 +02:00
WorkingDirectory=%h/www
2016-12-29 11:25:39 +01:00
UMask=0027
2017-07-04 18:15:31 +02:00
PIDFile=%h/ruby.pid
ExecStartPre=/bin/mkdir -m 0750 %h/run
ExecStart=/usr/local/bin/puma --bind unix://%h/run/puma.sock?umask=0007 --pidfile %h/run/puma.pid --dir %h/www --config /etc/puma/%u.rb
2016-12-29 11:25:39 +01:00
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=process
2017-07-04 18:15:31 +02:00
#Restart=on-failure
2016-12-29 11:25:39 +01:00
[Install]
WantedBy=multi-user.target
2017-07-04 18:15:31 +02:00
Alias=puma.service
2016-12-29 11:25:39 +01:00
EOF
~~~
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
Correction des droits du service SystemD
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
~~~
2017-07-04 18:45:23 +02:00
chmod 644 /etc/systemd/user/puma.service
2016-12-29 11:25:39 +01:00
~~~
2017-07-04 18:45:23 +02:00
## Configuration
2016-12-29 11:25:39 +01:00
2017-07-04 18:15:31 +02:00
Création du fichier de configuration de Puma pour l'utilisateur $USER :
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
~~~
2017-07-04 18:15:31 +02:00
cat > /etc/puma/$USER.rb <<EOF
2016-12-29 11:25:39 +01:00
environment 'production'
workers 2
2017-07-04 18:15:31 +02:00
threads 0, 4
tag 'Puma $USER'
2016-12-29 11:25:39 +01:00
EOF
~~~
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
Correction des droits du fichier de configuration
2017-01-14 00:06:38 +01:00
2016-12-29 11:25:39 +01:00
~~~
2017-07-04 18:45:23 +02:00
chmod 640 /etc/puma/$USER.rb
2017-07-04 18:15:31 +02:00
chown $USER: /etc/puma/$USER.rb
2017-07-04 18:45:23 +02:00
~~~
2017-07-04 18:49:18 +02:00
## Reverse proxy
Nous avons fait écouter Puma sur un socket Unix, maintenant il faut mettre en place un reverse proxy [Nginx](HowtoNginx) ou [Apache](HowtoApache#mod_proxy_http) vers :
~~~
unix:/home/$USER/run/puma.sock
~~~
2017-07-04 18:45:58 +02:00
## Gestion du service puma
2017-07-04 18:45:23 +02:00
**A lancer en mode utilisateur !**
Démarrer/éteindre l'application :
~~~
systemctl --user start/stop puma
~~~
Recharger la configuration après avoir modifier /etc/puma/$USER.rb (pas de coupure) :
~~~
systemctl --user reload puma
~~~
Redémarrer l'application :
~~~
systemctl --user restart puma
~~~
Activer/désactiver l'application au démarrage :
~~~
systemctl --user enable/disable puma
2016-12-29 11:25:39 +01:00
~~~