docker 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: docker
  4. # Required-Start: $syslog $remote_fs
  5. # Required-Stop: $syslog $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Create lightweight, portable, self-sufficient containers.
  9. # Description:
  10. # Docker is an open-source project to easily create lightweight, portable,
  11. # self-sufficient containers from any application. The same container that a
  12. # developer builds and tests on a laptop can run at scale, in production, on
  13. # VMs, bare metal, OpenStack clusters, public clouds and more.
  14. ### END INIT INFO
  15. BASE=$(basename $0)
  16. DOCKER=/usr/bin/$BASE
  17. DOCKER_PIDFILE=/var/run/$BASE.pid
  18. DOCKER_OPTS=
  19. PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  20. # Get lsb functions
  21. . /lib/lsb/init-functions
  22. if [ -f /etc/default/$BASE ]; then
  23. . /etc/default/$BASE
  24. fi
  25. # see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
  26. if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | /bin/grep -q upstart; then
  27. log_failure_msg "Docker is managed via upstart, try using service $BASE $1"
  28. exit 1
  29. fi
  30. # Check docker is present
  31. if [ ! -x $DOCKER ]; then
  32. log_failure_msg "$DOCKER not present or not executable"
  33. exit 1
  34. fi
  35. fail_unless_root() {
  36. if [ "$(id -u)" != '0' ]; then
  37. log_failure_msg "Docker must be run as root"
  38. exit 1
  39. fi
  40. }
  41. case "$1" in
  42. start)
  43. fail_unless_root
  44. log_begin_msg "Starting Docker: $BASE"
  45. mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup 2>/dev/null
  46. start-stop-daemon --start --background \
  47. --exec "$DOCKER" \
  48. --pidfile "$DOCKER_PIDFILE" \
  49. -- -d -p "$DOCKER_PIDFILE" \
  50. $DOCKER_OPTS
  51. log_end_msg $?
  52. ;;
  53. stop)
  54. fail_unless_root
  55. log_begin_msg "Stopping Docker: $BASE"
  56. start-stop-daemon --stop \
  57. --pidfile "$DOCKER_PIDFILE"
  58. log_end_msg $?
  59. ;;
  60. restart)
  61. fail_unless_root
  62. docker_pid=`cat "$DOCKER_PIDFILE" 2>/dev/null`
  63. [ -n "$docker_pid" ] \
  64. && ps -p $docker_pid > /dev/null 2>&1 \
  65. && $0 stop
  66. $0 start
  67. ;;
  68. force-reload)
  69. fail_unless_root
  70. $0 restart
  71. ;;
  72. status)
  73. status_of_proc -p "$DOCKER_PIDFILE" "$DOCKER" docker
  74. ;;
  75. *)
  76. echo "Usage: $0 {start|stop|restart|status}"
  77. exit 1
  78. ;;
  79. esac
  80. exit 0