docker 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. # Only set the hard limit (soft limit should remain as the system default of 1024):
  51. ulimit -Hn 524288
  52. # Having non-zero limits causes performance problems due to accounting overhead
  53. # in the kernel. We recommend using cgroups to do container-local accounting.
  54. if [ "$BASH" ]; then
  55. ulimit -u unlimited
  56. else
  57. ulimit -p unlimited
  58. fi
  59. log_begin_msg "Starting $DOCKER_DESC: $BASE"
  60. start-stop-daemon --start --background \
  61. --no-close \
  62. --exec "$DOCKERD" \
  63. --pidfile "$DOCKER_SSD_PIDFILE" \
  64. --make-pidfile \
  65. -- \
  66. -p "$DOCKER_PIDFILE" \
  67. $DOCKER_OPTS \
  68. >> "$DOCKER_LOGFILE" 2>&1
  69. log_end_msg $?
  70. ;;
  71. stop)
  72. fail_unless_root
  73. if [ -f "$DOCKER_SSD_PIDFILE" ]; then
  74. log_begin_msg "Stopping $DOCKER_DESC: $BASE"
  75. start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" --retry 10
  76. log_end_msg $?
  77. else
  78. log_warning_msg "Docker already stopped - file $DOCKER_SSD_PIDFILE not found."
  79. fi
  80. ;;
  81. restart)
  82. fail_unless_root
  83. docker_pid=$(cat "$DOCKER_SSD_PIDFILE" 2> /dev/null || true)
  84. [ -n "$docker_pid" ] \
  85. && ps -p $docker_pid > /dev/null 2>&1 \
  86. && $0 stop
  87. $0 start
  88. ;;
  89. force-reload)
  90. fail_unless_root
  91. $0 restart
  92. ;;
  93. status)
  94. status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKERD" "$DOCKER_DESC"
  95. ;;
  96. *)
  97. echo "Usage: service docker {start|stop|restart|status}"
  98. exit 1
  99. ;;
  100. esac