zoukankan      html  css  js  c++  java
  • mac下supervisor安装及简单配置

    supervisor是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(守护进程)。可以用他来管理自己的“服务程序”。

    安装

    首先安装Python,Mac系统好像自带。

    执行 sudo pip install supervisor 安装

    安装pip

    下载get-pip.py,然后执行。具体请查看文档

    $ wget https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
    ...
    $ sudo python get-pip.py
    

    配置

    使用默认配置项

    $ sudo echo_supervisord_conf > /etc/supervisord.conf
    $ sudo vim /etc/supervisord.conf
    

    其他可以暂时忽略,修改最底下一行

    ; 包含其他的配置文件
    [include]
    files = /etc/supervisor/*.conf    ; 可以随意指定,目录不存在请先建立。配置文件可以是 *.conf 或 *.ini
    

    测试一下

    supervisord -c /etc/supervisord.conf
    ps aux | grep supervisord
    

    配置“服务”

    这里我用“IDEA License Server”做示例

    sudo vim /etc/supervisor/idea.conf
    

    文件内容

    [program:idea]                          ; 是应用程序的唯一标识,不能重复
    directory = /data/jidea-server          ; 程序的启动目录
    command = /data/jidea-server/IntelliJIDEALicenseServer_darwin_amd64 ; 启动命令
    autostart = true                        ; 在 supervisord 启动的时候也自动启动
    startsecs = 5                           ; 启动 5 秒后没有异常退出,就当作已经正常启动了
    autorestart = true                      ; 程序异常退出后自动重启
    startretries = 3                        ; 启动失败自动重试次数,默认是 3
    redirect_stderr = true                  ; 把 stderr 重定向到 stdout,默认 false
    stdout_logfile_maxbytes = 20MB
    stdout_logfile_backups = 20
    stdout_logfile = /var/log/supervusor/jidea-server.log   ; stdout 日志文件,注意:要确保目录已经建立并且可以访问(写权限)
    

    使用命令supervisorctl -c /etc/supervisord.conf加装并启动。如果一切正常可以使用命令supervisorctl status查看状态。例如:

    $ supervisorctl status
    idea                            RUNNING   pid 1177, uptime 0:32:00
    $ 
    

    以上输出表示一起正常,如果有错误,请“具体情况具体分析”本文档暂不做相关讨论。

    使用 launchctl 来启动 supervisor 自身

    launchctl是Mac自带的工具,具体使用方法请看官方文档或者问度娘。
    这里我在 /Library/LaunchAgents 目录下, 创建一个 supervisord.plist 文件, 命令:sudo vim /Library/LaunchDaemons/supervisord.plist,内容如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>KeepAlive</key>
        <dict>
            <key>SuccessfulExit</key>
            <false/>
        </dict>
        <key>Label</key>
        <string>supervisord</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/supervisord</string>
            <string>-n</string>
            <string>-c</string>
            <string>/etc/supervisord.conf</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
    </plist>
    

    注意:检查文件的权限

    $ ls -lsa /Library/LaunchDaemons
    total 24
    0 drwxr-xr-x   5 root  wheel   170 11 22 09:44 .
    0 drwxr-xr-x+ 67 root  wheel  2278 11 16 14:41 ..
    8 -rw-r--r--   1 root  wheel   590 11 16 17:52 supervisord.plist
    

    supervisord.plist必须是属于root用户的。不是的话修改:sudo chown root:wheel /Library/LaunchDaemons/supervisord.plist。最后启动他

    sudo launchctl load /Library/LaunchDaemons/supervisord.plist
    

    注意,在启动前先检查一下supervisord时不时已经在运行了,如果已经运行请先kill掉。

    注意: 必须在这个目录(/Library/LaunchDaemons)下才会使用root启动。

    $ ps aux | grep supervisord
    user              1167   0.0  0.2  4304600  15744   ??  Ss    9:52上午   0:00.51 /usr/bin/python /usr/local/bin/supervisord -n -c /etc/supervisord.conf
    $ kill -4 1167
    
     


    作者:xBei
    链接:https://www.jianshu.com/p/050273859836
    來源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
  • 相关阅读:
    HDU 1025 Constructing Roads In JGShining's Kingdom (DP+二分)
    HDU 1158 Employment Planning
    HDU 2059 龟兔赛跑
    Csharp 简单操作Word模板文件
    Csharp windowform datagridview Clipboard TO EXCEL OR FROM EXCEL DATA 保存datagridview所有數據
    Csharp 讀寫文件內容搜索自動彈出 AutoCompleteMode
    Csharp windowform controls clear
    CSS DIV大图片右上角叠加小图片
    Csharp DataGridView自定义添加DateTimePicker控件日期列
    Csharp 打印Word文件默認打印機或選擇打印機設置代碼
  • 原文地址:https://www.cnblogs.com/donve/p/10252348.html
Copyright © 2011-2022 走看看