自定义服务启动脚本

Redhat 装软件通常会带有服务启动的脚本,若是遇到一些软件或者程序须要源码安装则须要,本身编写软件服务的启动程序shell

1,自定义编写apache的apache

[root@IBM rc5.d]# cat /etc/init.d/Apache
#!/bin/bash
#下面注释对自己的shell没什么做用,可是对checkconfig这个程序会读取这个注释,- 是默认值,任何级别都不开,能够设置成2345,
#chkconfig: - 80 90
file=/var/run/httpd/httpd.pid
start(){
    if [ ! -f $file ];then
        /usr/sbin/httpd
        echo "httpd 正在运行"
    else
        echo "已经启动过了"
    fi
}
stop(){
    if [ -f $file ];then
        kill `cat $file`
        echo "httpd 正在中止"
    else
        echo "已经中止了"  
    fibash

}函数

case $1 in
start)
    start;;
stop)
    stop;;
restart)
    kill `cat $file`
    echo "httpd 正在中止"
    sleep 1
    /usr/sbin/httpd
    echo "httpd 正在启动";;
status)
    if [ -f $file ];then
        echo "Aapche 正在运行"
    else
        echo "Apache 没有运行"
    fi;;
*)
    echo "usage: {start|stop|status}";;
esac.net


#重复的代码能够作成一个函数,直接掉rest

相关文章
相关标签/搜索