-
Notifications
You must be signed in to change notification settings - Fork 283
/
init.d-xapi
executable file
·138 lines (122 loc) · 3.07 KB
/
init.d-xapi
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
#! /bin/bash
# Source function library.
. /etc/init.d/functions
if [ -f /etc/sysconfig/xapi ]; then
. /etc/sysconfig/xapi
fi
XAPI_STARTUP_COOKIE=/var/run/xapi_startup.cookie
XAPI_INIT_COMPLETE_COOKIE=/var/run/xapi_init_complete.cookie
XAPI_BLOCK_STARTUP_COOKIE=@ETCDIR@/xapi_block_startup
XAPI_BOOT_TIME_INFO_UPDATED=@ETCDIR@/boot_time_info_updated
# Enable core dumping for xapi
ulimit -c unlimited
start() {
echo -n $"Starting xapi: "
# clear out any old xapi coredumps
rm -rf /var/xapi/debug
if [ -e /var/lock/subsys/xapi ]; then
if [ -e /var/run/xapi.pid ] && [ -e /proc/`cat /var/run/xapi.pid` ]; then
echo -n $"cannot start xapi: already running.";
failure $"cannot start xapi: already running.";
echo
return 1
fi
fi
# This bit is ok though:
rm -f ${XAPI_STARTUP_COOKIE}
rm -f ${XAPI_INIT_COMPLETE_COOKIE}
# Enable backtraces
export OCAMLRUNPARAM="b"
# For debugging, prevent xapi startup
if [ -e ${XAPI_BLOCK_STARTUP_COOKIE} ]; then
if [ -e ${XAPI_BOOT_TIME_INFO_UPDATED} ]; then
logger "Aborting xapi startup because ${XAPI_BLOCK_STARTUP_COOKIE} is present and the system has just booted. Remove file and try again";
echo -n $"startup blocked."
failure $"startup blocked."
echo
return 1
fi
fi
if [ -e ${XAPI_BOOT_TIME_INFO_UPDATED} ]; then
# clear out qemu coredumps/chroot dirs on system boot:
rm -rf /var/xen/qemu/*
#rm -f ${XAPI_BOOT_TIME_INFO_UPDATED}
echo
exec "@BINDIR@/xapi" -nowatchdog ${xapiflags} \
-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE} -onsystemboot
RETVAL=$?
else
echo
exec "@BINDIR@/xapi" -nowatchdog ${xapiflags} \
-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE}
RETVAL=$?
fi
}
stop() {
echo -n $"Stopping xapi: "
if [ ! -e /var/lock/subsys/xapi ]; then
echo -n $"cannot stop xapi: xapi is not running."
failure $"cannot stop xapi: xapi is not running."
echo
return 1;
fi
rm -f ${XAPI_STARTUP_COOKIE}
rm -f ${XAPI_INIT_COMPLETE_COOKIE}
# Find out if xapi has died
RETRIES=60
while [ ${RETRIES} -ne 0 ]; do
xe host-shutdown-agent 2> /dev/null
# Finish if all xapis have gone
xapi_pids=$(pidof xapi)
if [ -z "$xapi_pids" ]; then
logger "xapi stopped successfully"
rm -f /var/run/xapi.pid /var/lock/subsys/xapi
success $"xapi stopped successfully"
echo
return 0
fi
sleep 1
echo -n .
RETRIES=$(( ${RETRIES} - 1 ))
done
killproc xapi
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
logger "xapi stopped forcibly"
success $"xapi stopped successfully"
echo
rm -f /var/run/xapi.pid /var/lock/subsys/xapi
else
logger "failed to stop xapi"
failure $"failed to stop xapi"
echo
fi
return $RETVAL
}
rhstatus() {
status xapi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
rhstatus
;;
condrestart)
[ -f /var/lock/subsys/xapi ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac