龙空技术网

linux 通过supervisord守护进程启动多个服务

战神联盟go 297

前言:

而今我们对“ubuntu804中文”大致比较着重,姐妹们都需要学习一些“ubuntu804中文”的相关文章。那么小编也在网摘上汇集了一些有关“ubuntu804中文””的相关知识,希望兄弟们能喜欢,姐妹们一起来了解一下吧!

supervisord介绍

supervisor就是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。

关键进程:

supervisord :运行supervisor时会启动一个进程,叫supervisord,它负责启动所管理的进程,并将所管理的进程作为自己的子进程来启动,而且可以在所管理的进程出现崩溃时自动重启。

supervisorctl:是命令行管理工具,可以用来执行 stop、start、restart 等命令,来对这些子进程进行管理。

supervisor:是所有进程的父进程,管理着启动的子进展,supervisor以子进程的PID来管理子进程,当子进程异常退出时supervisor可以收到相应的信号量。

ubuntu环境安装以及测试

//安装supervisor sudo apt update && sudo apt install supervisor //查看状态 systemctl status supervisor#解决python3无法安装supervisor==3.2.0//使用如下命令pip3 install git+ pip3 install git+ git+  Cloning  to /tmp/pip-req-build-nise2p7o  Running command git clone --filter=blob:none -q  /tmp/pip-req-build-nise2p7o  Resolved  to commit 8b83afdac70f140787fdb160d930f824a1f90a33  Preparing metadata (setup.py) ... doneRequirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from supervisor==4.3.0.dev0) (56.2.0)Building wheels for collected packages: supervisor  Building wheel for supervisor (setup.py) ... done  Created wheel for supervisor: filename=supervisor-4.3.0.dev0-py2.py3-none-any.whl size=347609 sha256=48daa79d7c99262a54f8c8b5aedf2110e4fa94885307a450ffde56d974754964  Stored in directory: /tmp/pip-ephem-wheel-cache-k329ccka/wheels/aa/e0/56/1e38df38dc5514512288d804fea35fc574e012c075f49e19e3Successfully built supervisorInstalling collected packages: supervisor  Attempting uninstall: supervisor    Found existing installation: supervisor 4.2.4    Uninstalling supervisor-4.2.4:      Successfully uninstalled supervisor-4.2.4Successfully installed supervisor-4.3.0.dev0安装成功root@wadequ-ThinkPad-L13:/etc/supervisor/conf.d# ln -s  /usr/local/bin/supervisorctl /usr/bin/supervisorctl//使用命令supervisorctl statussupervisorctl startsupervisorctl restart//可通过命令行的方式管理root@wadequ-ThinkPad-L13:~# supervisorctlChose default config file: /etc/supervisor/supervisord.confWARN: No file matches via include "/etc/supervisor/conf.d/*.conf"supervisor> statussupervisor> helpdefault commands (type help <topic>):=====================================add    exit      open  reload  restart   start   tail   avail  fg        pid   remove  shutdown  status  update clear  maintail  quit  reread  signal    stop    version
配置文件以及启动自己的守护进程
//配置自己的服务root@wadequ-ThinkPad-L13:/etc/supervisor/conf.d# pwd/etc/supervisor/conf.droot@wadequ-ThinkPad-L13:/etc/supervisor/conf.d# vi devops.conf[program:devops]#启动目录directory=/opt/pythondjango/django-vue-admin20210713bak/dvadmin-backend#启动命令comand=python manage.py runserver 0.0.0.0:8000#是否自动启动autostart=true#启动时间startsecs=5#异常关闭后自动启动autorestart=true#启动尝试次数startretries=3#启动用户user=root#重定向错误信息到文件redirect_stderr=true#文件大小stdout_logfile_maxbytes=20MBstdout_logfile=/var/log/devops.logstderr_logfile=/var/log/devops_err.log//重新启动以及查看root@wadequ-ThinkPad-L13:/etc/supervisor/conf.d# supervisorctlChose default config file: /etc/supervisor/supervisord.confINFO: Included extra file "/etc/supervisor/conf.d/devops.conf" during parsingdevops                           RUNNING   pid 24880, uptime 0:05:23supervisor> statusdevops                           RUNNING   pid 24880, uptime 0:05:27supervisor>   查看正在启动中
配置web页面查看supervisor服务启动的当前状态
//添加配置[inet_http_server]         ; inet (TCP) server disabled by defaultport=0.0.0.0:9090          ; (ip_address:port specifier, *:port for all iface)username=wade              ; (default is no username (open server))password=12456              ; (default is no password (open server))//重新加载supervisorsupervisorctl reload//访问页面
上图就是web页面的访问情况  ,可根据自己的实际情况进行重启以及重新加载

标签: #ubuntu804中文