zoukankan      html  css  js  c++  java
  • Supervisor服务开机自启动

    要解决的问题

    在机器上部署自己编写的服务时候,我们可以使用Supervisor作为进程检活工具,用来自动重启服务。
    但是当机器重启后,Supervisor却不能自动重启,那么谁来解决这个问题呢?

    答案就是linux的service。

    总体思路

    编写一个脚本,然后把它放在/etc/init.d这个目录下,再用service + 脚本名字 运行即可。如果是要开机自动启动那就得用chkconfig命令了。

    话不多说,上手做吧!

    安装方法

    增加service配置

    [root@hdx9whvy init.d]# vim /etc/init.d/supervisor
    

    内容为

    #!/bin/bash
    #
    # supervisord   This scripts turns supervisord on
    #
    # Author:       Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
    #
    # chkconfig:    - 95 04
    #
    # description:  supervisor is a process control utility.  It has a web based
    #               xmlrpc interface as well as a few other nifty features.
    # processname:  supervisord
    # config: /etc/supervisor/supervisord.conf
    # pidfile: /var/run/supervisord.pid
    #
    
    # source function library
    . /etc/rc.d/init.d/functions
    
    RETVAL=0
    
    start() {
        echo -n $"Starting supervisord: "
        daemon "/usr/bin/supervisord -c /etc/supervisord.conf"
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord
    }
    
    stop() {
        echo -n $"Stopping supervisord: "
        killproc supervisord
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/supervisord
    }
    
    restart() {
        stop
        start
    }
    
    case "$1" in
      start)
        start
        ;;
      stop) 
        stop
        ;;
      restart|force-reload|reload)
        restart
        ;;
      condrestart)
        [ -f /var/lock/subsys/supervisord ] && restart
        ;;
      status)
        status supervisord
        RETVAL=$?
        ;;
      *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
        exit 1
    esac
    
    exit $RETVAL
    

    设置脚本为可执行

    [root@hdx9whvy init.d]# chmod +x /etc/init.d/supervisor
    

    设置服务开机启动

    • service这个命令往往是即时生效,不用开关机,但是重启后服务会回到默认状态。
    • chkconfig是用于把服务加到开机自动启动列表里,只要启动它,就能自动启动,重启后永久生效
    [root@hdx9whvy init.d]# chkconfig supervisor on
    

    启停命令

    [root@hdx9whvy init.d]# service supervisor start
    Starting supervisord:                                      [  OK  ]
    
    [root@hdx9whvy init.d]# service supervisor stop
    Stopping supervisord:                                      [  OK  ]
    
    [root@hdx9whvy ~]# service supervisor restart
    Stopping supervisord:                                      [  OK  ]
    Starting supervisord:                                      [  OK  ]
    
  • 相关阅读:
    【leetcode】Binary Search Tree Iterator
    【leetcode】Palindrome Partitioning II
    【leetcode】Best Time to Buy and Sell Stock III
    【leetcode】Best Time to Buy and Sell Stock II
    【leetcode】Longest Consecutive Sequence
    【leetcode】Factorial Trailing Zeroes
    【leetcode】Simplify Path
    【leetcode】Generate Parentheses
    【leetcode】Combination Sum II
    【leetcode】Combination Sum
  • 原文地址:https://www.cnblogs.com/laolieren/p/restart_supervisor_when_reboot_system.html
Copyright © 2011-2022 走看看