Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 4963f28

Browse files
author
Mangled Deutz
committed
Fix #368
Various gunicorn launch stances are now more uniform. Normalized the use of environment variables to bind the host and port. Synching contrib scripts that fall out of synch earlier. Docker-DCO-1.1-Signed-off-by: Mangled Deutz <[email protected]> (github: dmp42)
1 parent e82092a commit 4963f28

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

contrib/docker-registry.conf

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ env REGISTRY_DIR=/srv/docker/registry
99
env USER=www-data
1010
env GROUP=www-data
1111
env LOG_FILE=/var/log/docker/registry.log
12-
env NUM_WORKERS=9
12+
env GUNICORN_WORKERS=9
1313

14-
env ADDRESS=127.0.0.1:5000
14+
env REGISTRY_PORT=5000
15+
env REGISTRY_HOST=127.0.0.1
1516

1617

1718
pre-start script
@@ -27,5 +28,5 @@ script
2728

2829
[ -r $REGISTRY_DIR/.venv/bin/activate ] && . $REGISTRY_DIR/.venv/bin/activate
2930
cd $REGISTRY_DIR
30-
exec gunicorn -w $NUM_WORKERS --bind=$ADDRESS --user=$USER --group=$GROUP --log-level=$LOG_LEVEL --log-file=$LOG_FILE 2>>$LOG_FILE wsgi:application
31+
exec gunicorn -w $GUNICORN_WORKERS --bind=$REGISTRY_HOST:$REGISTRY_PORT --user=$USER --group=$GROUP --log-level=$LOG_LEVEL --log-file=$LOG_FILE 2>>$LOG_FILE docker_registry.wsgi:application
3132
end script

contrib/docker-registry_RHEL.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ self_dir="${self_path%%/${self_path##*/}}"
4343

4444
NAME="Docker Registry"
4545
DAEMON="/usr/bin/gunicorn"
46-
DAEMON_OPTS="-D --error-logfile ${ERROR_LOGFILE} --access-logfile ${ACCESS_LOGFILE} --log-file ${LOGFILE} --pid ${PIDFILE} --max-requests 500 --graceful-timeout 3600 -t 3600 -k gevent -b ${LISTEN_IP}:${LISTEN_PORT} -w ${GUNICORN_WORKERS:-2} wsgi:application"
46+
DAEMON_OPTS="-D --error-logfile ${ERROR_LOGFILE} --access-logfile ${ACCESS_LOGFILE} --log-file ${LOGFILE} --pid ${PIDFILE} --max-requests 500 --graceful-timeout 3600 -t 3600 -k gevent -b ${LISTEN_IP}:${LISTEN_PORT} -w ${GUNICORN_WORKERS:-2} docker_registry.wsgi:application"
4747

4848
RED='\e[0;31m'
4949
GREEN='\e[0;32m'

contrib/docker-registry_debian.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Required-Start: $network $remote_fs $syslog
66
# Required-Stop: $network $remote_fs $syslog
77
# Default-Start: 2 3 4 5
8-
# Default-Stop: 0 1 6
8+
# Default-Stop: 0 1 6
99
# Short-Description: Start Docker-Registry
1010
### END INIT INFO
1111

@@ -33,15 +33,15 @@ self_dir="${self_path%%/${self_path##*/}}"
3333
# set defaults if they are not set by config
3434
[[ -z "$RUNAS" ]] && RUNAS=$(stat --format "%U" $self_path) # defaults to user owning this init script
3535
[[ -z "$LOGFILE" ]] && LOGFILE=/var/log/docker-registry.log # will be chowned to $RUNAS
36-
[[ -z "$PIDFILE" ]] && PIDFILE=/var/run/docker-registry/docker-registry.pid # path will created and chowned to $RUNAS
36+
[[ -z "$PIDFILE" ]] && PIDFILE=/var/run/docker-registry/docker-registry.pid # path will created and chowned to $RUNAS
3737
[[ -z "$LISTEN_IP" ]] && LISTEN_IP="0.0.0.0"
3838
[[ -z "$LISTEN_PORT" ]] && LISTEN_PORT=5000
3939
[[ -z "$GUNICORN_WORKERS" ]] && GUNICORN_WORKERS=2
4040
[[ -z "$DOCKER_REGISTRY_HOME" ]] && DOCKER_REGISTRY_HOME=${self_dir%/*}
4141

4242
NAME="Docker Registry"
4343
DAEMON="/usr/local/bin/gunicorn"
44-
DAEMON_OPTS="-D --access-logfile ${LOGFILE} --pid ${PIDFILE} --max-requests 500 --graceful-timeout 3600 -t 3600 -k gevent -b ${LISTEN_IP}:${LISTEN_PORT} -w ${GUNICORN_WORKERS:-2} wsgi:application"
44+
DAEMON_OPTS="-D --access-logfile ${LOGFILE} --pid ${PIDFILE} --max-requests 500 --graceful-timeout 3600 -t 3600 -k gevent -b ${LISTEN_IP}:${LISTEN_PORT} -w ${GUNICORN_WORKERS:-2} docker_registry.wsgi:application"
4545

4646
RED='\e[0;31m'
4747
GREEN='\e[0;32m'

docker_registry/run.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .tags import * # noqa
1717
from .images import * # noqa
1818
from .lib import config
19+
from .server import env
1920
from .status import * # noqa
2021
from .search import * # noqa
2122

@@ -47,12 +48,13 @@ def run_gunicorn():
4748
formatter_class=RawTextHelpFormatter)
4849
parser.parse_args()
4950

50-
workers = os.environ.get('GUNICORN_WORKERS', '4')
51-
port = os.environ.get('REGISTRY_PORT', '5000')
52-
graceful_timeout = os.environ.get('GUNICORN_GRACEFUL_TIMEOUT', '3600')
53-
silent_timeout = os.environ.get('GUNICORN_SILENT_TIMEOUT', '3600')
51+
workers = env.source('GUNICORN_WORKERS')
52+
host = env.source('REGISTRY_HOST')
53+
port = env.source('REGISTRY_PORT')
54+
graceful_timeout = env.source('GUNICORN_GRACEFUL_TIMEOUT')
55+
silent_timeout = env.source('GUNICORN_SILENT_TIMEOUT')
5456

55-
address = '0.0.0.0:{0}'.format(port)
57+
address = '%s:%s' % (host, port)
5658

5759
gunicorn_path = distutils.spawn.find_executable('gunicorn')
5860
if gunicorn_path is None:

docker_registry/server/env.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
5+
__all__ = ['source']
6+
7+
defined = {
8+
'REGISTRY_PORT': 5000,
9+
'REGISTRY_HOST': '0.0.0.0',
10+
'SETTINGS_FLAVOR': 'dev',
11+
'GUNICORN_WORKERS': 4,
12+
'GUNICORN_GRACEFUL_TIMEOUT': 3600,
13+
'GUNICORN_SILENT_TIMEOUT': 3600
14+
}
15+
16+
17+
def source(key, override=None):
18+
return os.environ.get(key, defined[key] if key in defined else override)

docker_registry/wsgi.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
# -*- coding: utf-8 -*-
33

44
import logging
5-
import os
65

76
from .run import app
7+
from .server import env
88

99

1010
if __name__ == '__main__':
1111
# Bind to PORT if defined, otherwise default to 5000.
12-
port = int(os.environ.get('PORT_WWW', 5000))
12+
host = env.source('REGISTRY_HOST')
13+
port = int(env.source('REGISTRY_PORT'))
1314
app.debug = True
14-
app.run(host='0.0.0.0', port=port)
15+
app.run(host=host, port=port)
1516
# Or you can run:
1617
# gunicorn --access-logfile - --log-level debug --debug -b 0.0.0.0:5000 \
1718
# -w 1 wsgi:application

0 commit comments

Comments
 (0)