mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Moved init.d implementation to its own folder and added basic upstart support
This commit is contained in:
parent
2e24400246
commit
0fa28f9d1f
6 changed files with 146 additions and 0 deletions
63
tools/jungle/upstart/README.md
Normal file
63
tools/jungle/upstart/README.md
Normal file
|
@ -0,0 +1,63 @@
|
|||
# Puma as a service using Upstart
|
||||
|
||||
Manage multiple Puma servers as services on the same box using Ubuntu upstart.
|
||||
|
||||
## Installation
|
||||
|
||||
# Copy the scripts to services directory
|
||||
sudo cp puma.conf puma-manager.conf /etc/init
|
||||
|
||||
# Create an empty configuration file
|
||||
sudo touch /etc/puma.conf
|
||||
|
||||
## Managing the jungle
|
||||
|
||||
Puma apps are referenced in /etc/puma.conf by default. Add each app's path as a new line, e.g.:
|
||||
|
||||
```
|
||||
/home/apps/my-cool-ruby-app
|
||||
/home/apps/another-app/current
|
||||
```
|
||||
|
||||
Start the jungle running:
|
||||
|
||||
`sudo start puma-manager`
|
||||
|
||||
This script will run at boot time.
|
||||
|
||||
Start a single puma like this:
|
||||
|
||||
`sudo start puma app=/path/to/app`
|
||||
|
||||
## Logs
|
||||
|
||||
Everything is logged by upstart, defaulting to `/var/log/upstart`.
|
||||
|
||||
Each puma instance is named after its directory, so for an app called `/home/apps/my-app` the log file would be `/var/log/upstart/puma-_home_apps_my-app.log`.
|
||||
|
||||
* log: /path/to/app/*config/puma.log*
|
||||
|
||||
## Conventions
|
||||
|
||||
* The script expects:
|
||||
* a config file to exist under `config/puma.rb` in your app. E.g.: `/home/apps/my-app/config/puma.rb`.
|
||||
* a temporary folder to put the PID, socket and state files to exist called `tmp/puma`. E.g.: `/home/apps/my-app/tmp/puma`. Puma will take care of the files for you.
|
||||
|
||||
You can always change those defaults by editing the scripts.
|
||||
|
||||
## Here's what a minimal app's config file should have
|
||||
|
||||
```
|
||||
pidfile "/path/to/app/tmp/puma/pid"
|
||||
state_path "/path/to/app/tmp/puma/state"
|
||||
activate_control_app
|
||||
```
|
||||
|
||||
## Before starting...
|
||||
|
||||
You need to customise `puma.conf` to:
|
||||
|
||||
* Set the right user your app should be running on unless you want root to execute it!
|
||||
* Look for `setuid apps` and `setgid apps`, uncomment those lines and replace `apps` to whatever your deployment user is.
|
||||
* Replace `apps` on the paths (or set the right paths to your user's home) everywhere else.
|
||||
* Uncomment the source lines for `rbenv` or `rvm` support unless you use a system wide installation of Ruby.
|
31
tools/jungle/upstart/puma-manager.conf
Normal file
31
tools/jungle/upstart/puma-manager.conf
Normal file
|
@ -0,0 +1,31 @@
|
|||
# /etc/init/puma-manager.conf - manage a set of Pumas
|
||||
|
||||
# This example config should work with Ubuntu 12.04+. It
|
||||
# allows you to manage multiple Puma instances with
|
||||
# Upstart, Ubuntu's native service management tool.
|
||||
#
|
||||
# See puma.conf for how to manage a single Puma instance.
|
||||
#
|
||||
# Use "stop workers" to stop all Puma instances.
|
||||
# Use "start workers" to start all instances.
|
||||
# Use "restart workers" to restart all instances.
|
||||
# Crazy, right?
|
||||
#
|
||||
|
||||
description "Manages the set of puma processes"
|
||||
|
||||
# This starts upon bootup and stops on shutdown
|
||||
start on runlevel [2345]
|
||||
stop on runlevel [06]
|
||||
|
||||
# Set this to the number of Puma processes you want
|
||||
# to run on this machine
|
||||
env PUMA_CONF=/etc/puma.conf
|
||||
|
||||
pre-start script
|
||||
for i in `cat $PUMA_CONF`; do
|
||||
app=`echo $i | cut -d , -f 1`
|
||||
logger -t "puma-manager" "Starting $app"
|
||||
start puma app=$app
|
||||
done
|
||||
end script
|
52
tools/jungle/upstart/puma.conf
Normal file
52
tools/jungle/upstart/puma.conf
Normal file
|
@ -0,0 +1,52 @@
|
|||
# /etc/init/puma.conf - Puma config
|
||||
|
||||
# This example config should work with Ubuntu 12.04+. It
|
||||
# allows you to manage multiple Puma instances with
|
||||
# Upstart, Ubuntu's native service management tool.
|
||||
#
|
||||
# See workers.conf for how to manage all Puma instances at once.
|
||||
#
|
||||
# Save this config as /etc/init/puma.conf then mange puma with:
|
||||
# sudo start puma index=0
|
||||
# sudo stop puma index=0
|
||||
# sudo status puma index=0
|
||||
#
|
||||
# or use the service command:
|
||||
# sudo service puma {start,stop,restart,status}
|
||||
#
|
||||
|
||||
description "Puma Background Worker"
|
||||
|
||||
# no "start on", we don't want to automatically start
|
||||
stop on (stopping puma-manager or runlevel [06])
|
||||
|
||||
# change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
|
||||
# setuid apps
|
||||
# setgid apps
|
||||
|
||||
respawn
|
||||
respawn limit 3 30
|
||||
|
||||
instance ${app}
|
||||
|
||||
script
|
||||
# this script runs in /bin/sh by default
|
||||
# respawn as bash so we can source in rbenv/rvm
|
||||
exec /bin/bash <<EOT
|
||||
export HOME=/home/apps
|
||||
|
||||
# Pick your poison :) Or none if you're using a system wide installed Ruby.
|
||||
# rbenv
|
||||
# source /home/apps/.bash_profile
|
||||
# OR
|
||||
# source /home/apps/.profile
|
||||
#
|
||||
# rvm
|
||||
# source /home/apps/.rvm/scripts/rvm
|
||||
|
||||
logger -t puma "Starting server: $app"
|
||||
|
||||
cd $app
|
||||
exec bundle exec puma -C config/puma.rb
|
||||
EOT
|
||||
end script
|
Loading…
Add table
Add a link
Reference in a new issue