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

Commit f8723f8

Browse files
committed
Merge pull request #74 from anapsix/debian-init
Debian INIT and NGINX update
2 parents 54d3fb7 + 2d5efd9 commit f8723f8

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

contrib/docker-registry_debian.sh

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/bin/bash
2+
3+
### BEGIN INIT INFO
4+
# Provides: docker-registry
5+
# Required-Start: $network $remote_fs $syslog
6+
# Required-Stop: $network $remote_fs $syslog
7+
# Default-Start: 2 3 4 5
8+
# Default-Stop: 0 1 6
9+
# Short-Description: Start Docker-Registry
10+
### END INIT INFO
11+
12+
# Author: Anastas Semenov <anapsix@random.io>
13+
# Updated by:
14+
15+
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
16+
. /lib/lsb/init-functions
17+
18+
# check is we are running as root
19+
[ $(id -u) -ne 0 ] && echo "must run as root, exiting" && exit 1
20+
21+
# a way to figure out a service home directory, no matter where it's called from
22+
self_path="$(readlink -e $0)"
23+
self_dir="${self_path%%/${self_path##*/}}"
24+
25+
# load config if present/readable
26+
[ -r /etc/default/docker-registry ] && . /etc/default/docker-registry
27+
28+
# MAKE SURE THIS PATH IS CORRECT
29+
# it will default to repository location
30+
# which will work if you are calling directly from repo path or even symlink to it
31+
#DOCKER_REGISTRY_HOME="" # path to docker-registry codebase
32+
33+
# set defaults if they are not set by config
34+
[[ -z "$RUNAS" ]] && RUNAS=$(stat --format "%U" $self_path) # defaults to user owning this init script
35+
[[ -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
37+
[[ -z "$LISTEN_IP" ]] && LISTEN_IP="0.0.0.0"
38+
[[ -z "$LISTEN_PORT" ]] && LISTEN_PORT=5000
39+
[[ -z "$GUNICORN_WORKERS" ]] && GUNICORN_WORKERS=2
40+
[[ -z "$DOCKER_REGISTRY_HOME" ]] && DOCKER_REGISTRY_HOME=${self_dir%/*}
41+
42+
NAME="Docker Registry"
43+
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"
45+
46+
RED='\e[0;31m'
47+
GREEN='\e[0;32m'
48+
YELLOW='\e[0;33m'
49+
PURPLE='\e[0;35m'
50+
NC='\e[0m'
51+
52+
if [[ -z "${DOCKER_REGISTRY_HOME}" ]]; then
53+
echo "DOCKER_REGISTRY_HOME is not set, update this \"$(readlink -e $0)\" script or set it in /etc/default/docker-registry , exiting.."
54+
exit 1
55+
else
56+
cd $DOCKER_REGISTRY_HOME
57+
fi
58+
59+
start_server() {
60+
[ -d ${PIDFILE%/*} ] || mkdir -p ${PIDFILE%/*} || return 1
61+
chown -R $RUNAS ${PIDFILE%/*} || return 1
62+
touch $LOGFILE && chown $RUNAS $LOGFILE || return 1
63+
start-stop-daemon --start --chuid $RUNAS --chdir $DOCKER_REGISTRY_HOME --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
64+
return $?
65+
}
66+
67+
stop_server() {
68+
start-stop-daemon --stop --oknodo --user $RUNAS --name ${DAEMON##*/} --pidfile $PIDFILE --retry 5 1>/dev/null
69+
return $?
70+
# kill $(cat $PIDFILE)
71+
# RETVAL=$?
72+
# rm -f $PIDFILE
73+
# return $RETVAL
74+
}
75+
76+
reload_server() {
77+
kill -HUP $(cat $PIDFILE)
78+
}
79+
80+
status_server() {
81+
if [ ! -r $PIDFILE ]; then
82+
return 1
83+
elif ( kill -0 $(cat $PIDFILE) 2>/dev/null); then
84+
return 0
85+
else
86+
rm -f $PIDFILE
87+
return 1
88+
fi
89+
}
90+
91+
case $1 in
92+
start)
93+
if status_server; then
94+
/bin/echo -e "${NAME} is ${GREEN}already running${NC}" >&2
95+
exit 0
96+
else
97+
log_daemon_msg "Starting ${NAME}" "on port ${LISTEN_IP}:${LISTEN_PORT}"
98+
start_server
99+
sleep 1
100+
status_server
101+
log_end_msg $?
102+
fi
103+
;;
104+
stop)
105+
if status_server; then
106+
log_daemon_msg "Stopping ${NAME}" # "on port ${LISTEN_IP}:${LISTEN_PORT}"
107+
stop_server
108+
log_end_msg $?
109+
else
110+
log_daemon_msg "${NAME}" "is not running"
111+
log_end_msg 0
112+
fi
113+
;;
114+
restart)
115+
log_daemon_msg "Restarting ${NAME}" # "on port ${LISTEN_IP}:${LISTEN_PORT}"
116+
if status_server; then
117+
stop_server && sleep 1 || log_end_msg $?
118+
fi
119+
start_server
120+
log_end_msg $?
121+
;;
122+
reload)
123+
if status_server; then
124+
log_daemon_msg "Reloading ${NAME}" # "on port ${LISTEN_IP}:${LISTEN_PORT}"
125+
reload_server
126+
log_end_msg $?
127+
else
128+
log_daemon_msg "${NAME}" "is not running"
129+
log_end_msg 1
130+
fi
131+
;;
132+
status)
133+
/bin/echo -en "${NAME} is.. " >&2
134+
if status_server; then
135+
/bin/echo -e "${GREEN}running${NC}" >&2
136+
exit 0
137+
else
138+
/bin/echo -e "${RED}not running${NC}" >&2
139+
exit 1
140+
fi
141+
;;
142+
*)
143+
echo "Usage: $0 {start|stop|restart|reload|status}" >&2
144+
exit 2
145+
;;
146+
esac
147+
148+
exit 0

contrib/nginx.conf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ upstream docker-registry {
88
server {
99
listen 443;
1010
server_name my.docker.registry.com;
11-
proxy_set_header Host $http_host;
11+
1212
ssl on;
1313
ssl_certificate /etc/ssl/certs/docker-registry;
1414
ssl_certificate_key /etc/ssl/private/docker-registry;
15+
16+
proxy_set_header Host $http_host; # required for docker client's sake
17+
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
18+
19+
client_max_body_size 800M; # avoid HTTP 413 for large image uploads
20+
1521
location / {
1622
proxy_pass http://docker-registry;
1723
}
18-
}
24+
}

0 commit comments

Comments
 (0)