blob: 2e8eb9e40a3f6105e7c6c18fa7d1b6845d3bce4a [file] [log] [blame]
Patrick Williamsd849ec72016-08-17 14:59:38 -05001#!/bin/sh
2#
3# /etc/rc.d/init.d/docker
4#
5# Daemon for docker.com
6#
7# chkconfig: 2345 95 95
8# description: Daemon for docker.com
9
10### BEGIN INIT INFO
11# Provides: docker
12# Required-Start: $network cgconfig
13# Required-Stop:
14# Should-Start:
15# Should-Stop:
16# Default-Start: 2 3 4 5
17# Default-Stop: 0 1 6
18# Short-Description: start and stop docker
19# Description: Daemon for docker.com
20### END INIT INFO
21
22# Source function library.
23. /etc/init.d/functions
24
25prog="docker"
26unshare=/usr/bin/unshare
27exec="/usr/bin/$prog"
28pidfile="/var/run/$prog.pid"
29lockfile="/var/lock/subsys/$prog"
30logfile="/var/log/$prog"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031other_args="--registry-mirror=http://localhost:5000 --insecure-registry=http://localhost:5000 --raw-logs"
Patrick Williamsd849ec72016-08-17 14:59:38 -050032
33[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
34
35start() {
36 [ -x $exec ] || exit 5
37
38 check_for_cleanup
39
40 if ! [ -f $pidfile ]; then
41 printf "Starting $prog:\t"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 echo -e "\n$(date)\n" >> $logfile
43 "$unshare" -m -- $exec daemon $other_args &>> $logfile &
Patrick Williamsd849ec72016-08-17 14:59:38 -050044 pid=$!
45 touch $lockfile
46 # wait up to 10 seconds for the pidfile to exist. see
47 # https://github.com/docker/docker/issues/5359
48 tries=0
49 while [ ! -f $pidfile -a $tries -lt 10 ]; do
50 sleep 1
51 tries=$((tries + 1))
52 done
53 success
54 echo
55 else
56 failure
57 echo
58 printf "$pidfile still exists...\n"
59 exit 7
60 fi
61}
62
63stop() {
64 echo -n $"Stopping $prog: "
65 killproc $prog
66 retval=$?
67 echo
68 [ $retval -eq 0 ] && rm -f $lockfile
69 return $retval
70}
71
72restart() {
73 stop
74 start
75}
76
77reload() {
78 restart
79}
80
81force_reload() {
82 restart
83}
84
85rh_status() {
86 status -p $pidfile $prog
87}
88
89rh_status_q() {
90 rh_status >/dev/null 2>&1
91}
92
93
94check_for_cleanup() {
95 if [ -f ${pidfile} ]; then
96 /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
97 fi
98}
99
100case "$1" in
101 start)
102 $1
103 ;;
104 stop)
105 $1
106 ;;
107 restart)
108 $1
109 ;;
110 reload)
111 $1
112 ;;
113 force-reload)
114 force_reload
115 ;;
116 status)
117 status
118 ;;
119 condrestart|try-restart)
120 restart
121 ;;
122 *)
123 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
124 exit 2
125esac
126
127exit $?