HPUX自定义service,/sbin/init.d/template示例

在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 <specific> 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 <specific> 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
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(66) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值