-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenericServiceScript
More file actions
executable file
·120 lines (102 loc) · 2.6 KB
/
genericServiceScript
File metadata and controls
executable file
·120 lines (102 loc) · 2.6 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
#!/bin/bash
#
# APPLICATION_NAME This shell script takes care of starting and stopping APPLICATION_NAME
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: APPLICATION_NAME
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: APPLICATION_NAME daemon
# Description: Starts the APPLICATION_NAME daemon.
### END INIT INFO
#
# Author: Eli Keimig
# Copyright: GPL 2012
# VARIABLES
USER="root"
NAME="Application_Name"
BIN="/usr/bin"
CONTAINER="${BIN}/CONTAINER" # REPLACE "CONTAINER" with something like "perl, bash, or python"
PROGRAM="Script_to_Execute"
START_ARGS="-d"
NAME="Container for ${NAME}"
LOG="/var/log/${NAME}_Service.log"
HOME="/apps/serviceDirectory"
WAIT_TIME=60
# EXECUTION
function start {
PID=`/bin/ps -ef | grep "${PROGRAM}" | grep -v "grep" | awk '{print $2}'`
if [ ${PID} ]
then
/bin/echo "${NAME} is already started"
else
/bin/echo "Starting ${NAME}..."
su ${USER} -c "${CONTAINER} ${HOME}/${PROGRAM} ${START_ARGS}" >> ${LOG} 2>&1 &
/bin/echo "${NAME} will be up shortly..."
/bin/sleep 5
PID_VALIDATE=`/bin/ps -ef | grep "${PROGRAM}" | grep -v "grep" | awk '{print $2}'`
if [ ${PID_VALIDATE} ]
then
/bin/echo "${NAME} is now running"
else
/bin/echo "${NAME} failed to start - Please check ${LOG} for more information"
fi
fi
}
function stop {
/bin/echo "Stopping ${NAME}..."
PID=`/bin/ps -ef | grep "${PROGRAM}" | grep -v "grep" | awk '{print $2}'`
if [ ${PID} ]
then
/bin/echo "${NAME} is stopping.."
/bin/su ${USER} -c "/bin/kill -15 ${PID}" >> ${LOG} 2>&1 &
MAX_TRIES=$((WAIT_TIME/5))
while [ true ]; do
if [ -z ${PID} ]
then
/bin/echo "Stopped ${NAME}"
break;
fi
/bin/echo "."
((tries ++))
if [ ${tries} -ge ${MAX_TRIES} ]
then
/bin/echo "Process not responding..."
/bin/echo "Killing process..."
/bin/kill -9 ${PID}
fi
/bin/sleep 5;
PID=`/bin/ps -ef | grep "${PROGRAM}" | grep -v "grep" | awk '{print $2}'`
done;
else
/bin/echo "${NAME} is not running"
fi
}
function status {
PID=`/bin/ps -ef | grep "${PROGRAM}" | grep -v "grep" | awk '{print $2}'`
if [ ${PID} ]
then
/bin/echo "${NAME} is running"
else
/bin/echo "${NAME} is not running"
fi
}
case $1 in
start)
start
;;
restart)
stop
start
;;
status)
status
;;
stop)
stop
;;
esac