Skip to content

Commit a21de8b

Browse files
jhassdenschub
authored andcommitted
Make listen directive for Unicorn configurable
1 parent a396a24 commit a21de8b

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

config/defaults.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ defaults:
3232
host:
3333
pubsub_server: 'https://pubsubhubbub.appspot.com/'
3434
server:
35-
port: 3000
35+
port:
36+
listen: '0.0.0.0:3000'
3637
rails_environment: 'development'
3738
stderr_log:
3839
stdout_log:

config/diaspora.yml.example

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ configuration: ## Section
140140

141141
## Settings affecting how ./script/server behaves.
142142
server: ## Section
143+
## Where the appserver should listen to (default=0.0.0.0:3000)
144+
#listen: '127.0.0.1:3000'
145+
#listen: 'unix:tmp/diaspora.sock'
146+
#listen: 'unix:/run/diaspora/diaspora.sock'
143147

144-
## The port on which the appserver should listen (default=3000).
148+
## The port on which the appserver should listen (default=none).
149+
## Note: this setting is deprecated, use listen instead.
145150
#port: 3000
146151

147152
## Rails environment (default='development').
@@ -407,14 +412,14 @@ configuration: ## Section
407412
## **or** an encrypted key for an unhosted button.
408413
paypal_donations: ## Section
409414
#enable: false
410-
415+
411416
## Currency used (USD, EUR...)
412417
#currency: USD
413-
418+
414419
## hosted Paypal button id
415420
#paypal_hosted_button_id: "change_me"
416421
## OR encrypted key of unhosted button
417-
#paypal_unhosted_button_encrypted: "-----BEGIN PKCS7-----"
422+
#paypal_unhosted_button_encrypted: "-----BEGIN PKCS7-----"
418423

419424
## Bitcoin donations
420425
## You can provide a bitcoin address here to allow your users to provide

config/unicorn.rb

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,32 @@
1-
require File.expand_path('../load_config', __FILE__)
1+
require_relative "load_config"
22

3-
# Enable and set these to run the worker as a different user/group
4-
#user = 'diaspora'
5-
#group = 'diaspora'
3+
port = ENV["PORT"]
4+
port = port && !port.empty? ? port.to_i : nil
65

6+
listen port || AppConfig.server.listen.get unless RACKUP[:set_listener]
77
worker_processes AppConfig.server.unicorn_worker.to_i
8-
9-
## Load the app before spawning workers
10-
preload_app true
11-
12-
# How long to wait before killing an unresponsive worker
138
timeout AppConfig.server.unicorn_timeout.to_i
14-
15-
@sidekiq_pid = nil
16-
17-
#pid '/var/run/diaspora/diaspora.pid'
18-
#listen '/var/run/diaspora/diaspora.sock', :backlog => 2048
19-
20-
219
stderr_path AppConfig.server.stderr_log.get if AppConfig.server.stderr_log?
2210
stdout_path AppConfig.server.stdout_log.get if AppConfig.server.stdout_log?
2311

24-
before_fork do |server, worker|
25-
# If using preload_app, enable this line
26-
ActiveRecord::Base.connection.disconnect!
12+
preload_app true
13+
@sidekiq_pid = nil
14+
15+
before_fork do |_server, _worker|
16+
ActiveRecord::Base.connection.disconnect! # preloading app in master, so reconnect to DB
2717

2818
# disconnect redis if in use
2919
unless AppConfig.environment.single_process_mode?
3020
Sidekiq.redis {|redis| redis.client.disconnect }
3121
end
3222

3323
if AppConfig.server.embed_sidekiq_worker?
34-
@sidekiq_pid ||= spawn('bin/bundle exec sidekiq')
35-
end
36-
37-
old_pid = '/var/run/diaspora/diaspora.pid.oldbin'
38-
if File.exists?(old_pid) && server.pid != old_pid
39-
begin
40-
Process.kill("QUIT", File.read(old_pid).to_i)
41-
rescue Errno::ENOENT, Errno::ESRCH
42-
# someone else did our job for us
43-
end
24+
@sidekiq_pid ||= spawn("bin/bundle exec sidekiq")
4425
end
4526
end
4627

47-
48-
after_fork do |server, worker|
49-
# If using preload_app, enable this line
50-
ActiveRecord::Base.establish_connection
28+
after_fork do |_server, _worker|
29+
ActiveRecord::Base.establish_connection # preloading app in master, so reconnect to DB
5130

5231
# We don't generate uuids in the frontend, but let's be on the safe side
5332
UUID.generator.next_sequence

script/server

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,28 @@ then
119119
export DB
120120
fi
121121

122+
if [ -z "$PORT" -a -n "$port" ]
123+
then
124+
warning "Setting port via configuration is deprecated, set listen instead. See the updated config/diaspora.yml.example."
125+
PORT="$port"
126+
fi
127+
122128
args="$@"
123129
for arg in $(echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
124130
do
125-
[ "$prev_arg" = '-p' ] && port="$arg"
131+
[ "$prev_arg" = '-p' ] && PORT="$arg"
126132
prev_arg="$arg"
127133
done
128134

129-
services=$(chk_service $port )
130-
if [ -n "$services" ]
135+
if [ -n "$PORT" ]
131136
then
132-
fatal "Port $port is already in use.\n\t$services"
137+
export PORT
138+
139+
services=$(chk_service $PORT)
140+
if [ -n "$services" ]
141+
then
142+
fatal "Port $port is already in use.\n\t$services"
143+
fi
133144
fi
134145

135146
# Force AGPL
@@ -186,11 +197,15 @@ think about editing your proxy configuration as described in:
186197
diaspora.yml.example
187198
*****************************************************************
188199
"
189-
fi
190200
fi
191201

192202
# Start Diaspora
193-
printf "Starting Diaspora in $RAILS_ENV mode on port $port "
203+
printf "Starting Diaspora in $RAILS_ENV mode "
204+
if [ -n "$PORT" ]
205+
then
206+
printf "on port $PORT "
207+
port_option="-p $PORT"
208+
fi
194209
if [ "$embed_sidekiq_worker" = "true" ]
195210
then
196211
echo "with a Sidekiq worker embedded into Unicorn."
@@ -204,4 +219,4 @@ else
204219
fi
205220
echo ""
206221

207-
exec bin/bundle exec foreman start -m "xmpp=$vines,web=1,sidekiq=$workers" -p $port
222+
exec bin/bundle exec foreman start -m "xmpp=$vines,web=1,sidekiq=$workers" $port_option

0 commit comments

Comments
 (0)