Write a service script under CentOS 5,6

Source: Internet
Author: User

Overview : CentOS 5 and 6 under the service start, the use of the command is the service name start mode start, in fact, the service command is also called the script under/etc/init.d/, see the specific steps below

Experimental steps:

first prepare the service script, the following piece of code is I wrote earlier, it is similar to the parameters we accept when the service starts, and then returns the output content according to the parameters you entered .

[[Email protected] ~]# vim testsrv #!/bin/bash#function: script test#author : xiaoshui#[ -z $1 ] && echo  "Empty"  &&exitdir= ' Basename $0 ' dir= "/var/lock/subsys/$dir" var= ' echo $1 | tr  ' A-Z '   ' A-Z ' case $ Var instart)         if [ ! -e  "$Dir"  ]; Then                touch   $Dir  && echo  "$dir  start success"          else                 echo  "$dir  already start"         fi         ;; Stop)         if [ ! -e  "$Dir"  ];then                echo  "$dir  is not start "        else                 rm -f  $Dir  &&  echo  "$dir  stop success"         fi         ;; Restart)         if [ ! -e  "$Dir"  ];then                 echo  "$dir  not start "                 touch  $Dir  && echo  "$dir  restart success"          else                rm  $Dir  && echo  "$dir  stopped"                  touch  $Dir  &&  echo  "$dir  restart success"         fi         ;; Status)         if [ ! -e  "$Dir"  ];then                 echo  "$dir  is stopped "         else                 echo  "$dir  is running"          fi        ;; *)         echo  "argues error,please input start|Restart|stop|status "        ;; Esac

The first step: Copy the script to the/etc/init.d/directory and add a line under the previous #!/bin/bash #chkconfig:35 12 88

[Email protected] ~]# vim/etc/init.d/testsrv #!/bin/bash#function:script test#chkconfig:35 88#description:test ser Vice#author:xiaoshui

In addition, the meaning of this content is that 35 indicates the initial level under which to start,-the default is not to start 12 88 means that it represents/etc/rc.d/rc#.d/below the large head of K and S file, which means the priority of the start.

Step Two: Chkconfig--add service adds the service to the Chkconfig list

[Email protected] rc.d]# chkconfig--add testsrv[[email protected] rc.d]# chkconfig--list ... To omit ... testsrv 0:off 1:off 2:off 3:on 4:off 5:on 6:off ..... Omitted.....

Step three: Test with the service command

[[Email protected] rc.d]# service testsrv starttestsrv start Success[[email protected] rc.d]# service Testsrv stoptestsrv Stop Success[[email protected] rc.d]# service testsrv restarttestsrv not starttestsrv restart Success[[email protected] RC  . d]# Service Testsrv Statustestsrv is running[[email protected] rc.d]# service testsrv statfsdfsfargues error,please input Start|restart|stop|status



This article is from the "Endless Learning" blog, please be sure to keep this source http://dashui.blog.51cto.com/11254923/1851747

Write a service script under CentOS 5,6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.