mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Freebsd rc.d jungle for puma (#1529)
This commit is contained in:
parent
7e932d0c50
commit
34a3790bc7
4 changed files with 149 additions and 0 deletions
|
@ -11,3 +11,7 @@ See `/tools/jungle/upstart` for Ubuntu's upstart scripts.
|
|||
## Systemd
|
||||
|
||||
See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md).
|
||||
|
||||
## rc.d
|
||||
|
||||
See `/tools/jungle/rc.d` for FreeBSD's rc.d scripts
|
||||
|
|
74
tools/jungle/rc.d/README.md
Normal file
74
tools/jungle/rc.d/README.md
Normal file
|
@ -0,0 +1,74 @@
|
|||
# Puma as a service using rc.d
|
||||
|
||||
Manage multilpe Puma servers as services on one box using FreeBSD's rc.d service.
|
||||
|
||||
## Dependencies
|
||||
|
||||
* `jq` - a command-line json parser is needed to parse the json in the config file
|
||||
|
||||
## Installation
|
||||
|
||||
# Copy the puma script to the rc.d directory (make sure everyone has read/execute perms)
|
||||
sudo cp puma /usr/local/etc/rc.d/
|
||||
|
||||
# Create an empty configuration file
|
||||
sudo touch /usr/local/etc/puma.conf
|
||||
|
||||
# Enable the puma service
|
||||
sudo echo 'puma_enable="YES"' >> /etc/rc.conf
|
||||
|
||||
## Managing the jungle
|
||||
|
||||
Puma apps are referenced in /usr/local/etc/puma.conf by default.
|
||||
|
||||
Start the jungle running:
|
||||
|
||||
`service puma start`
|
||||
|
||||
This script will run at boot time.
|
||||
|
||||
|
||||
You can also stop the jungle (stops ALL puma instances) by running:
|
||||
|
||||
`service puma stop`
|
||||
|
||||
|
||||
To restart the jungle:
|
||||
|
||||
`service puma restart`
|
||||
|
||||
## 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`.
|
||||
|
||||
You can always change those defaults by editing the scripts.
|
||||
|
||||
## Here's what a minimal app's config file should have
|
||||
|
||||
```
|
||||
{
|
||||
"servers" : [
|
||||
{
|
||||
"dir": "/path/to/rails/project",
|
||||
"user": "deploy-user",
|
||||
"ruby_version": "ruby.version",
|
||||
"ruby_env": "rbenv"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 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!
|
||||
* Set the directory of the app
|
||||
* Set the ruby version to execute
|
||||
* Set the ruby environment (currently set to rbenv, since that is the only ruby environment currently supported)
|
||||
* Add additional server instances following the scheme in the example
|
||||
|
||||
## Notes:
|
||||
|
||||
Only rbenv is currently supported.
|
61
tools/jungle/rc.d/puma
Executable file
61
tools/jungle/rc.d/puma
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
|
||||
# PROVIDE: puma
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
name="puma"
|
||||
start_cmd="puma_start"
|
||||
stop_cmd="puma_stop"
|
||||
restart_cmd="puma_restart"
|
||||
rcvar=puma_enable
|
||||
required_files=/usr/local/etc/puma.conf
|
||||
|
||||
puma_start()
|
||||
{
|
||||
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
|
||||
i=0
|
||||
while [ "$i" -lt "$server_count" ]; do
|
||||
rb_env=$(/usr/local/bin/jq -r ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
|
||||
dir=$(/usr/local/bin/jq -r ".servers[$i].dir" /usr/local/etc/puma.conf)
|
||||
user=$(/usr/local/bin/jq -r ".servers[$i].user" /usr/local/etc/puma.conf)
|
||||
rb_ver=$(/usr/local/bin/jq -r ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
|
||||
case $rb_env in
|
||||
"rbenv")
|
||||
su - $user -c "cd $dir && rbenv shell $rb_ver && bundle exec puma -C $dir/config/puma.rb -d"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
puma_stop()
|
||||
{
|
||||
pkill ruby
|
||||
}
|
||||
|
||||
puma_restart()
|
||||
{
|
||||
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
|
||||
i=0
|
||||
while [ "$i" -lt "$server_count" ]; do
|
||||
rb_env=$(/usr/local/bin/jq -r ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
|
||||
dir=$(/usr/local/bin/jq -r ".servers[$i].dir" /usr/local/etc/puma.conf)
|
||||
user=$(/usr/local/bin/jq -r ".servers[$i].user" /usr/local/etc/puma.conf)
|
||||
rb_ver=$(/usr/local/bin/jq -r ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
|
||||
case $rb_env in
|
||||
"rbenv")
|
||||
su - $user -c "cd $dir && pkill ruby && rbenv shell $ruby_version && bundle exec puma -C $dir/config/puma.rb -d"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
load_rc_config $name
|
||||
run_rc_command "$1"
|
10
tools/jungle/rc.d/puma.conf
Normal file
10
tools/jungle/rc.d/puma.conf
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"servers" : [
|
||||
{
|
||||
"dir": "/path/to/rails/project",
|
||||
"user": "deploy-user",
|
||||
"ruby_version": "ruby.version",
|
||||
"ruby_env": "rbenv"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue