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" |
| 31 | |
| 32 | [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog |
| 33 | |
| 34 | start() { |
| 35 | [ -x $exec ] || exit 5 |
| 36 | |
| 37 | check_for_cleanup |
| 38 | |
| 39 | if ! [ -f $pidfile ]; then |
| 40 | printf "Starting $prog:\t" |
| 41 | echo "\n$(date)\n" >> $logfile |
| 42 | "$unshare" -m -- $exec -d $other_args &>> $logfile & |
| 43 | pid=$! |
| 44 | touch $lockfile |
| 45 | # wait up to 10 seconds for the pidfile to exist. see |
| 46 | # https://github.com/docker/docker/issues/5359 |
| 47 | tries=0 |
| 48 | while [ ! -f $pidfile -a $tries -lt 10 ]; do |
| 49 | sleep 1 |
| 50 | tries=$((tries + 1)) |
| 51 | done |
| 52 | success |
| 53 | echo |
| 54 | else |
| 55 | failure |
| 56 | echo |
| 57 | printf "$pidfile still exists...\n" |
| 58 | exit 7 |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | stop() { |
| 63 | echo -n $"Stopping $prog: " |
| 64 | killproc $prog |
| 65 | retval=$? |
| 66 | echo |
| 67 | [ $retval -eq 0 ] && rm -f $lockfile |
| 68 | return $retval |
| 69 | } |
| 70 | |
| 71 | restart() { |
| 72 | stop |
| 73 | start |
| 74 | } |
| 75 | |
| 76 | reload() { |
| 77 | restart |
| 78 | } |
| 79 | |
| 80 | force_reload() { |
| 81 | restart |
| 82 | } |
| 83 | |
| 84 | rh_status() { |
| 85 | status -p $pidfile $prog |
| 86 | } |
| 87 | |
| 88 | rh_status_q() { |
| 89 | rh_status >/dev/null 2>&1 |
| 90 | } |
| 91 | |
| 92 | |
| 93 | check_for_cleanup() { |
| 94 | if [ -f ${pidfile} ]; then |
| 95 | /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile} |
| 96 | fi |
| 97 | } |
| 98 | |
| 99 | case "$1" in |
| 100 | start) |
| 101 | $1 |
| 102 | ;; |
| 103 | stop) |
| 104 | $1 |
| 105 | ;; |
| 106 | restart) |
| 107 | $1 |
| 108 | ;; |
| 109 | reload) |
| 110 | $1 |
| 111 | ;; |
| 112 | force-reload) |
| 113 | force_reload |
| 114 | ;; |
| 115 | status) |
| 116 | status |
| 117 | ;; |
| 118 | condrestart|try-restart) |
| 119 | restart |
| 120 | ;; |
| 121 | *) |
| 122 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" |
| 123 | exit 2 |
| 124 | esac |
| 125 | |
| 126 | exit $? |