forked from SUSE/s390-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpram
278 lines (249 loc) · 6.26 KB
/
xpram
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#! /bin/sh
# Copyright (c) 2004 SUSE LINUX AG Nuernberg, Germany.
#
# Submit feedback to http://www.suse.de/feedback/
#
# /etc/init.d/xpram
#
# and symbolic its link
#
# /use/sbin/rcxpram
#
# System startup script for XPRAM device driver
#
### BEGIN INIT INFO
# Provides: xpram
# Required-Start: $remote_fs
# Required-Stop: $null
# Default-Start: 3 5
# Default-Stop: 0 1 6
# Short-Description: XPRAM device driver
# Description: Creates an xpram device and mounts it
### END INIT INFO
#
XPRAM_CONFIG_FILE=/etc/sysconfig/xpram
read_config_file() {
if [ config_read = 1 ]; then
return 0
fi
file=$XPRAM_CONFIG_FILE
if [ -s "$file" ]; then
source $file
config_read=1
else
echo -ne "Cannot read $file: empty or nonexistant! "
# Means not configured:
rc_failed 6
rc_status -v
return 6
fi
}
prepare_xpram() {
if [ -z "$XPRAM_MNTPATH" -o -z "$XPRAM_DEVNODE" ]; then
echo -n "Cannot mkfs/mount XPRAM: Missing parameters! "
rc_failed 6
rc_status -v
rc_exit
fi
grep -q $XPRAM_DEVNODE /proc/mounts 2>&1 > /dev/null
if [ $? -eq 0 ] ; then
echo -n "$service: $XPRAM_DEVNODE already mounted! "
return
fi
current_fstype=`vol_id -t $XPRAM_DEVNODE 2> /dev/null`
if [ $? -ne 0 -o "$XPRAM_FORCE" = "yes" ]
then
# Does not contain a valid filesystem/swap space
if [ "$XPRAM_FSTYPE" = swap ]
then
mkswap $XPRAM_DEVNODE
else
mkfs -t "$XPRAM_FSTYPE" -b 4096 "$XPRAM_DEVNODE"
fi
sleep 1 # workaround
current_fstype=$XPRAM_FSTYPE
fi
if [ ! "$current_fstype" = "$XPRAM_FSTYPE" ]
then
echo
echo -n "Warning: current filessystem and configured filesystem are not the same!"
rc_failed 6
rc_status -v
rc_exit
fi
if [ "$XPRAM_FSTYPE" = swap ]
then
if [ "$XPRAM_SWAP_PRI" = "" ]
then
swapon $XPRAM_DEVNODE
else
swapon -p $XPRAM_SWAP_PRI $XPRAM_DEVNODE
fi
else
if [ ! -d "$XPRAM_MNTPATH" ]
then
mkdir -p "$XPRAM_MNTPATH"
fi
mount "$XPRAM_DEVNODE" "$XPRAM_MNTPATH"
if [ $? -ne 0 ]
then
echo -n "Mount failed with error code $?"
rc_failed 6
rc_status -v
rc_exit
fi
fi
}
# Shell functions sourced from /etc/rc.status:
# rc_check check and set local and overall rc status
# rc_status check and set local and overall rc status
# rc_status -v ditto but be verbose in local rc status
# rc_status -v -r ditto and clear the local rc status
# rc_failed set local and overall rc status to failed
# rc_failed <num> set local and overall rc status to <num><num>
# rc_reset clear local rc status (overall remains)
# rc_exit exit appropriate to overall rc status
. /etc/rc.status
# First reset status of this service
config_read=0
rc_reset
# Return values acc. 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
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.
check_config () {
if [ -z "$XPRAM_MODULE" ]; then
echo -n "$file: parameters XPRAM_MODULE missing! "
rc_failed 6
rc_status -v
rc_exit
fi
}
quit_disabled() {
if [ "$XPRAM_START" != "yes" ]; then
# Config file exists but xpram not enabled, do not complain,
# but note with exit status 6 that we are not configured.
rc_exit
fi
}
check_enabled() {
if [ "$XPRAM_START" != "yes" ]; then
rc_failed 6
if [ "$XPRAM_MODULE" ]; then
if grep -q "$XPRAM_MODULE" /proc/modules; then
echo -n "Service $service $_rc_todo "
rc_status -v
fi
fi
rc_exit
fi
}
service="xpram"
case "$1" in
start)
# Read in configuration
read_config_file || rc_exit
check_enabled
quit_disabled
check_config
echo -n "Creating $service device "
modprobe "$XPRAM_MODULE"
if [ $? -ne 0 ]; then
echo -n "- failed to load $XPRAM_MODULE "
rc_failed 1
else
prepare_xpram
fi
# Remember status and be verbose
rc_status -v
;;
stop)
# Read in configuration
read_config_file || rc_exit
# check_enabled
# quit_disabled
echo -n "Removing $service device "
check_config
if [ "$XPRAM_DEVNODE" ]; then
if grep -q $XPRAM_DEVNODE /proc/mounts; then
umount $XPRAM_DEVNODE
fi
if swapon -s | grep -q $XPRAM_DEVNODE; then
swapoff $XPRAM_DEVNODE
fi
fi
if grep -q "$XPRAM_MODULE" /proc/modules; then
rmmod "$XPRAM_MODULE"
rc_status
else
rc_failed 7
fi
# Remember status and be verbose
rc_status -v
;;
try-restart)
## Stop the service and if this succeeds (i.e. the
## service was running before), start it again.
## Note: try-restart is not (yet) part of LSB (as of 0.7.5)
$0 status >/dev/null && $0 restart
# Remember status and be quiet
rc_status
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
force-reload)
echo -n "Force-reload $service "
$0 stop && $0 start
rc_status
;;
reload)
echo -n "Reloading $service not supported."
## it does not support reload:
rc_failed 3
rc_status -v
;;
status)
echo -n "Checking $service "
# Status has a slightly different meaning for the status command:
# 0 - service running
# 1 - service dead, but /var/run/ pid file exists
# 3 - service not running
# Read in configuration
read_config_file || rc_exit
check_config
lsmod | grep -q $XPRAM_MODULE
if [ $? -eq 0 ]; then
if [ "$XPRAM_DEVNODE" ]; then
if ! grep -q $XPRAM_DEVNODE /proc/mounts && ! swapon -s | grep -q $XPRAM_DEVNODE; then
xpram_result=3
echo -n "loaded, but $XPRAM_DEVNODE not used"
rc_failed 3
fi
fi
else
rc_failed 3
fi
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart}"
exit 1
;;
esac
rc_exit