给源码服务写启动脚本

简介:

给源码服务写启动脚本


给源码包httpd写启动脚本,可以启动、停止、查看状态


第一步:编辑脚本文件

[root@server2 ~]# cat apache.sh

start(){

      `/usr/local/apache2/bin/apachectl start &> /dev/null`

       if [ $?-eq 0 ];then

              echo "start the httpd server ......     [ok]"

       else

              echo "start faild ... "

       fi

}


stop(){                            //停止服务

      `/usr/local/apache2/bin/apachectl stop &> /dev/null`

       if [ $?-eq 0 ];then

              echo "stop the httpd server ......      [ok]"

       else

              echo "stop faild ... "

       fi

}


status(){                             //查看状态,根据是否开启80端口查看

       j=`netstat-tunlp | grep :80 | wc -l`

       if [ $j-eq 0 ];then

              echo "httpd server is stoped ... "

       else

              echo "httpd server is running ..."

       fi

}


case $1 in

start)

       start;;

stop)

       stop;;

status)

       status;;

*)

       echo"$0 values in { stop | start | status } , please again !"

esac

[root@server2 ~]#


第二步:将脚本移动到/etc/init.d目录下并重命名为apache,并添加x权限


[root@server2 ~]# mv apache.sh /etc/init.d/apache

[root@server2 ~]# chmod +x /etc/init.d/apache


第三步:为/etc/init.d/apache添加下列两行


# chkconfig: 2345 55 25               //指定运行级别、启动服务的优先级、关闭服务的优先级

# description: httpd server daemon             //指定服务的描述信息


第四步:使用chkconfig --add将apache添加为系统服务


[root@server2 ~]# chkconfig --add /etc/init.d/apache

[root@server2 ~]# chkconfig --list | grep apache

apache          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

[root@server2 ~]# service apache stop

stop the httpd server ......      [ok]

[root@server2 ~]# service apache status

httpd server is stoped ...

[root@server2 ~]# service apache start

start the httpd server ......     [ok]

[root@server2 ~]# service apache status

httpd server is running ...

[root@server2 ~]#




本文转自 murongqingqqq  51CTO博客,原文链接:http://blog.51cto.com/murongqingqqq/1385616
相关文章
|
Java 应用服务中间件 Windows
Tomcat安装与启动和配置
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选,对于一个初学者来说;
278 0
|
Java
配置java环境变量的几种方法
配置java环境变量的几种方法
58 0
|
Shell
项目的启动脚本
项目的启动脚本
92 0
|
关系型数据库 MySQL 应用服务中间件
|
JavaScript 应用服务中间件 nginx