]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VBLADE/vblade-master/contrib/persistence/vblade.init.daemon
Fix the order issue in TreeView mode. (#3218)
[Ventoy.git] / VBLADE / vblade-master / contrib / persistence / vblade.init.daemon
1 #!/bin/sh
2
3 PATH=/sbin:/usr/sbin:/bin:/usr/bin
4 DESC="vblade export"
5 NAME=vblade
6 VBLADE="/usr/sbin/$NAME"
7 DAEMON=/usr/bin/daemon
8 IONICE=/usr/bin/ionice
9 PIDDIR="/var/run/vblade/"
10
11 [ -x "$VBLADE" ] || exit 0
12 [ -x "$DAEMON" ] || exit 0
13
14 mkdir -p "$PIDDIR"
15
16 # Emulation of LSB functions
17 VERBOSE=1
18 log_daemon_msg () {
19 printf '%s ' "$@"
20 }
21 log_end_msg () {
22 local CODE="$1"
23 if [ "$CODE" -eq 0 ] ; then
24 echo '.'
25 else
26 echo 'failed!'
27 fi
28 }
29
30 # Start a vblade instance
31 #
32 # Return
33 # 0 if daemon has been started
34 # 1 if daemon was already running
35 # 2 if daemon could not be started
36 do_start () {
37 local INSTANCE="$1"
38 local CONFIG="$2"
39
40 sh -n "$CONFIG" 2>/dev/null || return 2
41
42 shelf=
43 slot=
44 filename=
45 netif=
46 options=
47 ionice=
48
49 . "$CONFIG"
50
51 [ "$netif" ] || return 2
52 [ "$shelf" ] || return 2
53 [ "$slot" ] || return 2
54 [ "$filename" ] || return 2
55
56 if [ "$ionice" ] ; then
57 if [ -x "$IONICE" ] ; then
58 ionice="$IONICE $ionice"
59 else
60 ionice=
61 fi
62 fi
63
64 "$DAEMON" \
65 --running \
66 --name "$INSTANCE" \
67 --pidfiles "$PIDDIR" \
68 && return 1
69 $ionice "$DAEMON" \
70 --respawn \
71 --name "$INSTANCE" \
72 --pidfiles "$PIDDIR" \
73 --output daemon.notice \
74 --stdout daemon.notice \
75 --stderr daemon.err -- \
76 $VBLADE $options $shelf $slot $netif $filename || return 2
77 }
78
79 # Stop a vblade instance
80 #
81 # Return
82 # 0 if daemon has been stopped
83 # 1 if daemon was already stopped
84 # 2 if daemon could not be stopped
85 # other if a failure occurred
86 do_stop () {
87 local INSTANCE="$1"
88
89 "$DAEMON" \
90 --running \
91 --name "$INSTANCE" \
92 --pidfiles "$PIDDIR" || return 1
93 "$DAEMON" \
94 --stop \
95 --name "$INSTANCE" \
96 --pidfiles "$PIDDIR" \
97 --stop || return 2
98 # Wait until the process is gone
99 for i in $(seq 1 10) ; do
100 "$DAEMON" \
101 --running \
102 --name "$INSTANCE" \
103 --pidfiles "$PIDDIR" || return 0
104 done
105 return 2
106 }
107
108 EXIT=0
109
110 do_action () {
111 local CONFIG="$1"
112
113 INSTANCE="$(basename "${CONFIG%%.conf}")"
114
115 case "$ACTION" in
116 start)
117 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$INSTANCE"
118 do_start "$INSTANCE" "$CONFIG"
119 case "$?" in
120 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
121 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
122 esac
123 ;;
124 stop)
125 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$INSTANCE"
126 do_stop "$INSTANCE"
127 case "$?" in
128 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
129 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
130 esac
131 ;;
132 status)
133 if "$DAEMON" \
134 --running \
135 --name "$INSTANCE" \
136 --pidfiles "$PIDDIR"
137 then
138 echo "$DESC instance $INSTANCE is running"
139 else
140 echo "$DESC instance $INSTANCE is not running"
141 EXIT=1
142 fi
143 ;;
144 restart|force-reload)
145 log_daemon_msg "Restarting $DESC" "$INSTANCE"
146 do_stop "$INSTANCE"
147 case "$?" in
148 0|1)
149 do_start "$INSTANCE" "$CONFIG"
150 case "$?" in
151 0) log_end_msg 0 ;;
152 *)
153 # Old process is still running or
154 # failed to start
155 log_end_msg 1 ;;
156 esac
157 ;;
158 *)
159 # Failed to stop
160 log_end_msg 1
161 ;;
162 esac
163 ;;
164 *)
165 echo "Usage: /etc/init.d/vblade {start|stop|status|restart|force-reload} [<export> ...]" >&2
166 exit 3
167 ;;
168 esac
169 }
170
171
172 ACTION="$1"
173 shift
174
175 if [ "$1" ] ; then
176 while [ "$1" ] ; do
177 CONFIG="/etc/vblade.conf.d/$1.conf"
178 if [ -f "$CONFIG" ] ; then
179 do_action "$CONFIG"
180 fi
181 shift
182 done
183 else
184 for CONFIG in /etc/vblade.conf.d/*.conf ; do
185 if [ -f "$CONFIG" ] ; then
186 do_action "$CONFIG"
187 fi
188 done
189 fi
190
191 exit $EXIT