Patrick Williams | d849ec7 | 2016-08-17 14:59:38 -0500 | [diff] [blame] | 1 | #!/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 | |
| 25 | prog="docker" |
| 26 | unshare=/usr/bin/unshare |
| 27 | exec="/usr/bin/$prog" |
| 28 | pidfile="/var/run/$prog.pid" |
| 29 | lockfile="/var/lock/subsys/$prog" |
| 30 | logfile="/var/log/$prog" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | other_args="--registry-mirror=http://localhost:5000 --insecure-registry=http://localhost:5000 --raw-logs" |
Patrick Williams | d849ec7 | 2016-08-17 14:59:38 -0500 | [diff] [blame] | 32 | |
| 33 | [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog |
| 34 | |
| 35 | start() { |
| 36 | [ -x $exec ] || exit 5 |
| 37 | |
| 38 | check_for_cleanup |
| 39 | |
| 40 | if ! [ -f $pidfile ]; then |
| 41 | printf "Starting $prog:\t" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | echo -e "\n$(date)\n" >> $logfile |
| 43 | "$unshare" -m -- $exec daemon $other_args &>> $logfile & |
Patrick Williams | d849ec7 | 2016-08-17 14:59:38 -0500 | [diff] [blame] | 44 | 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 | |
| 63 | stop() { |
| 64 | echo -n $"Stopping $prog: " |
| 65 | killproc $prog |
| 66 | retval=$? |
| 67 | echo |
| 68 | [ $retval -eq 0 ] && rm -f $lockfile |
| 69 | return $retval |
| 70 | } |
| 71 | |
| 72 | restart() { |
| 73 | stop |
| 74 | start |
| 75 | } |
| 76 | |
| 77 | reload() { |
| 78 | restart |
| 79 | } |
| 80 | |
| 81 | force_reload() { |
| 82 | restart |
| 83 | } |
| 84 | |
| 85 | rh_status() { |
| 86 | status -p $pidfile $prog |
| 87 | } |
| 88 | |
| 89 | rh_status_q() { |
| 90 | rh_status >/dev/null 2>&1 |
| 91 | } |
| 92 | |
| 93 | |
| 94 | check_for_cleanup() { |
| 95 | if [ -f ${pidfile} ]; then |
| 96 | /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile} |
| 97 | fi |
| 98 | } |
| 99 | |
| 100 | case "$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 |
| 125 | esac |
| 126 | |
| 127 | exit $? |