zl程序教程

您现在的位置是:首页 >  系统

当前栏目

Linux_自制系统服务启动脚本

Linux系统服务 启动 脚本 自制
2023-09-27 14:29:20 时间
#/bin/bash -e 表示系统发生第一个错误时就中止脚本执行 #每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。 # chkconfig:35 12 45 #第一行告诉chkconfig缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用 – 代替运行级。 # description:Service start script #第二行对服务进行描述,可以用\ 跨行注释。 RETVAL=0 case $1 in start) echo "service starting..." stop) echo "service stopping..." restart) #$0 meating is this one script sh $0 stop || true # $0 stop || ture 表示出现错误时候不想中止的指令 sh $0 start echo "input syntax error!" echo "Usage:Is [start|stop|restart]" exit 1 echo $RETVAL ###################################SCRIPT END Apache 启动脚本
[ -f /etc/rc.d/init.d/functions ] . /etc/rc.d/init.d/functions RETVAL=0 #使用变量作为判断和关联上下本的载体 httpd="/application/apache/bin/httpd" #使用变量简化使用指令的决定路径 start() { $httpd -k start /dev/null 2 1 #httpd -k start|restart|graceful|stop|graceful-stop 发送信号使httpd启动、重新启动或停止 # daemon httpd /dev/null 2 1 # 2 1 将错误输出到正确输出,即标准输出和错误输出一起输出,管道|不通过错误输出 RETVAL=$? [ $RETVAL -eq 0 ] action "启动 httpd:" /bin/true ||\ action "启动 httpd:" /bin/false return $RETVAL stop() { $httpd -k stop /dev/null 2 1 # killproc httpd /dev/null 2 1 [ $? -eq 0 ] action "停止 httpd:" /bin/true ||\ action "停止 httpd:" /bin/false return $RETVAL case "$1" in start) start #Call function start() stop) stop restart) sh $0 stop sh $0 start echo "Format error!" echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit $RETVAL ####################################### SCRIPT END Postfix service 启停脚本