docker 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/sh
  2. set -e
  3. ### BEGIN INIT INFO
  4. # Provides: docker
  5. # Required-Start: $syslog $remote_fs
  6. # Required-Stop: $syslog $remote_fs
  7. # Should-Start: cgroupfs-mount cgroup-lite
  8. # Should-Stop: cgroupfs-mount cgroup-lite
  9. # Default-Start: 2 3 4 5
  10. # Default-Stop: 0 1 6
  11. # Short-Description: Create lightweight, portable, self-sufficient containers.
  12. # Description:
  13. # Docker is an open-source project to easily create lightweight, portable,
  14. # self-sufficient containers from any application. The same container that a
  15. # developer builds and tests on a laptop can run at scale, in production, on
  16. # VMs, bare metal, OpenStack clusters, public clouds and more.
  17. ### END INIT INFO
  18. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  19. BASE=docker
  20. # modify these in /etc/default/$BASE (/etc/default/docker)
  21. DOCKERD=/usr/bin/dockerd
  22. # This is the pid file managed by docker itself
  23. DOCKER_PIDFILE=/var/run/$BASE.pid
  24. # This is the pid file created/managed by start-stop-daemon
  25. DOCKER_SSD_PIDFILE=/var/run/$BASE-ssd.pid
  26. DOCKER_LOGFILE=/var/log/$BASE.log
  27. DOCKER_OPTS=
  28. DOCKER_DESC="Docker"
  29. # Get lsb functions
  30. . /lib/lsb/init-functions
  31. if [ -f /etc/default/$BASE ]; then
  32. . /etc/default/$BASE
  33. fi
  34. # Check docker is present
  35. if [ ! -x $DOCKERD ]; then
  36. log_failure_msg "$DOCKERD not present or not executable"
  37. exit 1
  38. fi
  39. fail_unless_root() {
  40. if [ "$(id -u)" != '0' ]; then
  41. log_failure_msg "$DOCKER_DESC must be run as root"
  42. exit 1
  43. fi
  44. }
  45. case "$1" in
  46. start)
  47. fail_unless_root
  48. touch "$DOCKER_LOGFILE"
  49. chgrp docker "$DOCKER_LOGFILE"
  50. ulimit -n 1048576
  51. # Having non-zero limits causes performance problems due to accounting overhead
  52. # in the kernel. We recommend using cgroups to do container-local accounting.
  53. if [ "$BASH" ]; then
  54. ulimit -u unlimited
  55. else
  56. ulimit -p unlimited
  57. fi
  58. log_begin_msg "Starting $DOCKER_DESC: $BASE"
  59. start-stop-daemon --start --background \
  60. --no-close \
  61. --exec "$DOCKERD" \
  62. --pidfile "$DOCKER_SSD_PIDFILE" \
  63. --make-pidfile \
  64. -- \
  65. -p "$DOCKER_PIDFILE" \
  66. $DOCKER_OPTS \
  67. >> "$DOCKER_LOGFILE" 2>&1
  68. log_end_msg $?
  69. ;;
  70. stop)
  71. fail_unless_root
  72. if [ -f "$DOCKER_SSD_PIDFILE" ]; then
  73. log_begin_msg "Stopping $DOCKER_DESC: $BASE"
  74. start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" --retry 10
  75. log_end_msg $?
  76. else
  77. log_warning_msg "Docker already stopped - file $DOCKER_SSD_PIDFILE not found."
  78. fi
  79. ;;
  80. restart)
  81. fail_unless_root
  82. docker_pid=$(cat "$DOCKER_SSD_PIDFILE" 2> /dev/null || true)
  83. [ -n "$docker_pid" ] \
  84. && ps -p $docker_pid > /dev/null 2>&1 \
  85. && $0 stop
  86. $0 start
  87. ;;
  88. force-reload)
  89. fail_unless_root
  90. $0 restart
  91. ;;
  92. status)
  93. status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKERD" "$DOCKER_DESC"
  94. ;;
  95. *)
  96. echo "Usage: service docker {start|stop|restart|status}"
  97. exit 1
  98. ;;
  99. esac