Skip to content

Commit ad6a322

Browse files
authored
Merge branch 'master' into schneems/puma-stats
2 parents 1e69dac + 9eb3136 commit ad6a322

File tree

6 files changed

+160
-1
lines changed

6 files changed

+160
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ branches:
1111
only:
1212
- "master"
1313
rvm:
14-
- 2.2.9
14+
- 2.2.8
1515
- 2.3.6
1616
- 2.4.3
1717
- 2.5.0

docs/systemd.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ for additional configuration details.
102102
Note that the above configurations will work with Puma in either
103103
single process or cluster mode.
104104

105+
### Sockets and symlinks
106+
107+
When using releases folders, you should set the socket path using the
108+
shared folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the
109+
release folder path (`/srv/projet/releases/1234/tmp/puma.sock`).
110+
111+
Puma will detect the release path socket as different than the one provided by
112+
systemd and attempt to bind it again, resulting in the exception
113+
`There is already a server bound to:`.
114+
105115
## Usage
106116

107117
Without socket activation, use `systemctl` as root (e.g. via `sudo`) as

tools/jungle/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ See `/tools/jungle/upstart` for Ubuntu's upstart scripts.
1111
## Systemd
1212

1313
See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md).
14+
15+
## rc.d
16+
17+
See `/tools/jungle/rc.d` for FreeBSD's rc.d scripts

tools/jungle/rc.d/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Puma as a service using rc.d
2+
3+
Manage multilpe Puma servers as services on one box using FreeBSD's rc.d service.
4+
5+
## Dependencies
6+
7+
* `jq` - a command-line json parser is needed to parse the json in the config file
8+
9+
## Installation
10+
11+
# Copy the puma script to the rc.d directory (make sure everyone has read/execute perms)
12+
sudo cp puma /usr/local/etc/rc.d/
13+
14+
# Create an empty configuration file
15+
sudo touch /usr/local/etc/puma.conf
16+
17+
# Enable the puma service
18+
sudo echo 'puma_enable="YES"' >> /etc/rc.conf
19+
20+
## Managing the jungle
21+
22+
Puma apps are referenced in /usr/local/etc/puma.conf by default.
23+
24+
Start the jungle running:
25+
26+
`service puma start`
27+
28+
This script will run at boot time.
29+
30+
31+
You can also stop the jungle (stops ALL puma instances) by running:
32+
33+
`service puma stop`
34+
35+
36+
To restart the jungle:
37+
38+
`service puma restart`
39+
40+
## Conventions
41+
42+
* The script expects:
43+
* a config file to exist under `config/puma.rb` in your app. E.g.: `/home/apps/my-app/config/puma.rb`.
44+
45+
You can always change those defaults by editing the scripts.
46+
47+
## Here's what a minimal app's config file should have
48+
49+
```
50+
{
51+
"servers" : [
52+
{
53+
"dir": "/path/to/rails/project",
54+
"user": "deploy-user",
55+
"ruby_version": "ruby.version",
56+
"ruby_env": "rbenv"
57+
}
58+
]
59+
}
60+
```
61+
62+
## Before starting...
63+
64+
You need to customise `puma.conf` to:
65+
66+
* Set the right user your app should be running on unless you want root to execute it!
67+
* Set the directory of the app
68+
* Set the ruby version to execute
69+
* Set the ruby environment (currently set to rbenv, since that is the only ruby environment currently supported)
70+
* Add additional server instances following the scheme in the example
71+
72+
## Notes:
73+
74+
Only rbenv is currently supported.

tools/jungle/rc.d/puma

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
#
3+
4+
# PROVIDE: puma
5+
6+
. /etc/rc.subr
7+
8+
name="puma"
9+
start_cmd="puma_start"
10+
stop_cmd="puma_stop"
11+
restart_cmd="puma_restart"
12+
rcvar=puma_enable
13+
required_files=/usr/local/etc/puma.conf
14+
15+
puma_start()
16+
{
17+
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
18+
i=0
19+
while [ "$i" -lt "$server_count" ]; do
20+
rb_env=$(/usr/local/bin/jq -r ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
21+
dir=$(/usr/local/bin/jq -r ".servers[$i].dir" /usr/local/etc/puma.conf)
22+
user=$(/usr/local/bin/jq -r ".servers[$i].user" /usr/local/etc/puma.conf)
23+
rb_ver=$(/usr/local/bin/jq -r ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
24+
case $rb_env in
25+
"rbenv")
26+
su - $user -c "cd $dir && rbenv shell $rb_ver && bundle exec puma -C $dir/config/puma.rb -d"
27+
;;
28+
*)
29+
;;
30+
esac
31+
i=$(( i + 1 ))
32+
done
33+
}
34+
35+
puma_stop()
36+
{
37+
pkill ruby
38+
}
39+
40+
puma_restart()
41+
{
42+
server_count=$(/usr/local/bin/jq ".servers[] .ruby_env" /usr/local/etc/puma.conf | wc -l)
43+
i=0
44+
while [ "$i" -lt "$server_count" ]; do
45+
rb_env=$(/usr/local/bin/jq -r ".servers[$i].ruby_env" /usr/local/etc/puma.conf)
46+
dir=$(/usr/local/bin/jq -r ".servers[$i].dir" /usr/local/etc/puma.conf)
47+
user=$(/usr/local/bin/jq -r ".servers[$i].user" /usr/local/etc/puma.conf)
48+
rb_ver=$(/usr/local/bin/jq -r ".servers[$i].ruby_version" /usr/local/etc/puma.conf)
49+
case $rb_env in
50+
"rbenv")
51+
su - $user -c "cd $dir && pkill ruby && rbenv shell $ruby_version && bundle exec puma -C $dir/config/puma.rb -d"
52+
;;
53+
*)
54+
;;
55+
esac
56+
i=$(( i + 1 ))
57+
done
58+
}
59+
60+
load_rc_config $name
61+
run_rc_command "$1"

tools/jungle/rc.d/puma.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"servers" : [
3+
{
4+
"dir": "/path/to/rails/project",
5+
"user": "deploy-user",
6+
"ruby_version": "ruby.version",
7+
"ruby_env": "rbenv"
8+
}
9+
]
10+
}

0 commit comments

Comments
 (0)