Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible...
Transcript of Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible...
![Page 1: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/1.jpg)
SupervisorA Process Control System
Sergej Kurakin
![Page 2: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/2.jpg)
Need for Long Running Scripts under Linux● Job Queues in PHP (or any other language)● Application Servers in PHP (or any other language)● NodeJS Applications● Selenium WebDriver + Xvfb● You name it
![Page 3: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/3.jpg)
Solutions● Self-Made Daemons● SysV / systemd / launchd● Screen or tmux● nohup● Five star crons● Daemontools● Might be more possible solutions● Supervisor● Docker
![Page 4: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/4.jpg)
Needed options● � Automatic start● � Automatic restart● � Execute under some user account● � Logs (stdout and stderr)● � Easy to use
![Page 5: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/5.jpg)
Self-Made Daemons● Wrote once by myself● I will never do it twice● Third-party is not always good or maintainable● Lots of debugging● All features must be implemented by yourself● Depends on SysV/launchd/systemd
![Page 6: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/6.jpg)
![Page 7: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/7.jpg)
Screen / tmux or nohup● No automatic start● No automatic restart● Logs...
![Page 8: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/8.jpg)
daemontools● Old (but not obsolete)● Does not work under some virtualizations● Might be hard to configure
![Page 9: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/9.jpg)
Five star cron● Still popular and usable● Perfect for job queues (in some situations)
![Page 10: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/10.jpg)
DockerThis topic deserves a separate talk from someone who has good experience with Docker in production environment.
![Page 11: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/11.jpg)
Supervisor!
![Page 12: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/12.jpg)
Supervisor?Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.
![Page 13: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/13.jpg)
Features● Simple - INI-style files● Centralized - one place to manage● Efficient - fork, don’t daemonize● Extensible - events and XML-RPC interface● Compatible - Linux, Mac OS X, Solaris and FreeBSD● Proven
![Page 14: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/14.jpg)
Components
supervisord supervisorctl
![Page 15: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/15.jpg)
Installiation● apt-get install supervisor● yum install supervisor
● easy_install supervisor● pip install supervisor
![Page 16: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/16.jpg)
Configuration files/etc/supervisor/supervisord.conf
/etc/supervisor/conf.d/*.conf
/etc/supervisord.conf
/etc/supervisord.d/*.ini
![Page 17: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/17.jpg)
Simplest process setup [program:myprocess]
command=/usr/bin/php -f /home/user/long.php
Warning: you run this script as root! This is for demo only!!!
![Page 18: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/18.jpg)
Control your processessupervisorctl status
supervisorctl update
supervisorctl stop <name>
supervisorctl start <name>
supervisorctl restart <name>
![Page 19: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/19.jpg)
What about logs?See in /var/log/supervisor/
supervisorctl maintail -f
supervisorctl tail -f <name> stdout
supervisorctl tail -f <name> stderr
![Page 20: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/20.jpg)
![Page 21: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/21.jpg)
You gona like it (program section)!numprocs
directory
umask
autostart
autorestart (false, unexpected, true)
user
environment
startretries
exitcodes
![Page 22: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/22.jpg)
More on command lineclear <name>|all
fg <name>
pid
version
restart <name>
start <name>
stop <name>
reread
update
![Page 23: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/23.jpg)
Many processes[program:myother]
command=/usr/bin/php -f /home/user/other.php
user=user
numprocs=2
process_name=%(program_name)s_%(process_num)s
![Page 24: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/24.jpg)
Groups![group:mygroup]
programs=myprocess,myother
priority=999
![Page 25: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/25.jpg)
Control whole grouprestart <group name>:*
start <group name>:*
stop <group name>:*
![Page 26: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/26.jpg)
Control process in grouprestart <group name>:<name>
start <group name>:<name>
stop <group name>:<name>
![Page 27: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/27.jpg)
Needed options● ✔ Automatic start● ✔ Automatic restart● ✔ Execute under some user account● ✔ Logs (stdout and stderr)● ✔ Easy to use
![Page 28: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/28.jpg)
Not covered topics● Logs Capture Mode● Events and Event Listeners● SupervisorD configuration● Process monitoring (Munin, Zabbix, DataDog)● Lots of details you must figure out
![Page 29: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/29.jpg)
Some notes on Long Running Scripts● Watch for resources (memory usage), GC or restart● Be ready for connection timeouts (MySQL, Redis, etc.)● Clear caches between calls (Doctrine ORM, Statcache, etc.)● Handle exceptions better
![Page 30: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/30.jpg)
Linkshttp://supervisord.org/
https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps
https://code.tutsplus.com/tutorials/monitor-and-control-applications-using-supervisor-part-1--cms-23770
Demo files https://github.com/sergej-kurakin/supervisord-demo
![Page 31: Supervisor - KurakinScreen or tmux nohup Five star crons Daemontools Might be more possible solutions Supervisor Docker. Needed options Automatic start Automatic restart Execute under](https://reader033.fdocuments.net/reader033/viewer/2022051814/60375ea612ae9d6dfb021820/html5/thumbnails/31.jpg)
DiscussionSergej Kurakin
Work @mail: [email protected]
Personal @mail: [email protected]
https://www.linkedin.com/in/sergejkurakin