-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathlcfs.systemv
executable file
·111 lines (94 loc) · 3.22 KB
/
lcfs.systemv
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
#!/bin/sh
#
# chkconfig: 345 99 9
# description: LCFS service daemon start/stop script
# Source function library
[ -e /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
# Source networking configuration.
[ -e /etc/sysconfig/network ] && . /etc/sysconfig/network
TERM=linux
SERVICE_NAME=lcfssrv
SERVICE_LOG=/var/log/${SERVICE_NAME}.log
SERVICE_SCRIPT=/opt/lcfs/bin/lcfs-setup.sh
SERVICE_ENV_FILE=/etc/lcfs/lcfs.env
SERVICE_LOCK_FILE=/var/lock/${SERVICE_NAME}
function log_service_msg()
{
local append=">"
[ -z "$1" -o -z "$2" ] && return 0
[ "$3" == "append" ] && append=">>"
local msg="$1"
local log="$2"
local date_msg="`/bin/date +\"%F %T\"`: $msg"
/bin/sh -c "echo -e \"$date_msg\" $append $log 2>&1"
}
function start_lcfs()
{
local ret=0
if [ ! -e ${SERVICE_ENV_FILE} ]; then
echo "LCFS is not configured to start. Run ${SERVICE_SCRIPT}."
exit 1
fi
log_service_msg "${ACTION} ${SERVICE_NAME}" "${SERVICE_LOG}" "append"
${SERVICE_SCRIPT} --start >> ${SERVICE_LOG} 2>&1
ret=$?
if [ ${ret} -eq 0 ]; then
touch ${SERVICE_LOCK_FILE}
${SERVICE_SCRIPT} --status
else
echo "Error: failed to start ${SERVICE_NAME} service. Check ${SERVICE_LOG} for more details."
fi
return ${ret}
}
function stop_lcfs()
{
local ret=0
log_service_msg "${ACTION} ${SERVICE_NAME}" "${SERVICE_LOG}" "append"
${SERVICE_SCRIPT} --stop >> ${SERVICE_LOG} 2>&1
ret=$?
if [ ${ret} -eq 0 ]; then
\rm -f ${SERVICE_LOCK_FILE}
${SERVICE_SCRIPT} --status
else
echo "Error: failed to start ${SERVICE_NAME} service. Check ${SERVICE_LOG} for more details."
fi
return ${ret}
}
RETVAL=0
case "$1" in
start)
ACTION=Starting
start_lcfs
RETVAL=$?
echo
;;
stop)
ACTION=Stopping
stop_lcfs
RETVAL=$?
echo
;;
status)
ACTION=Status
log_service_msg "${ACTION} ${SERVICE_NAME}" "${SERVICE_LOG}" "append"
${SERVICE_SCRIPT} --status
RETVAL=$?
echo
;;
restart)
log_service_msg "${ACTION} ${SERVICE_NAME}" "${SERVICE_LOG}" "append"
stop_lcfs
RETVAL=$?
sleep 2
if [ ${RETVAL} -eq 0 ]; then
start_lcfs
RETVAL=$?
fi
echo
;;
*)
echo "Usage: ${SERVICE_NAME} {start|stop|status|restart}"
RETVAL=1
;;
esac
exit $RETVAL