日期:2014-05-16  浏览次数:20766 次

Linux自启动脚本编写(RH series)

这里以ASSP(Anti-Spam SMTP Proxy)为例,介绍下自启动脚本:

#!/bin/sh -e
# Start or stop ASSP
# chkconfig:345 89 17
# description: “Anti-Spam SMTP Proxy”
PATH=/bin:/usr/bin:/sbin:/usr/sbin

case “$1″ in

start)
echo -n “Starting the Anti-Spam SMTP Proxy”
cd /usr/share/assp
perl assp.pl
;;

stop)
echo -n “Stopping the Anti-Spam SMTP Proxy”
kill -9 `ps ax | grep “perl assp.pl” | grep -v grep | awk ‘{ print $1 }’`
;;

restart)
$0 stop || true
$0 start
;;

*)
echo “Usage: /etc/init.d/assp {start|stop|restart}”
exit 1
;;

esac

?

将这个文件保存在/etc/init.d/目录下,名字即为服务的名字,我这里的名字为assp

完了之后,运行

chkconfig –add assp

?

chkconfig –list| grep assp

?

看一下是否存在。这样就建好自启动了。

下面简单介绍下脚本文件。

第三行:哪些Linux 级别需要启动httpd(3,4,5),启动序号(89),关闭序号(17)。第四行是服务描述。