Skip to content

Commit fb7c185

Browse files
committed
added dac init.d script, still in development
1 parent cd4a088 commit fb7c185

File tree

1 file changed

+347
-0
lines changed
  • Oracle Scripts/DAC/init.d

1 file changed

+347
-0
lines changed

Oracle Scripts/DAC/init.d/dac

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
#!/bin/bash
2+
# chkconfig: 345 96 20
3+
# description: Control infamatica process
4+
#
5+
# File: /etc/init.d/informatica
6+
# Purpose: Start and stop the Informatica server
7+
# Author: bthompso (Conundrum)
8+
# Date: 3/11/2014
9+
#
10+
# Absolutely no warranty, use at your own risk
11+
# Please include this header in any copy or reuse of the script you make
12+
#
13+
# Version 0.01
14+
#
15+
# Usage:
16+
# 1: Create file at /etc/init.d/informatica
17+
# 2: chmod 750 /etc/init.d/informatica
18+
# 3: chkconfig --add informatica
19+
#
20+
#------------------------------------
21+
#
22+
# The following values must be changed for your environment
23+
#
24+
25+
# full path to the infaservice.sh file
26+
DAC_HOME=/APPS/dac
27+
# log file path, change if you don't want logs to go to /var/log
28+
LOG_PATH=/var/log
29+
30+
# the following variables should not need modification
31+
SUBSYS=$(basename $0)
32+
DAC_FINGERPRINT='com.siebel.etl.net.QServer'
33+
START_TIMEOUT=300
34+
STOP_TIMEOUT=300
35+
LOCK_FILE='/var/lock/subsys/'$SUBSYS
36+
START_LOG=$LOG_PATH/$SUBSYS-start.log
37+
STOP_LOG=$LOG_PATH/$SUBSYS-stop.log
38+
LSOF_PATH=/usr/sbin/lsof
39+
ORACLE_OWNR=oracle
40+
# source the functions library
41+
#-----------------------
42+
if [ -f /etc/rc.d/init.d/functions ]; then
43+
. /etc/rc.d/init.d/functions
44+
fi
45+
#-----------------------
46+
47+
# check paths and permissions
48+
if [ ! -f $DAC_HOME/config.sh ] ; then
49+
echo ''
50+
echo -n "**config.sh file not found at $DAC_HOME/config.sh"
51+
echo_failure
52+
echo ''
53+
fi
54+
55+
if [ ! -f $DAC_HOME/startserver.sh ] ; then
56+
echo ''
57+
echo -n "**startserver.sh file not found at $DAC_HOME/startserver.sh"
58+
echo_failure
59+
echo ''
60+
fi
61+
62+
if [ ! -f $DAC_HOME/stopserver.sh ] ; then
63+
echo ''
64+
echo -n "**stopserver.sh file not found at $DAC_HOME/stopserver.sh"
65+
echo ''
66+
fi
67+
68+
#source the config.sh script
69+
. $DAC_HOME/config.sh
70+
71+
72+
check_permissions() {
73+
abort=0
74+
75+
#check lock file
76+
if [ ! -f $LOCK_FILE ] ; then
77+
if [ $(touch $LOCK_FILE 2>&1 | grep "Permission denied" | wc -l) -ne 0 ]; then
78+
echo ''
79+
echo '** Lock file '$LOCK_FILE' is not writable by '$(whoami)' **'
80+
echo_failure
81+
echo ''
82+
abort=1
83+
fi
84+
else
85+
if [ ! -w $LOCK_FILE ]; then
86+
echo ''
87+
echo '** Lock file '$LOCK_FILE' is not writable by '$(whoami)' **'
88+
echo ''
89+
abort=1
90+
fi
91+
fi
92+
93+
#check start log
94+
95+
if [ ! -f $START_LOG ]; then
96+
if [ $(touch $START_LOG 2>&1 | grep "Permission denied" | wc -l) -ne 0 ]; then
97+
echo ''
98+
echo '** Log file '$START_LOG' is not writable by '$(whoami)' **'
99+
echo_failure
100+
echo ''
101+
abort=1
102+
fi
103+
else
104+
if [ ! -w $START_LOG ]; then
105+
echo ''
106+
echo '** Log file '$START_LOG' is not writable by '$(whoami)' **'
107+
echo_failure
108+
echo ''
109+
abort=1
110+
fi
111+
fi
112+
113+
114+
#check stop log
115+
116+
if [ ! -f $STOP_LOG ]; then
117+
if [ $(touch $STOP_LOG 2>&1 | grep "Permission denied" | wc -l) -ne 0 ]; then
118+
echo ''
119+
echo '** Log file '$STOP_LOG' is not writable by '$(whoami)' **'
120+
echo_failure
121+
echo ''
122+
abort=1
123+
fi
124+
else
125+
if [ ! -w $STOP_LOG ]; then
126+
echo ''
127+
echo '** Log file '$STOP_LOG' is not writable by '$(whoami)' **'
128+
echo_failure
129+
echo ''
130+
abort=1
131+
fi
132+
fi
133+
134+
if [ $abort -eq 1 ]; then
135+
echo -e '\n\n------------------------\nTo start/stop this script must be run as root (directly, or with sudo)\n\n'
136+
exit 255
137+
fi
138+
}
139+
140+
#
141+
#--------------------
142+
#
143+
144+
check_process_ports () {
145+
# Pass the 'fingerprint' of the process to check, which should be a regex to uniquely
146+
# identify the process in a pgrep -f call
147+
#
148+
# Returns:
149+
# 0 - Process not running
150+
# 1 - Process running but not listening on any port
151+
# <ports> - the port(s) on which the process is listening
152+
PID=$(pgrep -f $1)
153+
if [ $? -eq 0 ] ; then
154+
PORT=$(pgrep -f $1|xargs -I'{}' $LSOF_PATH -nPp {}|grep LISTEN|awk -F ":" '{print $2}'|cut -d " " -f 1|sort -u|paste -s)
155+
if [ -n "$PORT" ] ; then
156+
echo $PORT
157+
else
158+
echo 1
159+
fi
160+
else
161+
echo 0
162+
fi
163+
}
164+
165+
166+
echo_process_status () {
167+
rc=$(check_process_ports $1)
168+
case "$rc" in
169+
0)
170+
echo_not_running
171+
;;
172+
1)
173+
echo_in_progress
174+
;;
175+
*)
176+
echo -n "listening on port" $rc
177+
echo_success
178+
esac
179+
echo ' '
180+
}
181+
182+
wait_to_die() {
183+
# check_process_ports will return 0 (not running), 1 (starting up) or other (port value)
184+
# This function will poll the process and based on the value returned (in rc) keep polling,
185+
# or after the predefined timeout period, kill the process by force.
186+
rc=999
187+
timeout=$2
188+
if [ -z $timeout ] ; then
189+
timeout=600
190+
fi
191+
# 30 is enough space on the line for the . to appear without overlapping the status message
192+
sleep_period=$(($timeout/30))
193+
[[ $sleep_period -eq 0 ]] && sleep_period=1
194+
fingerprint=$1
195+
starttime=$(date +%s)
196+
while [ "$rc" != "0" ]
197+
do
198+
rc=$(check_process_ports $fingerprint)
199+
nowtime=$(date +%s)
200+
timediff=$(( $nowtime - $starttime ))
201+
if [ $timediff -gt $timeout ] ; then
202+
echo_warning
203+
echo ''
204+
echo -e '\tTimed out after '$timeout' seconds'
205+
echo -en '\tSending SIGKILL. '
206+
pkill -SIGKILL -f $fingerprint
207+
sleep 5
208+
rc=$(check_process_ports $1)
209+
case "$rc" in
210+
0)
211+
echo -n 'Process killed'
212+
echo_success
213+
;;
214+
*)
215+
echo -n "Process still running"
216+
echo_failure
217+
esac
218+
echo ''
219+
return 1
220+
fi
221+
echo -n '.'
222+
if [ "$rc" != "0" ] ; then
223+
sleep $sleep_period
224+
fi
225+
done
226+
echo_success
227+
echo ''
228+
return 0
229+
}
230+
231+
wait_to_start() {
232+
# check_process_ports will return 0 (not running), 1 (starting up) or other (port value)
233+
# This function will poll the process and based on the value returned (in rc) keep polling,
234+
# or after the predefined timeout period, give up.
235+
rc=1
236+
timeout=$2
237+
if [ -z $timeout ] ; then
238+
timeout=600
239+
fi
240+
# 30 is enough space on the line for the . to appear without overlapping the status message
241+
sleep_period=$(($timeout/30))
242+
[[ $sleep_period -eq 0 ]] && sleep_period=1
243+
fingerprint=$1
244+
#echo 'Timeout: '$timeout ', Sleep period: '$sleep_period', Fingerprint: '$fingerprint
245+
starttime=$(date +%s)
246+
while [ "$rc" == "1" ]
247+
do
248+
sleep $sleep_period
249+
rc=$(check_process_ports $fingerprint)
250+
nowtime=$(date +%s)
251+
timediff=$(( $nowtime - $starttime ))
252+
if [ $timediff -gt $timeout ] ; then
253+
echo -n ' '
254+
echo -n ' (Timed out after '$timeout' seconds ) '
255+
break
256+
fi
257+
echo -n '.'
258+
done
259+
case "$rc" in
260+
0|1)
261+
echo_failure
262+
rc=255
263+
;;
264+
*)
265+
echo_success
266+
rc=0
267+
;;
268+
esac
269+
echo ''
270+
#echo '--'
271+
#echo $rc
272+
#echo '--'
273+
return $rc
274+
}
275+
276+
echo_not_running() {
277+
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
278+
echo -n "["
279+
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
280+
echo -n $"NOT RUNNING"
281+
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
282+
echo -n "]"
283+
echo -ne "\r"
284+
return 1
285+
}
286+
287+
echo_in_progress() {
288+
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
289+
echo -n "["
290+
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
291+
echo -n $"IN PROGRESS"
292+
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
293+
echo -n "]"
294+
echo -ne "\r"
295+
return 1
296+
}
297+
298+
start() {
299+
echo -en "\nStarting DAC Server"
300+
su $ORACLE_OWNR -c "$JAVA -server -Xms256m -Xmx800m -cp $DACCLASSPATH com.siebel.etl.net.QServer" > $START_LOG 2>&1 &
301+
wait_to_start $DAC_FINGERPRINT $START_TIMEOUT
302+
}
303+
304+
stop () {
305+
echo -en "\nStopping DAC Server"
306+
su $ORACLE_OWNR -c "$JAVA -cp $DACCLASSPATH com.siebel.etl.bootup.DAWUtils TERMINATE" > $STOP_LOG 2>&1 &
307+
wait_to_die $DAC_FINGERPRINT $STOP_TIMEOUT
308+
}
309+
310+
311+
312+
status () {
313+
echo ''
314+
echo -n ' Checking DAC Server: '
315+
echo_process_status $DAC_FINGERPRINT
316+
}
317+
318+
319+
case $1 in
320+
status)
321+
status
322+
;;
323+
start)
324+
check_permissions
325+
start
326+
echo ''
327+
touch $LOCK_FILE
328+
;;
329+
stop)
330+
check_permissions
331+
stop
332+
rm -f $LOCK_fILE
333+
;;
334+
restart)
335+
check_permissions
336+
stop
337+
start
338+
;;
339+
*)
340+
echo "Usage: $(basename $0) start|stop|restart|status"
341+
;;
342+
esac
343+
344+
345+
346+
347+

0 commit comments

Comments
 (0)