在redhat下面添加服务应该还算是比较简单的吧,只需要几个简单的命令即可。还是直接看脚本吧。
#!/bin/bash
#chkconfig: 2345 80 90
#description:testservice
# Source function library.
. /etc/rc.d/init.d/functions
echo "hello agent" >>/root/boco.log
echo "now is `date +%Y-%m-%d-%H-%M-%S`!" >> /root/boco.log
logfile="/root/boco.log"
start(){
echo "invoke start command now is `date +%Y-%m-%d-%H-%M-%S`!" >> $logfile
}
stop(){
echo "invoke stop command now is `date +%Y-%m-%d-%H-%M-%S`!" >> $logfile
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo "invoke restart command now is `date +%Y-%m-%d-%H-%M-%S`!" >> $logfile
stop
start
;;
*)
echo "usage: $0 {start|stop|restart|status}"
esac
有了脚本,就把此脚本放在/etc/init.d/下面,执行下面命令
chkconfig --list 列出所有服务
chkconfig [--level [012345]] [服务名称] [on|off]
chkconfig --add 服务名称 (必须放到/etc/init.d/ 下面)
chkconfig --del 服务名称