]> git.proxmox.com Git - pve-sheepdog.git/blob - debian/pve-sheepdog.sheepdog.init.d
2de87448bf0663341b9fa0c00a37055baa270a6e
[pve-sheepdog.git] / debian / pve-sheepdog.sheepdog.init.d
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides: sheepdog
4 # Required-Start: $network $remote_fs $syslog cman
5 # Required-Stop: $network $remote_fs $syslog cman
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: Sheepdog server
9 # Description: Sheepdog server
10 ### END INIT INFO
11
12 # Author: Proxmox Support Team <support@proxmox.com>
13
14 # PATH should only include /usr/* if it runs after the mountnfs.sh script
15 PATH=/sbin:/usr/sbin:/bin:/usr/bin
16 DESC="Sheepdog Server" # Introduce a short description here
17 NAME=sheepdog # Introduce the short server's name here
18 DAEMON=/usr/sbin/sheep # Introduce the server's location here
19 SCRIPTNAME=/etc/init.d/$NAME
20 PIDFILE="/var/run/sheep.pid"
21
22 # Exit if the package is not installed
23 [ -x $DAEMON ] || exit 0
24
25 ROOTDIR="/var/lib/sheepdog/"
26 JOURNALSIZE="256"
27
28 # Read configuration variable file if it is present
29 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
30
31 if [ "$START" != "yes" ]; then
32 exit 0
33 fi
34
35 . /lib/lsb/init-functions
36
37 #
38 # Function that starts the daemon/service
39 #
40 do_start()
41 {
42 mkdir -p /var/run
43
44 # Return
45 # 0 if daemon has been started
46 # 1 if daemon was already running
47 # 2 if daemon could not be started
48 ulimit -n 1024000 #avoid check_host_env(395) WARN: Allowed open files 1024 too small, suggested 1024000 warning message
49 ulimit -c unlimited #avoid check_host_env(404) Allowed core file size 0, suggested unlimited warning message
50 DAEMON_ARGS="--pidfile ${PIDFILE}"
51 DAEMON_ARGS="${DAEMON_ARGS} $ROOTDIR"
52
53 # /path/to/meta-store,/path/to/disk1{,/path/to/disk2,...}
54 for d in $ROOTDIR/disc*
55 do
56 if [ -d "$d" ]; then
57 DAEMON_ARGS="${DAEMON_ARGS},$d"
58 fi
59 done
60
61 if [ -d "$ROOTDIR/journal" ]; then
62 DAEMON_ARGS="${DAEMON_ARGS} -j dir=$ROOTDIR/journal,size=$JOURNALSIZE"
63
64 fi
65 status_of_proc -p ${PIDFILE} $DAEMON "$NAME" >/dev/null && continue
66 start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec $DAEMON -- $DAEMON_ARGS || return 2
67
68 return 0
69 }
70
71 #
72 # Function that stops the daemon/service
73 #
74 do_stop()
75 {
76 # Return
77 # 0 if daemon has been stopped
78 # 1 if daemon was already stopped
79 # 2 if daemon could not be stopped
80 # other if a failure occurred
81
82 start-stop-daemon --stop --oknodo --retry=TERM/20/KILL/5 --quiet --pidfile ${PIDFILE} --exec $DAEMON || return 2
83 }
84
85 case "$1" in
86 start)
87 log_daemon_msg "Starting $DESC " "$NAME"
88 do_start
89 case "$?" in
90 0|1) log_end_msg 0 ;;
91 2) log_end_msg 1 ;;
92 esac
93 ;;
94 stop)
95 log_daemon_msg "Stopping $DESC" "$NAME"
96 do_stop
97 case "$?" in
98 0|1) log_end_msg 0 ;;
99 2) log_end_msg 1 ;;
100 esac
101
102 ;;
103 status)
104 status_of_proc -p ${PIDFILE} $DAEMON "$NAME ${dir}" || exit 1
105 ;;
106 restart|force-reload)
107 log_daemon_msg "Restarting $DESC" "$NAME"
108 do_stop
109 case "$?" in
110 0|1)
111 do_start
112 case "$?" in
113 0) log_end_msg 0 ;;
114 1) log_end_msg 1 ;; # Old process is still running
115 *) log_end_msg 1 ;; # Failed to start
116 esac
117 ;;
118 *)
119 # Failed to stop
120 log_end_msg 1
121 ;;
122 esac
123 ;;
124 *)
125 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
126 exit 3
127 ;;
128 esac
129
130 :
131