Chinaunix首页 | 论坛 | 博客
  • 博客访问: 152728
  • 博文数量: 29
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 286
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-24 21:51
文章分类

全部博文(29)

文章存档

2015年(4)

2014年(25)

我的朋友

分类: 服务器与存储

2014-07-17 13:52:01

在HPUX上配置一个自定义的服务,用于init.d启动和停止一项服务,以下过程是配置一个简单的ping服务的启动和停止的过程。

  1. Make a copy of the /sbin/init.d/template template file to use as a template for your pinger startup script.
    # cp /sbin/init.d/template /sbin/init.d/pinger
  2. Use your editor of choice to customize the new startup script.

# vi /sbin/init.d/pinger

  1. Scroll down to the case statement towards the middle of the script. Look for 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 subsystem"

;;

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"

;;

  1. Scroll down to the stop_msg portion of the case statement that looks like this:

'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 subsystem"

;;

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"

;;

  1. Scroll down to the start argument in the case statement that looks like this:

# 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

;;

  1. Next, scroll down to the stop argument in the case statement that looks like this:

# 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

;;

  1. Save your changes to /sbin/init.d/pinger and quit.
  1. Create a configuration file and a control variable for your new startup script:

# vi /etc/rc.config.d/pinger

PINGER=1

  1. Create a start link to start the new service at run level 3 using the “don’t care” 900 sequence number, and a kill link to kill the new service with sequence number 100 at run level 2:

# ln –s /sbin/init.d/pinger /sbin/rc3.d/S900pinger

# ln –s /sbin/init.d/pinger /sbin/rc2.d/K100pinger

  1. Test your new startup script by executing both the start and kill links.

# /sbin/rc3.d/S900pinger start

# ps –ef | grep ping

# /sbin/rc2.d/K100pinger stop

# ps –ef | grep ping

  1. Assuming the previous test succeeded, change run levels a few times to further test your scripts.

# init 2

# init 3

# init 2

  1. Disable the the pinger service in /etc/rc.config.d/pinger.
    # vi /etc/rc.config.d/pinger
    PINGER=0
  2. Return to run level 3 before proceeding to the next lab.
    # init 3
阅读(2415) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~