]> git.proxmox.com Git - pve-sheepdog.git/blob - debian/pve-sheepdog.sheepdog.init.d
349c481fe83a93d61387c769fd0cd2232a74d5ad
[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="256M"
27 DAEMON_ARGS=""
28
29 # Read configuration variable file if it is present
30 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
31
32 if [ "$START" != "yes" ]; then
33 exit 0
34 fi
35
36 . /lib/lsb/init-functions
37
38 #
39 # Function that starts the daemon/service
40 #
41 do_start()
42 {
43 mkdir -p /var/run
44
45 # Return
46 # 0 if daemon has been started
47 # 1 if daemon was already running
48 # 2 if daemon could not be started
49 ulimit -n 1024000 #avoid check_host_env(395) WARN: Allowed open files 1024 too small, suggested 1024000 warning message
50 ulimit -c unlimited #avoid check_host_env(404) Allowed core file size 0, suggested unlimited warning message
51 DAEMON_ARGS="${DAEMON_ARGS} --pidfile ${PIDFILE}"
52 DAEMON_ARGS="${DAEMON_ARGS} $ROOTDIR"
53
54 # /path/to/meta-store,/path/to/disk1{,/path/to/disk2,...}
55 for d in $ROOTDIR/disc*
56 do
57 if [ -d "$d" ]; then
58 DAEMON_ARGS="${DAEMON_ARGS},$d"
59 fi
60 done
61
62 if [ -d "$ROOTDIR/journal" ]; then
63 DAEMON_ARGS="${DAEMON_ARGS} -j dir=$ROOTDIR/journal,size=$JOURNALSIZE"
64
65 fi
66 status_of_proc -p ${PIDFILE} $DAEMON "$NAME" >/dev/null && continue
67 start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec $DAEMON -- $DAEMON_ARGS || return 2
68
69 return 0
70 }
71
72 #
73 # Function that stops the daemon/service
74 #
75 do_stop()
76 {
77 # Return
78 # 0 if daemon has been stopped
79 # 1 if daemon was already stopped
80 # 2 if daemon could not be stopped
81 # other if a failure occurred
82
83 start-stop-daemon --stop --oknodo --retry=TERM/20/KILL/5 --quiet --pidfile ${PIDFILE} --exec $DAEMON || return 2
84 }
85
86 case "$1" in
87 start)
88 log_daemon_msg "Starting $DESC " "$NAME"
89 do_start
90 case "$?" in
91 0|1) log_end_msg 0 ;;
92 2) log_end_msg 1 ;;
93 esac
94 ;;
95 stop)
96 log_daemon_msg "Stopping $DESC" "$NAME"
97 do_stop
98 case "$?" in
99 0|1) log_end_msg 0 ;;
100 2) log_end_msg 1 ;;
101 esac
102
103 ;;
104 status)
105 status_of_proc -p ${PIDFILE} $DAEMON "$NAME ${dir}" || exit 1
106 ;;
107 restart|force-reload)
108 log_daemon_msg "Restarting $DESC" "$NAME"
109 do_stop
110 case "$?" in
111 0|1)
112 do_start
113 case "$?" in
114 0) log_end_msg 0 ;;
115 1) log_end_msg 1 ;; # Old process is still running
116 *) log_end_msg 1 ;; # Failed to start
117 esac
118 ;;
119 *)
120 # Failed to stop
121 log_end_msg 1
122 ;;
123 esac
124 ;;
125 *)
126 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
127 exit 3
128 ;;
129 esac
130
131 :
132