Linux Service Management Custom scripts

Source: Internet
Author: User

Need to start multiple MySQL instances on the server today

The new MySQL instance can not be managed with mysqld_multi, so it has customized a mysql_3307 service, with service management



You can look at the service code, which are simple shell scripts.

The principle of service is to go to/etc/init.d to find the corresponding service script, and then invoke the script, the service's second parameter is passed to the invocation of the services as the first parameter

Therefore, you can write a script under/ETC/INIT.D, define the corresponding start,stop,status in the script, or you can add some other actions on your own, and you can add an execution permission.



Here is my mysql_3307 definition script:

Start () {n=$ (netstat -ntlp |grep 3307|grep -v  "grep 3307" |wc -l) if [   $n  -ne 0 ];then  echo  "server is already running!"   exit 0fimysqld_multi --defaults-extra-file=/etc/my_3307.cnf --user=root start  3307if [ $? -eq 0 ];then echo  "Service mysql_3307 start  successful  "else echo " Service mysql_3307 start fail "Fi}stop () {n=$ (netstat  -ntlp |grep 3307|grep -v  "grep 3307" |wc -l) if [  $n  -eq  0 ];then  echo  "server is not running!" fimysqld_multi --defaults-extra-file=/etc/my_3307.cnf --user=root stop 3307if [  $? -eq 0 ];then echo  "service mysql_3307 stop successful " Else  echo  "Service mysql_3307 stop fail" Fi}sTatus () {ps -ef |grep 3307|grep -v  "grep 3307"}case $1 instart)   start;; Stop)  stop;; Status)  status;; *) echo  ' service accept arguments start|stop|status ' Esac


This article is from the "Epimetheus" blog, make sure to keep this source http://epime.blog.51cto.com/10727900/1696546

Linux Service Management Custom scripts

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.