#!/bin/sh
#
# /etc/rc.d/docker: start/stop docker daemon
#
. /etc/rc.subr

NAME="Docker daemon"
PROG=/usr/bin/dockerd
PID=/run/docker/pid
CONF=/etc/docker.conf
LOG=/var/log/docker.log
CGROUPFS=/usr/bin/cgroupfs-mount
SOCKET=/run/docker.sock

if [ -f $CONF ]; then
    . $CONF
else
    if [ -z $OPTS ]; then
	OPTS="-p $PID -g docker"
    fi
fi

case $1 in
  start)
    if [ ! -f $LOG ]; then
        touch $LOG
        chgrp docker $LOG
        chmod 640 $LOG
    fi
    
    $CGROUPFS
    msg "Starting $NAME..."
    start_daemon -p $PID $PROG $OPTS >> $LOG 2>&1 &
    ;;
  stop)
    msg "Stoping $NAME..."
    stop_daemon -p $PID $PROG
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  status)
    status_daemon $PROG &
    case $? in
      0) echo "$PROG is running with pid $(cat $PIDFILE)" ;;
      1) echo "$PROG is not running but the pid file $PIDFILE exists" ;;
      3) echo "$PROG is not running" ;;
      4) echo "Unable to determine the program status" ;;
    esac
    ;;
  *)
    echo "usage: $0 [start|stop|restart|status]"
    ;;
esac

# End of file
