|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +### BEGIN INIT INFO |
| 5 | +# Provides: dkv-netshare |
| 6 | +# Required-Start: $syslog $remote_fs $network |
| 7 | +# Required-Stop: $syslog $remote_fs $network |
| 8 | +# Default-Start: 2 3 4 5 |
| 9 | +# Default-Stop: 0 1 6 |
| 10 | +# Short-Description: Init for docker-volume-netshare |
| 11 | +# Description: Docker volume plugin supporting NFS, EFS and CIFS |
| 12 | +### END INIT INFO |
| 13 | + |
| 14 | +export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin |
| 15 | + |
| 16 | +BASE=$(basename $0) |
| 17 | + |
| 18 | +# modify these in /etc/default/$BASE (/etc/default/dkv-netshare) |
| 19 | +DKV_NETSHARE=/usr/bin/$BASE |
| 20 | +# This is the pid file created/managed by start-stop-daemon |
| 21 | +DKV_NETSHARE_SSD_PIDFILE=/var/run/$BASE-ssd.pid |
| 22 | +DKV_NETSHARE_LOGFILE=/var/log/$BASE.log |
| 23 | +DKV_NETSHARE_OPTS= |
| 24 | +DKV_NETSHARE_DESC="Docker-Volume-Netshare" |
| 25 | + |
| 26 | +# Get lsb functions |
| 27 | +. /lib/lsb/init-functions |
| 28 | + |
| 29 | +if [ -f /etc/default/$BASE ]; then |
| 30 | + . /etc/default/$BASE |
| 31 | +fi |
| 32 | + |
| 33 | +# Check docker is present |
| 34 | +if [ ! -x $DKV_NETSHARE ]; then |
| 35 | + log_failure_msg "$DKV_NETSHARE not present or not executable" |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +fail_unless_root() { |
| 40 | + if [ "$(id -u)" != '0' ]; then |
| 41 | + log_failure_msg "$DKV_NETSHARE_DESC must be run as root" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +case "$1" in |
| 47 | + start) |
| 48 | + fail_unless_root |
| 49 | + |
| 50 | + touch "$DKV_NETSHARE_LOGFILE" |
| 51 | + chgrp docker "$DKV_NETSHARE_LOGFILE" |
| 52 | + |
| 53 | + |
| 54 | + log_begin_msg "Starting $DKV_NETSHARE_DESC: $BASE" |
| 55 | + start-stop-daemon --start --background \ |
| 56 | + --no-close \ |
| 57 | + --exec "$DKV_NETSHARE" \ |
| 58 | + --pidfile "$DKV_NETSHARE_SSD_PIDFILE" \ |
| 59 | + --make-pidfile \ |
| 60 | + -- \ |
| 61 | + $DKV_NETSHARE_OPTS \ |
| 62 | + >> "$DKV_NETSHARE_LOGFILE" 2>&1 |
| 63 | + log_end_msg $? |
| 64 | + ;; |
| 65 | + |
| 66 | + stop) |
| 67 | + fail_unless_root |
| 68 | + log_begin_msg "Stopping $DKV_NETSHARE_DESC: $BASE" |
| 69 | + start-stop-daemon --stop --pidfile "$DKV_NETSHARE_SSD_PIDFILE" |
| 70 | + log_end_msg $? |
| 71 | + ;; |
| 72 | + |
| 73 | + restart) |
| 74 | + fail_unless_root |
| 75 | + dkv_pid=`cat "$DKV_NETSHARE_SSD_PIDFILE" 2>/dev/null` |
| 76 | + [ -n "$dkv_pid" ] \ |
| 77 | + && ps -p $dkv_pid > /dev/null 2>&1 \ |
| 78 | + && $0 stop |
| 79 | + $0 start |
| 80 | + ;; |
| 81 | + |
| 82 | + force-reload) |
| 83 | + fail_unless_root |
| 84 | + $0 restart |
| 85 | + ;; |
| 86 | + |
| 87 | + status) |
| 88 | + status_of_proc -p "$DKV_NETSHARE_SSD_PIDFILE" "$DKV_NETSHARE" "$DKV_NETSHARE_DESC" |
| 89 | + ;; |
| 90 | + |
| 91 | + *) |
| 92 | + echo "Usage: $0 {start|stop|restart|status}" |
| 93 | + exit 1 |
| 94 | + ;; |
| 95 | +esac |
0 commit comments