分类: 服务器与存储
2014-07-17 13:52:01
在HPUX上配置一个自定义的服务,用于init.d启动和停止一项服务,以下过程是配置一个简单的ping服务的启动和停止的过程。
# vi /sbin/init.d/pinger
'start_msg')
# Emit a _short_ message relating to running this script # with the "start" argument; this message appears as part # of the checklist.
echo "Starting the
;;
Change the echo statement to the following:
'start_msg')
# Emit a _short_ message relating to running this script
# with the "start" argument; this message appears as part
# of the checklist.
echo "Starting the pinger subsystem"
;;
'stop_msg')
# Emit a _short_ message relating to running this script
# with the "stop" argument; this message appears as part
# of the checklist.
echo "Stopping the
;;
Change the echo statement to the following:
'stop_msg')
# Emit a _short_ message relating to running this script
# with the "stop" argument; this message appears as part
# of the checklist.
echo "Stopping the pinger subsystem"
;;
# Check to see if this script is allowed to run...
if [ "$CONTROL_VARIABLE" != 1 ]; then
rval=2
else
# Execute the commands to start your subsystem
:
fi
;;
Change the CONTROL_VARIABLE, and add the command necessary to start the ping command in the background as shown below. Also add a call to the set_return function to notify /sbin/rc if the daemon successfully starts:
# Check to see if this script is allowed to run...
if [ "$PINGER" != 1 ]; then
rval=2
else
# Execute the commands to start your subsystem
/usr/sbin/ping localhost >/dev/null &
set_return
:
fi
;;
# Check to see if this script is allowed to run...
if [ "$CONTROL_VARIABLE" != 1 ]; then
rval=2
else
:
# Execute the commands to stop your subsystem
fi
;;
Change the CONTROL_VARIABLE, and add the command necessary to kill the ping command as shown below. Many applications include a command that may be used to shutdown the application. Otherwise, use the kill and ps commands as shown here. In this case, we’re using the ps –C and –o options to obtain the PID of the process currently running the ping command. The –C and –o options only work if the UNIX95 variable has been defined to enable special XPG4 options on the ps command. See the ps(1) man page for more information. Add a call to the set_return function to notify /sbin/rc if the daemon successfully starts:
# Check to see if this script is allowed to run...
if [ "$PINGER" != 1 ]; then
rval=2
else
:
# Execute the commands to stop your subsystem
kill $(UNIX95=true ps -o pid= -C “ping”)
set_return
fi
;;
# vi /etc/rc.config.d/pinger
PINGER=1
# ln –s /sbin/init.d/pinger /sbin/rc3.d/S900pinger
# ln –s /sbin/init.d/pinger /sbin/rc2.d/K100pinger
# /sbin/rc3.d/S900pinger start
# ps –ef | grep ping
# /sbin/rc2.d/K100pinger stop
# ps –ef | grep ping
# init 2
# init 3
# init 2