#!/bin/bash
. /etc/rc.d/init.d/functions
RETVAL=0
progdir="/usr/bin/"
prog="nc"
start(){
# Start daemons.
if [ -n "`/sbin/pidof $prog`" ]; then
echo -n "$prog: already running"
failure $"$prog start"
echo
return 1
fi
echo -n $"Starting $prog: "
# we can't seem to use daemon here - emulate its functionality
RETVAL=$?
usleep 10000
if [ -z "`/sbin/pidof $progdir$prog`" ]; then
# The child processes have died after fork()ing, e.g.
# because of a broken config file
RETVAL=1
fi
RETVAL=0
[ $RETVAL -ne 0 ] && failure $"$prog -l -p 8883"
[ $RETVAL -eq 0 ] && success $"$prog -l -p 8883"
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
RETVAL=$?
[ $RETVAL -ne 0 ] && failure $"$prog -l"
[ $RETVAL -eq 0 ] && success
echo
return $RETVAL
}
restart() {
start
stop
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
restart;;
*)
echo $0 "(start|stop|restart)"
exit 1
esac
exit $?
这个脚本是参考 zabbix 的启动脚本
脚本 主要 引用了. /etc/rc.d/init.d/functions
呵呵
多多学习Linux,多酷的效果呀
注: echo -n $"Stopping $prog: " 中 Stopping Starting 能根据你的系统的语言改变
success failure 效果是在后面的[]显示 哈哈
阅读(1285) | 评论(0) | 转发(0) |