How to add Apache and Nginx to the system service, with service command to control the start, stop

Source: Internet
Author: User

1 Add Apache to the system service, that is, the service command to control Apache start, stop

If HTTPD is installed by default on a Linux server (viewed with Rpm-qa|grep httpd), you can use the build to overwrite the/ETC/INIT.D/HTTPD

If it is not installed, then the following method

# grep-v "#"/usr/local/apache2/bin/apachectl >/etc/init.d/httpd

Then use VI to edit the Apache service control script/etc/init.d/httpd

Insert the following line at the front of the file so that it supports the Chkconfig command:

Divider line *************************** #!/bin/sh # chkconfig:2345 # Description:apache I     S a world Wide Web server. ***************************************************

After saving Exit VI Editor, execute the following command to increase the HTTPD service control script execution permissions

# chmod 755/ETC/INIT.D/HTTPD

Execute the following command to join the Apache service to the system service

# chkconfig--add httpd

Execute the following command to check if the Apache service is in effect:

# chkconfig--list httpd

httpd 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off

Indicates that Apache starts automatically with the system boot at 2, 3, 4, 5 runlevel, and can then use service to control httpd start or stop


2 Add Nginx to the system service, that is, the service command to control the Nginx start, stop

Drop-down editor/etc/rc.d/init.d/nginx

# Vi/etc/rc.d/init.d/nginx

=======================================================#!/bin/bash# nginx startup script  For the nginx http server# it is v.0.0.2 version.# chkconfig:  - 85 15# description: nginx is a high-performance web and  proxy server.#               It has a lot of features, but it ' s not for everyone.#  processname: nginx# pidfile: /var/run/nginx.pid# config: /usr/local/nginx/conf/ nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/ Nginx/logs/nginx.pidretval=0prog= "Nginx" # source function library.   /etc/rc.d/init.d/functions# source networking configuration.   /etc/sysconfig/network# check that networking&nbSp;is up. [ ${networking} =  "No"  ] && exit 0[ -x  $nginxd  ]  | |  exit 0# start nginx daemons functions.start ()  {if [ -e $ nginx_pid ];then   echo  "Nginx already running ..."    exit  1fi   echo -n $ "starting  $prog: "    daemon $ nginxd -c ${nginx_config}   retval=$?   echo   [ $ Retval = 0 ] && touch /var/lock/subsys/nginx   return   $RETVAL}# stop nginx daemons functions.stop ()  {         echo -n $ "stopping  $prog: "          killproc  $nginxd         RETVAL=$?         echo        [  $RETVAL  = 0 ] & & rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid}reload ()  {     echo -n $ "reloading  $prog: "      #kill  -hup   ' Cat ${nginx_pid} '     killproc  $nginxd  -HUP     retval=$?    echo}# see how we were called.case  "$"   Instart)         start        ;; Stop)         stop        ;; Reload)         reload        ;; Restart)         stop         Start        ;; Status)         status  $prog          RETVAL=$?        ;; *)         echo $ "usage:  $prog  {start|stop|restart| RELOAD|STATUS|HELP} "        exit 1esacexit  $RETVAL ========== =============================================

: wq! Save Exit

chmod 775/etc/rc.d/init.d/nginx #给文件执行权限

Chkconfig Nginx on #设置开机启动

/etc/rc.d/init.d/nginx restart

Service Nginx Restart

This article is from "Operation and maintenance record Mei Ling" blog, please be sure to keep this source http://meiling.blog.51cto.com/6220221/1720428

How to add Apache and Nginx to the system service, with service command to control the start, stop

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.