{"id":9352,"date":"2024-07-01T11:27:56","date_gmt":"2024-07-01T03:27:56","guid":{"rendered":"\/?p=9352"},"modified":"2024-07-01T11:27:56","modified_gmt":"2024-07-01T03:27:56","slug":"linux-%e8%bf%9b%e7%a8%8b%e7%ae%a1%e7%90%86%e5%b7%a5%e5%85%b7-supervisor-%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"\/?p=9352","title":{"rendered":"Linux \u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177 Supervisor \u8be6\u89e3"},"content":{"rendered":"<p>Ubuntu su<a href=\"https:\/\/geek.csdn.net\/educolumn\/2c6ed1be7edac16b3c9a0c3228eaff0c?spm=1055.2569.3001.10083\">per<\/a>visor\u662f\u4e00\u4e2a\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u76d1\u63a7\u548c\u63a7\u5236\u8fdb\u7a0b\u7684\u8fd0\u884c\u3002\u4ee5\u4e0b\u662fUbuntu su<a href=\"https:\/\/geek.csdn.net\/educolumn\/2c6ed1be7edac16b3c9a0c3228eaff0c?spm=1055.2569.3001.10083\">per<\/a>visor\u7684\u5b89\u88c5\u65b9\u6cd5\uff1a 1.\u4f7f\u7528apt\u5b89\u88c5\uff1asudo apt-get install su<a href=\"https:\/\/geek.csdn.net\/educolumn\/2c6ed1be7edac16b3c9a0c3228eaff0c?spm=1055.2569.3001.10083\">per<\/a>visor 2.\u4f7f\u7528pip\u5b89\u88c5\uff1asudo apt-get install python-pip\uff0c\u7136\u540epip install su<a href=\"https:\/\/geek.csdn.net\/educolumn\/2c6ed1be7edac16b3c9a0c3228eaff0c?spm=1055.2569.3001.10083\">per<\/a>visor \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8su<a href=\"https:\/\/geek.csdn.net\/educolumn\/2c6ed1be7edac16b3c9a0c3228eaff0c?spm=1055.2569.3001.10083\">per<\/a>visor\uff1a sudo supervisord -c \/etc\/supervisor\/conf.d\/app.conf \u6ce8\u610f\uff0c\u8fd9\u91cc\u7684app.conf\u662f\u4f60\u81ea\u5df1\u5b9a\u4e49\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u4fee\u6539\u3002\u53e6\u5916\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fUbuntu 16.04.x\uff0c\u53ef\u4ee5\u53c2\u8003\u5f15\u7528\u4e2d\u63d0\u4f9b\u7684\u6559\u7a0b\u8fdb\u884c\u5b89\u88c5\u548c\u914d\u7f6e\u3002<\/p>\n<p>\u76f8\u5173\u95ee\u9898<\/p>\n<h2>ubuntu \u5b89\u88c5supervisor<\/h2>\n<p>\u5b89\u88c5 supervisor \u7684\u65b9\u6cd5\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u4f7f\u7528\u547d\u4ee4 sudo apt-get update \u66f4\u65b0\u7cfb\u7edf\u8f6f\u4ef6\u5305\uff0c\u786e\u4fdd\u5404\u4e2a\u7248\u672c\u5305\u90fd\u662f\u6700\u65b0\u7684\u3002<\/li>\n<li>\u4f7f\u7528\u547d\u4ee4 sudo apt-get install supervisor \u5b89\u88c5 supervisor\u3002<\/li>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 sudo service supervisor start \u542f\u52a8 supervisor \u670d\u52a1\u3002<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 \/etc\/supervisor\/supervisord.conf \u6587\u4ef6\u6765\u914d\u7f6e supervisor\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u8be5\u6587\u4ef6\u4e2d\u6dfb\u52a0 [program:myprogram] \u914d\u7f6e\u6765\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a myprogram \u7684\u7a0b\u5e8f\uff0c\u5e76\u6307\u5b9a\u5176\u542f\u52a8\u547d\u4ee4\u3002<\/li>\n<li>\u4f7f\u7528 sudo supervisorctl reread \u547d\u4ee4\u91cd\u65b0\u8bfb\u53d6 supervisor \u914d\u7f6e\u6587\u4ef6\u3002<\/li>\n<li>\u4f7f\u7528 sudo supervisorctl update \u547d\u4ee4\u542f\u52a8\u65b0\u6dfb\u52a0\u7684\u7a0b\u5e8f\uff0c\u6216\u4f7f\u7528 sudo supervisorctl start [program_name] \u547d\u4ee4\u5355\u72ec\u542f\u52a8\u67d0\u4e2a\u7a0b\u5e8f\u3002<\/li>\n<\/ol>\n<h2>ubuntu20.04\u5b89\u88c5supervisor<\/h2>\n<p>\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5\u548c\u914d\u7f6e Supervisor\uff1a<\/p>\n<ul>\n<li>\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\u548c\u5df2\u5b89\u88c5\u8f6f\u4ef6\u5305<\/li>\n<\/ul>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<ul>\n<li>\u5b89\u88c5 Supervisor \u8f6f\u4ef6\u5305<\/li>\n<\/ul>\n<pre><code>sudo apt install supervisor<\/code><\/pre>\n<ul>\n<li>\u914d\u7f6e Supervisor<\/li>\n<\/ul>\n<p>\u6253\u5f00 \/etc\/supervisor\/supervisord.conf \u6587\u4ef6\u8fdb\u884c\u7f16\u8f91\uff1a<\/p>\n<pre><code>sudo nano \/etc\/supervisor\/supervisord.conf<\/code><\/pre>\n<p>\u627e\u5230\u5e76\u53d6\u6d88\u6ce8\u91ca\u4ee5\u4e0b\u884c\uff0c\u4ee5\u4fbf\u5141\u8bb8 Supervisor web \u754c\u9762\u7684\u8bbf\u95ee\uff1a<\/p>\n<pre><code>[inet_http_server]\nport = 127.0.0.1:9001<\/code><\/pre>\n<p>\u53ef\u4ee5\u4fee\u6539 <code>port<\/code> \u4e3a\u9002\u5408\u60a8\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<ul>\n<li>\u914d\u7f6e Supervisor \u7684\u7a0b\u5e8f<\/li>\n<\/ul>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Supervisor \u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982 <code>myprogram.conf<\/code>\uff1a<\/p>\n<pre><code>sudo nano \/etc\/supervisor\/conf.d\/myprogram.conf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff0c\u4ee5\u542f\u52a8\u4e00\u4e2a Python \u7a0b\u5e8f\u4f5c\u4e3a\u793a\u4f8b\uff1a<\/p>\n<pre><code>[program:myprogram]\ncommand=\/usr\/bin\/python3 \/path\/to\/myprogram.py\ndirectory=\/path\/to\/\nautostart=true\nautorestart=true\nstderr_logfile=\/var\/log\/myprogram.err.log\nstdout_logfile=\/var\/log\/myprogram.out.log\nuser=myuser<\/code><\/pre>\n<p>\u60a8\u9700\u8981\u5c06 <code>\/path\/to\/myprogram.py<\/code> \u66ff\u6362\u4e3a\u60a8\u7684\u7a0b\u5e8f\u8def\u5f84\uff0c\u5c06 <code>\/path\/to\/<\/code> \u66ff\u6362\u4e3a\u60a8\u7684\u7a0b\u5e8f\u76ee\u5f55\uff0c\u5c06 <code>\/var\/log\/myprogram.err.log<\/code> \u548c <code>\/var\/log\/myprogram.out.log<\/code> \u66ff\u6362\u4e3a\u60a8\u7684\u65e5\u5fd7\u6587\u4ef6\u8def\u5f84\uff0c\u5c06 <code>myuser<\/code> \u66ff\u6362\u4e3a\u60a8\u7684\u7528\u6237\u540d\u3002<\/p>\n<ul>\n<li>\u91cd\u65b0\u52a0\u8f7d Supervisor \u914d\u7f6e<\/li>\n<\/ul>\n<pre><code>sudo supervisorctl reread\nsudo supervisorctl update<\/code><\/pre>\n<ul>\n<li>\u542f\u52a8 Supervisor<\/li>\n<\/ul>\n<pre><code>sudo systemctl start supervisor<\/code><\/pre>\n<ul>\n<li>\u68c0\u67e5 Supervisor \u72b6\u6001<\/li>\n<\/ul>\n<pre><code>sudo systemctl status supervisor<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u5e94\u8be5\u770b\u5230 Supervisor \u6b63\u5728\u8fd0\u884c\u5e76\u5df2\u542f\u52a8\u60a8\u7684\u7a0b\u5e8f\u3002<\/p>\n<ul>\n<li>\u8bbf\u95ee Supervisor web \u754c\u9762<\/li>\n<\/ul>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee <code>http:\/\/your-server-ip:9001\/<\/code>\uff0c\u60a8\u5e94\u8be5\u53ef\u4ee5\u770b\u5230 Supervisor web \u754c\u9762\uff0c\u5e76\u53ef\u4ee5\u7ba1\u7406\u60a8\u7684\u7a0b\u5e8f\u3002\u5982\u679c\u60a8\u5728\u7b2c 3 \u6b65\u4e2d\u66f4\u6539\u4e86\u7aef\u53e3\u53f7\uff0c\u8bf7\u5c06 <code>9001<\/code> \u66ff\u6362\u4e3a\u60a8\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728 Ubuntu 20.04 \u4e0a\u5b89\u88c5\u548c\u914d\u7f6e Supervisor\u3002<\/p>\n<h2>\u5e38\u7528\u6307\u4ee4<\/h2>\n<p><code>supervisorctl<\/code> \u662f\u4e0e <code>supervisord<\/code> \u8fdb\u884c\u4ea4\u4e92\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u4e8e\u7ba1\u7406\u901a\u8fc7 <code>supervisord<\/code> \u63a7\u5236\u7684\u8fdb\u7a0b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684 <code>supervisorctl<\/code> \u547d\u4ee4\uff0c\u6309\u7167\u529f\u80fd\u5206\u7c7b\u8fdb\u884c\u5f52\u7eb3\uff1a<\/p>\n<h3>1. <strong>\u8fde\u63a5\u4e0e\u65ad\u5f00<\/strong><\/h3>\n<ul>\n<li><strong>\u65e0\u53c2\u6570\u542f\u52a8<\/strong>\uff1a\u76f4\u63a5\u8f93\u5165 <code>supervisorctl<\/code> \u8fde\u63a5\u5230 <code>supervisord<\/code>\uff08\u5982\u679c\u914d\u7f6e\u4e86\u8ba4\u8bc1\uff0c\u53ef\u80fd\u9700\u8981\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801\uff09\u3002<\/li>\n<\/ul>\n<h3>2. <strong>\u67e5\u770b\u72b6\u6001<\/strong><\/h3>\n<ul>\n<li><strong>\u67e5\u770b\u6240\u6709\u8fdb\u7a0b\u72b6\u6001<\/strong>\uff1a<code>supervisorctl status<\/code><\/li>\n<li><strong>\u67e5\u770b\u7279\u5b9a\u8fdb\u7a0b\u72b6\u6001<\/strong>\uff1a<code>supervisorctl status [\u8fdb\u7a0b\u540d]<\/code><\/li>\n<\/ul>\n<h3>3. <strong>\u8fdb\u7a0b\u7ba1\u7406<\/strong><\/h3>\n<ul>\n<li>\n<p>\u542f\u52a8\u8fdb\u7a0b<\/p>\n<p>\uff1a<\/p>\n<ul>\n<li>\u542f\u52a8\u6240\u6709\u8fdb\u7a0b\uff1a<code>supervisorctl start all<\/code><\/li>\n<li>\u542f\u52a8\u7279\u5b9a\u8fdb\u7a0b\uff1a<code>supervisorctl start [\u8fdb\u7a0b\u540d]<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u505c\u6b62\u8fdb\u7a0b<\/p>\n<p>\uff1a<\/p>\n<ul>\n<li>\u505c\u6b62\u6240\u6709\u8fdb\u7a0b\uff1a<code>supervisorctl stop all<\/code><\/li>\n<li>\u505c\u6b62\u7279\u5b9a\u8fdb\u7a0b\uff1a<code>supervisorctl stop [\u8fdb\u7a0b\u540d]<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u91cd\u542f\u8fdb\u7a0b<\/p>\n<p>\uff1a<\/p>\n<ul>\n<li>\u91cd\u542f\u6240\u6709\u8fdb\u7a0b\uff1a<code>supervisorctl restart all<\/code><\/li>\n<li>\u91cd\u542f\u7279\u5b9a\u8fdb\u7a0b\uff1a<code>supervisorctl restart [\u8fdb\u7a0b\u540d]<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>4. <strong>\u914d\u7f6e\u6587\u4ef6\u7ba1\u7406<\/strong><\/h3>\n<ul>\n<li><strong>\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6<\/strong>\uff1a<code>supervisorctl reload<\/code><\/li>\n<li><strong>\u66f4\u65b0\u5e76\u91cd\u542f\u53d8\u5316\u7684\u8fdb\u7a0b<\/strong>\uff1a<code>supervisorctl update<\/code><\/li>\n<\/ul>\n<h3>5. <strong>\u5176\u4ed6\u7ba1\u7406\u547d\u4ee4<\/strong><\/h3>\n<ul>\n<li><strong>\u6dfb\u52a0\u65b0\u7684\u8fdb\u7a0b\u914d\u7f6e<\/strong>\uff1a<code>supervisorctl add [\u914d\u7f6e\u6587\u4ef6\u8def\u5f84]<\/code><\/li>\n<li><strong>\u79fb\u9664\u6307\u5b9a\u7684\u8fdb\u7a0b<\/strong>\uff1a<code>supervisorctl remove [\u8fdb\u7a0b\u540d]<\/code><\/li>\n<li><strong>\u5173\u95ed <code>supervisord<\/code><\/strong>\uff1a<code>supervisorctl shutdown<\/code><\/li>\n<\/ul>\n<h3>6. <strong>\u4ea4\u4e92\u6a21\u5f0f\u547d\u4ee4<\/strong><\/h3>\n<ul>\n<li>\u8fdb\u5165 <code>supervisorctl<\/code> \u7684\u4ea4\u4e92\u6a21\u5f0f\u540e\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165 <code>status<\/code>\u3001<code>start<\/code>\u3001<code>stop<\/code>\u3001<code>restart<\/code> \u7b49\u547d\u4ee4\uff0c\u800c\u65e0\u9700\u6bcf\u6b21\u90fd\u8f93\u5165 <code>supervisorctl<\/code>\u3002<\/li>\n<\/ul>\n<h3>7. <strong>\u5e2e\u52a9\u547d\u4ee4<\/strong><\/h3>\n<ul>\n<li>\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\uff0c\u8f93\u5165 <code>help<\/code> \u53ef\u4ee5\u67e5\u770b\u6240\u6709\u53ef\u7528\u7684\u547d\u4ee4\u53ca\u5176\u63cf\u8ff0\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u6ce8\u610f\uff0c\u4e0a\u8ff0\u547d\u4ee4\u4e2d\u7684 <code>[\u8fdb\u7a0b\u540d]<\/code> \u9700\u8981\u66ff\u6362\u4e3a\u4f60\u5b9e\u9645\u8981\u7ba1\u7406\u7684\u8fdb\u7a0b\u540d\u3002\u53e6\u5916\uff0c\u4e00\u4e9b\u547d\u4ee4\uff08\u5982 <code>add<\/code>\u3001<code>remove<\/code>\uff09\u53ef\u80fd\u9700\u8981\u6839\u636e\u4f60\u7684\u5b9e\u9645\u914d\u7f6e\u6587\u4ef6\u548c\u6743\u9650\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu supervisor\u662f\u4e00\u4e2a\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u76d1\u63a7\u548c\u63a7\u5236\u8fdb\u7a0b\u7684\u8fd0\u884c\u3002\u4ee5\u4e0b\u662fUbuntu supervisor\u7684\u5b89\u88c5\u65b9   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[14],"tags":[275],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9352"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9352"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9352\/revisions"}],"predecessor-version":[{"id":9353,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9352\/revisions\/9353"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9352"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}