-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsysv-initscript.sh
More file actions
executable file
·198 lines (139 loc) · 4.21 KB
/
sysv-initscript.sh
File metadata and controls
executable file
·198 lines (139 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: udev
# Required-Start: mountkernfs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Start vdevd, populate /dev and load drivers.
### END INIT INFO
SCRIPTNAME=$0
# fill defaults
if [ -z "$VDEV_BIN" ]; then
VDEV_BIN=/sbin/vdevd
fi
if [ -z "$VDEV_CONFIG" ]; then
VDEV_CONFIG=/etc/vdev/vdevd.conf
fi
if [ -z "$VDEV_MOUNTPOINT" ]; then
VDEV_MOUNTPOINT=/dev
fi
# load an ini file as a set of namespaced environment variables, echoing them to stdout
# $1 is the path to the file
# $2 is the namespace to be prepended to each variable name
source_ini_file() {
local FILE_PATH NAMESPACE line KEY VALUE
FILE_PATH=$1
NAMESPACE=$2
# convert [ini style header] to ""
/bin/cat $FILE_PATH | /bin/sed "s/.*\[.*\].*//g" | \
while read line; do
KEY=$(echo $line | /bin/sed "s/\(^.*\)=.*/\1/g");
VALUE=$(echo $line | /bin/sed "s/^.*=\(.*\)$/\1/g");
if [ -n "$KEY" ]; then
echo "${NAMESPACE}${KEY}=${VALUE}"
fi
done
}
##############################################################################
[ -x $VDEV_BIN ] || exit 0
PATH="/sbin:/bin"
# defaults
tmpfs_size="10M"
. /lib/lsb/init-functions
# system-wide vdevd needs /sys to be mounted
if [ ! -d /sys/class/ ]; then
log_failure_msg "vdev requires a mounted sysfs, not started"
log_end_msg 1
fi
# system-wide vdevd needs "modern" sysfs
if [ -d /sys/class/mem/null -a ! -L /sys/class/mem/null ] || \
[ -e /sys/block -a ! -e /sys/class/block ]; then
log_warning_msg "CONFIG_SYSFS_DEPRECATED must not be selected"
log_warning_msg "Booting will continue in 30 seconds but many things will be broken"
sleep 30
fi
# load vdev config variables as vdev_config_*
eval $(source_ini_file $VDEV_CONFIG "vdev_config_")
# config sanity check
if [ -z "$vdev_config_pidfile" ]; then
log_warning_msg "No PID file defined in $VDEV_CONFIG. Please set the pidfile= directive."
log_warning_msg "You will be unable control vdevd with this init script."
fi
# start up the system-wide vdevd
# $@ arguments to vdevd
vdevd_start() {
# clear uevent helper--vdevd subsumes its role
if [ -w /sys/kernel/uevent_helper ]; then
echo > /sys/kernel/uevent_helper
fi
# set the SELinux context for devices created in the initramfs
[ -x /sbin/restorecon ] && /sbin/restorecon -R $VDEV_MOUNTPOINT
log_daemon_msg "Starting the system device event dispatcher" "vdevd"
# make sure log directory exists...
if [ -n "$vdev_config_logfile" ]; then
vdev_log_dir="$(echo "$vdev_config_logfile" | sed 's/[^/]\+$//g')"
if [ -n "$vdev_log_dir" ]; then
mkdir -p "$vdev_log_dir"
fi
fi
# make sure the pid directory exists
if [ -n "$vdev_config_pidfile" ]; then
vdev_pid_dir="$(echo "$vdev_config_pidfile" | sed 's/[^/]\+$//g')"
if [ -n "$vdev_pid_dir" ]; then
mkdir -p "$vdev_pid_dir"
fi
fi
# start vdev
if "$VDEV_BIN" -c "$VDEV_CONFIG" $@ "$VDEV_MOUNTPOINT"; then
log_end_msg $?
else
log_warning_msg $?
log_warning_msg "Errors when starting \"$VDEV_BIN\" -c \"$VDEV_CONFIG\" "
log_warning_msg "Waiting 15 seconds and trying to continue anyway"
sleep 15
fi
return 0
}
# reseed device files with --once
# $@ arguments to vdevd
vdevd_once() {
log_daemon_msg "(Re)seeding device files" "vdevd"
# run vdevd once
$VDEV_BIN -c $VDEV_CONFIG --once $@ $VDEV_MOUNTPOINT
log_end_msg $?
return 0
}
# stop the system-wide vdevd
vdevd_stop() {
log_daemon_msg "Sending SIGTERM to the system device event dispatcher" "vdevd"
if ! [ -f $vdev_config_pidfile ]; then
echo "No PID file at $vdev_config_pidfile" >&2
exit 1
fi
# kill vdevd with SIGTERM
VDEV_PID=$(/bin/cat $vdev_config_pidfile)
/bin/kill -s SIGTERM $VDEV_PID
log_end_msg $?
return 0
}
case "$1" in
start)
vdevd_start
;;
stop)
vdevd_stop
;;
once)
vdevd_once
;;
restart)
vdevd_stop
vdevd_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|once|restart}" >&2
exit 1
;;
esac
exit 0