blob: ffd5b23902b14242f1b45bb4faf46dc09b0251a9 (
plain)
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
|
#!/sbin/openrc-run
#
# Copyright (C) 2008 Mark Buechler <mark.buechler@gmail.com>
# Copyright (C) 2009 Bart Van Assche <bvanassche@acm.org>
# Copyright (C) 2010 Scott Bowe <scottb@sentania.net>
# This software is made available under the GPLv2 license.
#
# System startup script for the SCST core functionality.
#
# Customized for gentoo linux by Scott Bowe.
#
# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while
# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash !
opts="${opts} try_restart reload force_reload"
depend() {
use logger
}
DEFAULTFILE="/etc/conf.d/scst"
SCST_CFG=/etc/scst.conf
MODPROBE="/sbin/modprobe"
RMMOD="/sbin/rmmod"
if [ -f $DEFAULTFILE ]; then
. $DEFAULTFILE
fi
# Modules to load/unload.
#
# !!! DON'T ADD HERE TARGET DRIVERS, WHICH IMMEDIATELLY START ACCEPTING
# !!! NEW CONNECTIONS, BECAUSE AT THIS POINT ACCESS CONTROL HASN'T CONFIGURED
# !!! YET!
#
SCST_MODULES="scst scst_disk scst_vdisk"
# Return values according to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
checkconfig() {
if [ ! -f $SCST_CFG ] ; then
eerror "Please create $SCST_CFG"
return 1
fi
return 0
}
checkinstall() {
if [ ! -x `which scstadmin` ] ; then
eerror "scstadmin is not intalled"
return 1
fi
return 0
}
start() {
ebegin "Loading and configuring the mid-level SCSI target SCST"
eindent
checkconfig
checkinstall || return $?
ret=0
for module in ${SCST_MODULES}; do
einfo "Loading SCST module ${module}..."
if ! modprobe "${module}"; then
eerror "${module} failed to load"
eend $? "Failed to load SCST"
return $?
fi
done
einfo "Configuring SCST..."
eindent
if [ -f $SCST_CFG ]; then
if scstadmin -config $SCST_CFG >/dev/null 2>&1; then
einfo "SCST config was loaded"
else
eend $? "SCST config could not be loaded"
return $?
fi
else
einfo "SCST configuration file $SCST_CFG missing, skipping"
return 0
fi
eoutdent
eoutdent
einfo "SCST loaded!!!"
eend $?
}
stop() {
## Stop the service.
ebegin "Stopping the mid-level SCSI target SCST"
eindent
reverse_list=""
for module in ${SCST_MODULES}; do
reverse_list="${module} ${reverse_list}"
done
for module in ${reverse_list}; do
einfo "Unloading ${module}"
if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then
eindent
eend $? "Failed to unload ${module}"
return $?
fi
done
eoutdent
einfo "SCST unloaded!!!"
eend $?
}
restart() {
## Stop and restart the service if the service is already running,
## otherwise start the service.
stop
sleep 3
start
}
try_restart() {
## Restart the service if the service is already running.
status >/dev/null 2>&1 && restart
}
reload() {
## Cause the configuration of the service to be reloaded without
## actually stopping and restarting the service.
einfo "Reloading SCST configuration"
eindent
if scstadmin -config $SCST_CFG >/dev/null 2>&1; then
ret=0
ebegin "SCST config reloaded"
else
eend $? "SCST config could not be releaded"
exit 1
fi
}
force_reload() {
## Cause the configuration to be reloaded if the service supports this,
## otherwise restart the service if it is running.
einfo "Reloading SCST configuration"
eindent
if scstadmin -config $SCST_CFG >/dev/null 2>&1; then
ret=0
ebegin "SCST config reloaded"
else
restart
fi
}
status() {
## Print the current status of the service.
einfo "SCST status: "
eindent
for module in ${SCST_MODULES}; do
if [ ! -e "/sys/module/${module}" ]; then
einfo "${module} not loaded"
ret=3
eend $ret
return $ret
fi
done
ret=0
ebegin "SCST modules loaded OK"
eend $ret
}
|