We need some applications should be stopped and started gracefully without manual intervention during the reboots . Order to serve this purpose , we use rc scripts in all unix flavors including AIX .
So, how do rc.scripts work:
- Write a single script, put it into /etc/rc.d/init.d, make sure the script accepts a single parameter of start or stop and does the right thing.
- In /etc/rc.d/rc2.d create a link (ln -s) to the script in init.d called Sxxname where xx is a number that dictates where in comparison to other scripts in the directory your script will execute (lower number first).
- In /etc/rc.d/rc2.d create a link to the script in init.d called Kxxname where xx is a number which dictates when the script is run to stop your app in comparison to other scripts in the directory (lower number first).
Note: Its just convention to place scripts in /etc/rc.d/init.d and make soft links in /etc/rc.d/rc2.d. But its need not mandatory to keep scripts in /etc/rc.d/init.d.
Example RC Script:
#!/usr/bin/ksh
ulimit -c 0
case "$1" in
start )
ps -ef | grep -v grep | grep myengine > /dev/null
ret=$?
if [ $ret -gt 0 ]; then
/var/myengine/bin/startup.sh
fi
;;
stop )
PID=$$
for i in myengine-app1 myengine-app2 myengine-app3 myengine-app4; do
ps -ef | grep $i | grep -v grep | awk '{print $2}' >> /tmp/myengine.$PID
done
while read line; do
kill $line
done < /tmp/myengine.$PID
rm /tmp/myengine.$PID
;;
* )
echo "Usage: $0 (start | stop)"
exit 1
esac
ulimit -c 0
case "$1" in
start )
ps -ef | grep -v grep | grep myengine > /dev/null
ret=$?
if [ $ret -gt 0 ]; then
/var/myengine/bin/startup.sh
fi
;;
stop )
PID=$$
for i in myengine-app1 myengine-app2 myengine-app3 myengine-app4; do
ps -ef | grep $i | grep -v grep | awk '{print $2}' >> /tmp/myengine.$PID
done
while read line; do
kill $line
done < /tmp/myengine.$PID
rm /tmp/myengine.$PID
;;
* )
echo "Usage: $0 (start | stop)"
exit 1
esac
Example Creating Symbolic Links
This is an example on creating symbolic links for automatic startup for tivoli. tivoli should start first (meaning a low Sxx) and stop last (meaning a high Kxx):
umadmin@umserve1:/etc/rc.d/rc2.d>sudo ln -s /etc/rc.d/init.d/rc.tivoli S20tivoli
umadmin@umserve1:/etc/rc.d/rc2.d>sudo ln -s /etc/rc.d/init.d/rc.tivoli K70tivoli
umadmin@umserve1:/etc/rc.d/rc2.d>sudo ln -s /etc/rc.d/init.d/rc.tivoli K70tivoli
0 blogger-disqus:
Post a Comment