Linux start process in with stdout

Содержание
  1. Работа с потоками STDIN, STDOUT, STDERR
  2. Виды потоков
  3. Управление потоками
  4. Заключение
  5. Потоки данных
  6. stdout
  7. stderr
  8. stdin
  9. Перенаправление потоков
  10. 0. Use Supervisor
  11. 0.1 installation
  12. 0.2 configure supervisord.conf
  13. 0.3 start supervisord
  14. 0.4 Start Elasticsearch
  15. 0.5 start Kibana
  16. 0.6 Start Redis
  17. 0.7 start RedisInsight
  18. 0.8 Access to Web UI
  19. 0.9 boot supervisord
  20. 0.10 Common commands
  21. 1 Introduction
  22. 1.1 Overview
  23. 1.1.1 Convenience
  24. 1.1.2 Accuracy
  25. 1.1.3 Commission
  26. 1.1.4 Process Group
  27. 1.2 Features
  28. 1.2.1 Simple
  29. 1.2.2 Concentration
  30. 1.2.3 Efficient
  31. 1.2.4 Scalable
  32. 1.2.5 Compatibility
  33. 1.2.6 Proven
  34. 1.3Supervisor components
  35. 1.3.1supervisord
  36. 1.3.2supervisorctl
  37. 1.3.3 Network Service
  38. 1.3.4XML-RPC interface
  39. 1.4 Platform requirements
  40. 2. Installation
  41. 2.1 Install to a system with network access
  42. 2.1.1 Network installation using Pip command
  43. 2.1.2 Network installation without Pip command
  44. 2.2 Install to a system that cannot access the network
  45. 2.3 Install the release package
  46. 2.4 Create a configuration file
  47. 3. Run Supervisor
  48. 3.1 Add program
  49. 3.2 Operationsupervisord
  50. 3.2.1supervisordCommand line options
  51. 3.3 Operationsupervisorctl
  52. 3.3.1supervisorctlCommand line options
  53. 3.3.2supervisorctloperating
  54. 3.4 Signal
  55. 3.4.1 Signal Processing
  56. 3.5 Runtime safety
  57. 3.6 Automatically start at startupsupervisord
  58. 4. Configuration file
  59. 4.1 File format
  60. 4.1.1 Environment variables
  61. 4.2 [unix_http_server] Set up
  62. 4.2.1 [unix_http_server] value
  63. 4.2.1.1 file
  64. 4.2.1.2 chmod
  65. 4.2.1.3 chown
  66. 4.2.1.4 username
  67. 4.2.1.5 password
  68. 4.2.2 [unix_http_server] Example
  69. 4.3 [inet_http_server] Set up
  70. 4.3.1 [inet_http_server] value
  71. 4.3.1.1 port
  72. 4.3.1.2 username
  73. 4.3.1.3 password
  74. 4.3.2 [inet_http_server] Example
  75. 4.4 [supervisord] Set up
  76. 4.4.1 [supervisord] value
  77. 4.4.1.1 logfile
  78. 4.4.1.2 logfile_maxbytes
  79. 4.4.1.3 logfile_backups
  80. 4.4.1.4 loglevel
  81. 4.4.1.5 pidfile
  82. 4.4.1.6 umask
  83. 4.4.1.7 nodaemon
  84. 4.4.1.8 silent
  85. 4.4.1.9 minfds
  86. 4.4.1.10 minprocs
  87. 4.4.1.11 nocleanup
  88. 4.4.1.12 childlogdir
  89. 4.4.1.13 user
  90. 4.4.1.14 directory
  91. 4.4.1.15 strip_ansi
  92. 4.4.1.16 environment
  93. 4.4.1.17 identifier
  94. 4.4.2 [supervisord] Example
  95. 4.5 [supervisorctl] Set up
  96. 4.5.1 [supervisorctl] value
  97. 4.5.1.1 serverurl
  98. 4.5.1.2 username
  99. 4.5.1.3 password
  100. 4.5.1.4 prompt
  101. 4.5.1.5 history_file
  102. 4.5.2 [supervisorctl] Example
  103. 4.6 [program:x] Set up
  104. 4.6.1 [program:x] value
  105. 4.6.1.1 command
  106. 4.6.1.2 process_name
  107. 4.6.1.3 numprocs
  108. 4.6.1.4 numprocs_start
  109. 4.6.1.5 priority
  110. 4.6.1.6 autostart
  111. 4.6.1.7 startsecs
  112. 4.6.1.8 startretries
  113. 4.6.1.9 autorestart
  114. 4.6.1.10 exitcodes
  115. 4.6.1.11 stopsignal
  116. 4.6.1.12 stopwaitsecs
  117. 4.6.1.13 stopasgroup
  118. 4.6.1.14 killasgroup
  119. 4.6.1.15 user
  120. 4.6.1.16 redirect_stderr
  121. 4.6.1.17 stdout_logfile
  122. 4.6.1.18 stdout_logfile_maxbytes
  123. 4.6.1.19 stdout_logfile_backups
  124. 4.6.1.20 stdout_capture_maxbytes
  125. 4.6.1.21 stdout_events_enabled
  126. 4.6.1.22 stdout_syslog
  127. 4.6.1.23 stderr_logfile
  128. 4.6.1.24 stderr_logfile_maxbytes
  129. 4.6.1.25 stderr_logfile_backups
  130. 4.6.1.26 stderr_capture_maxbytes
  131. 4.6.1.27 stderr_events_enabled
  132. 4.6.1.28 stderr_syslog
  133. 4.6.1.29 environment
  134. 4.6.1.30 directory
  135. 4.6.1.31 umask
  136. 4.6.1.32 serverurl
  137. 4.6.2 [program:x] Example
  138. 4.7 [include] Set up
  139. 4.7.1 [include] value
  140. 4.7.1.1 files
  141. 4.7.2 [include] Example
  142. 4.8 [group:x] Set up
  143. 4.8.1 [group:x] value
  144. 4.8.1.1 programs
  145. 4.8.1.2 priority
  146. 4.8.2 [group:x] Example
  147. 4.9 [fcgi-program:x] Set up
  148. 4.9.1 [fcgi-program:x] value
  149. 4.9.1.1 socket
  150. 4.9.1.2 socket_backlog
  151. 4.9.1.3 socket_owner
  152. 4.9.1.4 socket_mode
  153. 4.9.2 [fcgi-program:x] Example
  154. 4.10 [eventlistener:x] Set up
  155. 4.10.1 [eventlistener:x] value
  156. 4.10.1.1 buffer_size
  157. 4.10.1.2 events
  158. 4.10.1.3 result_handler
  159. 4.10.2 [eventlistener:x] Example
  160. 4.11 [rpcinterface:x] Set up
  161. 4.11.1 [rpcinterface:x] value
  162. 4.11.1.1 supervisor.rpcinterface_factory

Работа с потоками STDIN, STDOUT, STDERR

Виды потоков

В системах Linux и Unix существуют стандартные входной (STDIN) и выходные (STDOUT, STDERR) потоки (каналы). Далее рассмотрим подробнее каждый из них.

  • STDIN (Номер файлового дескриптора — 0)
    Стандартный входной поток. Канал принимающий данные для обработки и последующей передачи на канал STDOUT и/или STDERR.
  • STDOUT (Номер файлового дескриптора — 1)
    Стандартный выходной поток. Представляет собой канал записи результатов выполнения каких-либо процессов.
  • STDERR (Номер файлового дескриптора — 2)
    Стандартный выходной поток ошибок. В данный канал попадают сообщения об ошибках.

В рамках терминала канал STDIN считывает входные данные, а каналы STDOUT и STDERR выводят выходные данные на экран.

Управление потоками

Для перенаправления каналов в терминале, применяют определенные символы. Рассмотрим каждый из них на примере команды поиска системных файлов, которые содержат слово — core. Все найденные файлы будут формироваться в поток STDOUT. Те найденные файлы, к которым у обычного пользователя нет доступа будут попадать в STDERR.

find / -name core > /tmp/testfile

В файл /tmp/testfile попадет список путей ко всем найденным файлам, а список ошибок отобразится в терминале.

Запись STDOUT в файл

Символ > — затирает все его содержимое и вставляет значение из потока, поэтому будьте осторожны при правке системных файлов используя данный символ. Если Вам нужно добавить данные в конец файла — используйте два последовательных символа — >> .

  • >> — вывод STDOUT в конец файла.

find / -name core >> /tmp/testfile

В конец файла /tmp/testfile попадет список путей ко всем найденным файлам, а список ошибок отобразится в терминале.

Запись STDOUT в конец файла

  • >& — вывод STDOUT и STDERR в файл

find / -name core >& /tmp/testfile

С помощью составного символа — >& мы объединяем стандартный выходной поток с выходным потоком ошибок. В файл /tmp/testfile попадет список путей ко всем найденным файлам и список ошибок.

Объединение выходных потоков

  • 2> — вывод STDERR в файл

find / -name core 2> /tmp/testfile

В файл /tmp/testfile попадет список ошибок, а список найденных файлов, будет выведен в терминале.

Вывод STDERR

Вывод потоков можно комбинировать и распределять по разным местам. Например, выведем список найденных файлов в /tmp/testfile , а список ошибок отбросим, перенаправив их в /dev/null .

find / -name core > /tmp/testfile 2> /dev/null

Перенаправление потоков

Для того чтобы направить выходной поток одной команды на входной поток другой, применяют символ — | (pipe).

Для примера, выведем в консоли отдельные процессы системы с именем — chrome .

ps | grep chrome

Здесь результат выполнения команды ps передается в роли входных данных для команды grep , в которых она ищет совпадения с именем chrome .

Заключение

В этой небольшой статье мы рассмотрели все стандартные входные и выходные и потоки, которые, в свою очередь, очень часто применяются системными администраторами на практике.

Понравилась статья? Расскажите о ней друзьям!

Источник

Потоки данных

Статья посвящена работой с потоками данных в bash. Я постарался написать ее наиболее доступным и простым языком, чтобы было понятно даже новичкам в Linux.

В одной из моих статей мы рассматривали запись звука в файл с помощью команды:

Эта команда читает файл (устройство) /dev/audio с помощью команды cat и перенаправляет информацию из него в файл /tmp/my.sound (с помощью оператора >).

У каждой программы существует 3 системных потока: stdout, stderr, stdin.

stdout

Стандартный поток вывода данных для программ. Например, когда мы пишем команду ls, то список папок и файлов она выводит именно в этот поток, который отображается у нас в консоли:

stderr

Поток вывода ошибок. Если программа не смогла сделать все как надо — она пишет именно в этот поток. Например, когда rm пытается удалить несуществующий файл:

$ rm example.txt
rm: example.txt: No such file or directory

stdin

Поток ввода данных. А вот это довольно интересный и удобный поток. Например, его использует вэб-сервер, когда просит интерпретаторы выполнить скрипты через CGI. Мы тоже можем попробовать:

В этом примере мы встретили оператор перенаправления потока вывода. Мы остановимся на нем позже.

Перенаправление потоков

Для начала рассмотрим перенаправление потоков в файлы, устройства и другие потоки.

В этом примере мы направили stdout команды ls в файл 1.txt. Читаем его:

Да, все успешно записалось.

Теперь попробуем направить stderr команды rm:

Здесь мы использовали номер потока stderr (2). По умолчанию оператор > перенаправляет поток stdout, который имеет номер 1. Чтобы направить другой поток, надо перед оператором > поставить его номер.

Мы можем направлять одни потоки в направлении других:

В этом примере мы направили поток stdout в файл 1.txt, а затем направили stderr туда же, куда направлен stdout с помощью оператора & перед номером потока.

Теперь давайте поиграем с потоком stdin. Например, я хочу найти все папки «.svn» в некотором проекте и удалить:

Команда find с параметром. выводит в stdout все вложенные папки и файлы, которые находит в данной папке и во всех вложенных.

Теперь нам надо выбрать только папки с именем «.svn»:

Оператор | перенаправляет stdout одного приложения в stdin следующего. То есть все строки найденные с помощью find пошли в команду grep, которая выбирает строки по определенным условиям и выводит их. Здесь условие — это регулярное выражение, которое говорит о том, что строка должна заканчиваться на «/.svn».

Нужные папки мы выбрали, осталось их удалить.

И снова новый оператор: `. Он забирает stdout из команды, которую он окружает и вставляет в данное место как строку.

Получается, что мы запросили все файлы, выбрали из них папки с именем «.svn» и отдали результат как аргументы команде rm. В этом случае у нас будут проблемы если имена файлов и папок содержат пробелы. Исправляем ситуацию:

Теперь мы отдаем нужные файлы команде xargs, которая вызывает rm -Rf и в качестве параметров использует свой stdin построчно. Задача решена.

Источник

0. Use Supervisor

0.1 installation

Supervisor is written in Python, install pip

Don’t want to install pip Or don’t want to install on

To root The user executes the main configuration file to /usr/etc/ table of Contents

0.2 configure supervisord.conf

Switch to ordinary users, modify as needed, user=solang It is recommended to configure it, and supervisord will be started as a normal user. [include] The part must be configured to access the configuration of the custom program.

After saving, create [include] Partial path

0.3 start supervisord

0.4 Start Elasticsearch

There are 3 pits in it, and it will not start up according to the above configuration

1. The configured log directory must exist

2. Set the JAVA_HOME path

At this time, starting elasticsearch still cannot start

At this time, go to the configured log output directory to view

To set the JAVA_HOME path, the setting in the Linux system does not work.

3. Configure the number of file descriptors and threads

At this time, starting elasticsearch still cannot start

This error isInstall ElasticsearchI have encountered it, but we have configured the number of file descriptors and the number of threads during installation. It must be supervisord to configure.

modify /usr/etc/supervisord.conf The main configuration file, in [supervisord] Partially increase configuration.

Due to the modification of the main configuration file, supervisord Need to restart. The pit is coming again, execute supervisorctl reload , Found that the child process (ie the configuration file in the config directory) restarted, supervisord Did not restart, use kill Command to kill the process.

Restart after killing the process supervisord , Found that Elasticsearch started successfully.

note: startsecs=60 , Try to set a larger time at this time, in the configuration supervisord Before the number of file descriptors and the number of threads, the value of this key is set to 3, and then in supervisord.log 3s after the successful start of Elasticsearch on the output log supervisord I thought that Elasticsearch was successfully started, but later encountered the problem of insufficient file descriptors and threads.

In addition, the priority here priority=998 , Because Kibana will be started later, Elasticsearch must be started before Kibana.

0.5 start Kibana

After the configuration is complete, start Kibana

0.6 Start Redis

note: The pits here are mainly command The key configuration command should be started in the foreground. redis.conf In the configuration file daemonize To no Just fine, if you haven’t changed it, the default is no 。

Set here priority=998 , Because redis monitoring tool RedisInsight will be started later, redis must be started first than RedisInsight.

After the configuration is complete, start redis

0.7 start RedisInsight

After the configuration is complete, start RedisInsight

0.8 Access to Web UI

The browser visits http://192.168.86.100:9001/, enters the configured user name and password, and can manage and view the running status of the process.

0.9 boot supervisord

After booting up the settings, execute reboot

View supervisord The process found that does not exist.

Try to start manually and found an error

Error: According to the «minfds» command line parameter or configuration file setting, the minimum number of file descriptors required to run this process is 65536. The current environment only allows you to open 65536 file descriptors.

Of course, the number of file descriptors for this error is set when Elasticsearch is started. I expand the number of file descriptors in the system and execute systemctl start supervisord Still reporting an error.After doing it for a long time, there is still no solution. I hope that the friends who read here will inform us when they have a solution, and make progress together.(PS: Under normal circumstances, the machine will not be restarted, of course, start manually after restarting supervisord Also possible)

0.10 Common commands

1 Introduction

1.1 Overview

Supervisor is a client/server system that allows its users to control multiple processes on UNIX-like operating systems. It is inspired by:

1.1.1 Convenience

Need to be written for each single process instance rc.d Scripts are usually very inconvenient. rc.d Scripts are a good most basic form of process initialization/automatic startup/management, but they can be troublesome to write and maintain. In addition, rc.d Scripts cannot automatically restart crashed processes, and many programs cannot restart themselves correctly when they crash. Supervisord starts processes as its child processes and can be configured to restart them automatically in the event of a crash. It can also be automatically configured to invoke the startup process by itself.

1.1.2 Accuracy

On UNIX, it is often difficult to obtain accurate startup/shutdown status of a process. Pidfile often lies. Supervisord starts the process as a child process, so it always knows the true startup/shutdown status of its child process, and can easily query these data.

1.1.3 Commission

Users who need to control the state of a process usually only need to do so. They do not want or need full shell access to the computer running these processes. Processes that listen to «low» TCP ports usually need to be started and restarted as the root user (UNIX error feature). Under normal circumstances, it is perfectly possible to allow «normal» users to stop or restart such processes, but providing them with shell access is usually impractical, and providing them with root access or sudo access is usually impossible of. It is also difficult (correctly) to explain to them why this problem exists. If supervisord is started as a root user, you can allow «normal» users to control such processes without explaining the complexity of the problem to them. Supervisorctl allows access to the computer in a very limited way, essentially allowing users to view the process status and control the child processes supervised by supervisord by issuing «stop», «start» and «restart» commands from a simple Shell or Web UI.

1.1.4 Process Group

Processes usually need to be started and stopped in groups, sometimes even in «priority order». It is often difficult to explain to people how to do it. Supervisor allows you to assign priorities to processes and allows users to issue commands via the supervisorctl client, such as «start all» and «restart all», which will start them in the order of pre-assigned priority. In addition, processes can be grouped into «process groups», and a group of logically related processes can be stopped and started as a unit.

1.2 Features

1.2.1 Simple

Supervisor is configured through an easy-to-learn INI-style configuration file. It provides many options for each process to make your work easier, such as restarting failed processes and automatic log rotation.

1.2.2 Concentration

Supervisor provides you with a place to start, stop and monitor processes. Processes can be controlled individually or in groups. You can configure Supervisor to provide a local or remote command line and web interface.

1.2.3 Efficient

Supervisor starts its child process through fork/exec, and the child process does not daemonize. When the process terminates, the operating system immediately sends a signal to Supervisor, which is different from some solutions that rely on troublesome PID files and periodic polling to restart failed processes.

1.2.4 Scalable

Supervisor has a simple event notification protocol, which can be monitored by programs written in any language, and an XML-RPC interface for control. Python developers can use these extension points to build.

1.2.5 Compatibility

Except for Windows, Supervisor is suitable for almost all other aspects. It has been tested and supported on Linux, Mac OS X, Solaris and FreeBSD. It is written entirely in Python, so installation does not require a C compiler.

1.2.6 Proven

Although Supervisor is very active today, it is not new software. Supervisor has been around for many years and has been used on many services.

1.3Supervisor components

1.3.1supervisord

The service part of the supervisor is calledsupervisord. It is responsible for calling and launching subroutines by itself, responding to commands from the client, restarting crashed or exited subprocesses, and recording its subprocesses stdout with stderr Output and generate and process «events» corresponding to points in the life cycle of the child process.

The service process uses configuration files. It is usually located /etc/supervisord.conf in. This configuration file is a «Windows-INI» style configuration file. It is important to ensure the security of this file with proper file system permissions, as it may contain unencrypted user names and passwords.

1.3.2supervisorctl

The command line client part of the supervisor is calledsupervisorctl. It issupervisordThe provided features provide a shell-like interface. Fromsupervisorctl, Users can connect to differentsupervisordProcess (one at a time), get the status of the child process controlled by it, stop and start the child process, and getsupervisordList of running processes.

Читайте также:  Файл шрифта для mac os

The command line client communicates with the service through UNIX domain sockets or Internet (TCP) sockets. The service can assert that the user of the client should present authentication credentials before allowing the client to execute the command. The client process usually uses the same configuration file as the service, but any with [supervisorctl] Part of the configuration file can work.

1.3.3 Network Service

If started for Internet socketssupervisord, You can access functions similar tosupervisorctlThe (sparse) web user interface. Activation profile [inet_http_server] Part, access the service URL (e.g. http://localhost:9001/ ) To view and control the process status through the web interface.

1.3.4XML-RPC interface

The same HTTP service that provides services for the Web UI provides an XML-RPC interface, which can be used to query and control the supervisor and its running programs. SeeXML-RPC API documentation。

1.4 Platform requirements

Supervisor has been tested and is known to run on Linux (Ubuntu 9.10), Mac OS X (10.4/10.5/10.6), Solaris (10 for Intel) and FreeBSD 6.1. It may work well on most UNIX systems.

Supervisor will not run under any Windows version at all.

Supervisor is designed to work on Python 3 version 3.4 or higher and Python 2 version 2.7.

2. Installation

The installation instructions depend on whether the system you are trying to install Supervisor has network access.

2.1 Install to a system with network access

2.1.1 Network installation using Pip command

can use pip install Install Supervisor:

Depending on the system’s Python permissions, you may need to be a root user to use pip Supervisor is successfully installed.

You can also pass pip Install supervisor in a virtual environment.

2.1.2 Network installation without Pip command

If your system is not installed pip , You need to download the Supervisor release and install it manually. The current and previous Supervisor versions can be downloaded fromPyPidownload. After decompressing the software archive, run python setup.py install . This requires internet access. It will download and install all distributions that Supervisor depends on, and finally install Supervisor itself.

note:
Depending on the Python permissions of the system, you may need to be a root user to successfully call python setup.py install 。

2.2 Install to a system that cannot access the network

If the system where you want to install Supervisor does not have network access, you need to perform the installation in a slightly different way. due to pip with python setup.py install Both rely on network access to perform the download of dependent software, so neither of these two methods will work on a machine without network access until the dependencies are installed. To install on a machine that is not networked, get the following dependencies on a machine that is networked:

Copy these files to removable media, and then place them on the target computer. Follow the instructions to install them on the target computer. This usually just means unzip every file and call in the unzipped directory python setup.py install . Finally, run the supervisor python setup.py install 。

note:
Depending on the system’s Python permissions, you may need to be a root user to successfully invoke each package python setup.py install 。

2.3 Install the release package

Some Linux distributions provide a version of Supervisor that can be installed through the system package manager. These packages are made by third parties (not Supervisor developers) and usually include release-specific changes to Supervisor.

Use the distribution’s package management tool to check availability; for example, on Ubuntu, you can run apt-cache show supervisor , On CentOS, you can run yum info supervisor 。

One feature of Supervisor distribution packages is that they will usually be integrated into the distributed service management infrastructure, for example, allowing supervisord It starts automatically when the system starts.

note:
The Supervisor release package may lag far behind the official Supervisor package released to PyPI. For example, Ubuntu 12.04 (released in April 2012) provides a package based on Supervisor 3.0a8 (released in January 2010).

note:
Users report that the Supervisor distribution package for Ubuntu 16.04 behaves differently from previous versions. On Ubuntu 10.04, 12.04 and 14.04, the installation package will configure the system to start when the system boots supervisord . On Ubuntu 16.04, the initial release of the package did not do this. The package was later repaired. For more information, seeUbuntu Bug #1594740。

2.4 Create a configuration file

After the Supervisor installation is complete, run echo_supervisord_conf . This will print the «sample» Supervisor configuration file to the standard output of the terminal.

Once you see the file echoed to the terminal, please echo_supervisord_conf > /etc/supervisord.conf Recall the command. If you do not have root access, this operation will be invalid.

If you don’t have root access, or you don’t want to supervisord.conf File on /etc/supervisord.conf , You can place it in the current directory ( echo_supervisord_conf > supervisord.conf ) And use -c Logo startsupervisordTo specify the configuration file location.

E.g, supervisord -c supervisord.conf . In this case, use -c The logo is actually redundant becausesupervisordSearch in the current directory before searching for files in any other location supervisord.conf , But it will work. related -c For more information about the logo, see3. Run Supervisor

Once you have a configuration file on the file system, you can start to modify it to your liking.

3. Run Supervisor

This section explains how to runsupervisordwithsupervisorctlRefer to when ordering BINDIR . This is the «bindir» directory where the Python installation is configured. For example, for passing ./configure —prefix=/usr/local/py; make; make install Installed Python installation, BINDIR will be /usr/local/py/bin . Python interpreters on different platforms use different BINDIR . If you can’t determine your location, check setup.py install Output.

3.1 Add program

To makesupervisordTo help you, you need to add at least one in its configuration program section. program Part will define a callsupervisordPrograms that are run and managed at command time. To add a program, you need to edit supervisord.conf file.

UNIX cat The program is one of the simplest programs that can run. The following shows thesupervisordWill run when the process starts cat of program section.

This section can be cut and pasted into supervisord.conf File. This is the simplest program configuration because it only names one command. There are many other configuration options in the program configuration section, which are not shown here. For more information, see4.6 [program:x] settings

3.2 Operationsupervisord

To startsupervisord, Please run $BINDIR/supervisord . The spawned process daemonizes itself and separates it from the terminal. By default, it will keep the operation log in $CWD/supervisor.log in.

You can pass in the command line by -n Flag to launch executable in the foregroundsupervisord. This is useful for debugging startup problems.

whensupervisordAt startup, it will search for its configuration files in the default location (including the current working directory). If you focus on safety, you may need tosupervisordSpecify the «-c» parameter after the command to specify the absolute path of the configuration file to ensure that no one will trick you from including rogue supervisord.conf Run supervisor in the directory of the file. When supervisor is started as root without this -c When parameter, a warning will be issued.

To changesupervisordControlled assembly, please edit supervisord.conf File and kill -HUP Or restart in other wayssupervisordprocess. This file has several example program definitions.

supervisordThe command accepts many command line options. Each of these command-line options overrides any equivalent value in the configuration file.

3.2.1supervisordCommand line options

command description
-c FILE, —configuration=FILE Path to supervisord configuration file
-n, —nodaemon Run in the foregroundsupervisord
-s, —silent No output directed to stdout
-h, —help displaysupervisordCommand line help
-u USER, —user=USER UNIX user name or digital user ID. in casesupervisordStart as root user and setuid this user as soon as possible during the startup process.
-m OCTAL, —umask=OCTAL representativesupervisordWhat should be used after startupumaskThe octal number (for example, 022).
-d PATH, —directory=PATH When supervisord is running as a daemon, cd to this directory before the daemon is running.
-l FILE, —logfile=FILE The file name path used as supervisord activity log.
-y BYTES, —logfile_maxbytes=BYTES The maximum size of supervisord activity log files before the rotation occurs. The value suffix is ​​multiplied, for example, «1» is one byte, «1MB» is 1 megabyte, and «1GB» is 1 gigabyte.
-z NUM, —logfile_backups=NUM The number of backup copies of the supervisord activity log to keep. The size of each log file is logfile_maxbytes 。
-e LEVEL, —loglevel=LEVEL The supervisor should write it to the logging level of the activity log. The effective level is trace 、 debug 、 info 、 warn 、 error with critical 。
-j FILE, —pidfile=FILE The file name supervisord should write to its pid file.
-i STRING, —identifier=STRING Any string identifier that various client UIs expose for this supervisor instance.
-q PATH, —childlogdir=PATH supervisor will write its AUTO The directory path of the mode child process log (the directory must already exist).
-k, —nocleanup preventsupervisordPerform cleanup at startup (delete the old AUTO Process log file).
-a NUM, —minfds=NUM The minimum number of file descriptors that must be available before the supervisord process can be successfully started.
-t, —strip_ansi Remove ANSI escape sequences from all child log processes.
-v, —version Output the version number of supervisord to stdout and exit.
–profile_options=LIST A comma-separated list of options for analysis. MakesupervisordRun under the analyzer and output the results based on the options, which are the following list separated by commas: cumulative , calls , callers . E.g cumulative,callers 。
–minprocs=NUM The minimum number of OS process slots that must be available before the supervisord process can be successfully started.

3.3 Operationsupervisorctl

To startsupervisorctl,run $BINDIR/supervisorctl . Will display a shell allowing you to control the currentsupervisordProcess of management. Type «help» at the prompt to get information about the supported commands.

When called from the command line with parameterssupervisorctlWhen the file is executable, you can use the «one-time» command to call. E.g: supervisorctl stop all . If there are parameters in the command line, the interactive shell will be blocked. Instead, the command will be executed, supervisorctl Will exit, with 0 indicating success or running, and non-zero indicating an error. For example: if any single process is not running, supervisorctl status all Will return non-zero.

If you need to authenticate in interactive modesupervisordtransfersupervisorctl, You will be asked to provide authentication credentials.

3.3.1supervisorctlCommand line options

command description
-c, —configuration Configuration file path (default is /etc/supervisord.conf )
-h, —help Print usage information and exit
-i, —interactive Start the interactive shell after executing the command
-s, —serverurl URL The URL that the supervisord service is monitoring (the default is «http://localhost:9001”)。
-u, —username Username used for service authentication
-p, —password Password used for service authentication
-r, —history-file Keep readline history (if readline is available)

Actions are commands such as «tail» or «stop». If -i is specified on the command line or no operation is specified, an interactive type interpretation operation «shell» will be started. Use the action «help» to find available actions.

3.3.2supervisorctloperating

command description
help Print a list of available operations
help print s help
add [. ] Activate any updates in the process/group configuration
remove [. ] Remove process/group from active configuration
update Reload the configuration and add/remove as needed, and the affected programs will be restarted
update all Reload the configuration and add/remove as needed, and the affected programs will be restarted
update [. ] Update specific groups and restart affected programs
clear Clear the log file of the process.
clear Clear log files of multiple processes
clear all Clear log files of all processes
fg

Connect to the process in the foreground mode and press Ctrl+C to exit the foreground pid Get the PID of supervisord pid Get the PID of a single child process by name pid all Get the PID of each child process, one per line reload Restart remote supervisord reread Reload the configuration file of the daemon without adding/deleting (without restarting) restart Note on restarting the process: Restarting will not re-read the configuration file. For this, see reread and update restart :* Restart all processes in the group. Note: Restarting will not re-read the configuration file. For this, see reread and update restart Restart multiple processes or groups. Note: Restarting will not re-read the configuration file. For this, see reread and update restart all Restart all processes. Note: Restarting will not re-read the configuration file. For this, see reread and update signal No help signal start Start a process start :* Start all processes in the group start Start multiple processes or groups start all Start all processes status Get all process status information status Get the status of a single process by name status Get the status of multiple named processes stop Stop a process stop :* Stop all processes in the group stop Stop multiple processes or groups stop all Stop all processes tail [-f] [stdout|stderr] (default stdout) Output the last part of the process log, for example: tail -f The naming process continues at the tail stdout, Ctrl+C exits. tail -100 The last 100 bytes stdout of the process; tail stderr The last 1600 bytes of the process stderr

3.4 Signal

supervisordThe program may be signaled, causing it to perform certain actions while it is running.

You can send any of these signals to a singlesupervisordProcess ID. This process ID can be in the configuration file [supervisord] part of pidfile Found in the file indicated by the parameter (default is $CWD/supervisord.pid )。

3.4.1 Signal Processing

signal description
SIGTERM supervisordAnd all child processes will be closed. This may take a few seconds.
SIGINT supervisordAnd all child processes will be closed. This may take a few seconds.
SIGQUIT supervisordAnd all child processes will be closed. This may take a few seconds.
SIGHUP supervisordAll processes are stopped, the configuration is reloaded from the first configuration file found, and all processes are started.
SIGUSR2 supervisordThe main activity log and all sub log files will be closed and reopened.

3.5 Runtime safety

The developers have done their best to ensure the use ofsupervisordThe process does not cause unexpected privilege escalation. butUser discretion. Supervisor is not like DJ BernsteindaemontoolsSo paranoid becausesupervisordAllows to write arbitrary path specifications in its configuration file. Allowing an arbitrary path to be selected will cause loopholes in symbolic link attacks. Be careful when specifying the path in the configuration. Ensure that unauthorized users cannot read or writesupervisordConfiguration files, and all files installed by the supervisor package have «reasonable» file permission protection settings. In addition, make sure your PYTHONPATH Reasonable, and all Python standard library files have sufficient file permissions protection.

3.6 Automatically start at startupsupervisord

If you are using the Supervisor packaged with the release, it should have been integrated into the service management infrastructure of the release.

The following are scripts of various operating systems contributed by users:

In case you run into trouble, there are some answers on Serverfault:How to automatically start supervisord on Linux (Ubuntu)

4. Configuration file

The Supervisor configuration file is usually named supervisord.conf 。supervisordwithsupervisorctlBoth use it. If not -c In the case of option, start any application (this option is used to explicitly inform the application configuration file name), then the application will find the name in the following locations in the specified order supervisord.conf document. It will use the first file found.

  1. ../etc/supervisord.conf (Relative to executable files, for example /usr/etc/supervisord.conf )
  2. ../supervisord.conf (Relative to executable files, for example /usr/supervisord.conf )
  3. $CWD/supervisord.conf
  4. $CWD/etc/supervisord.conf
  5. /etc/supervisord.conf
  6. /etc/supervisor/supervisord.conf (From Supervisor 3.3.0)

note:
Many versions of Supervisor packaged for Debian and Ubuntu include a patch that will /etc/supervisor/supervisord.conf Added to the search path. Supervisor’s first PyPI software package included it was Supervisor 3.3.0.

4.1 File format

supervisord.conf It is a Windows-INI style (Python ConfigParser) file. It has parts (each part consists of [header] Represents) and key/value pairs within the section. The parts and their allowable values ​​are as follows.

4.1.1 Environment variables

start upsupervisordWhen the environment variables exist in the environment, you can use Python string expression syntax %(ENV_X)s Use in the configuration file:

In the example above, the expression %(ENV_LOGLEVEL)s Will expand to environment variables LOGLEVEL Value.

note:
In Supervisor 3.2 and later, all options are supported %(ENV_X)s expression. In previous versions, some options supported them, but most did not. See the documentation for each option below.

4.2 [unix_http_server] Set up

supervisord.conf The file contains the file named [unix_http_server] The configuration parameters of the HTTP service monitored on UNIX domain sockets should be inserted under this part. If there is no [unix_http_server] Part, the UNIX domain socket HTTP service will not be started. The allowed configuration values ​​are as follows.

4.2.1 [unix_http_server] value

4.2.1.1 file

The supervisor will listen to the path of HTTP/XML-RPC requests on UNIX domain sockets.supervisorctlUse XML-RPC to communicate withsupervisordCommunication. This option can contain values %(here)s , The value will expand to findsupervisordThe directory of the configuration file.

caveat:
echo_supervisord_confSample configuration output using /tmp/supervisor.sock As a socket file. This path is just an example, you may need to change it to a location that is more suitable for your system. Some systems delete regularly /tmp Old files in. If the socket file is deleted,supervisorctlWill not be able to connect tosupervisord

4.2.1.2 chmod

At startup, change the UNIX permission mode bit of the UNIX domain socket to this value.

4.2.1.3 chown

Change the user and group of the socket file to this value. Can be UNIX user names (such as chrism) or UNIX user names and groups separated by colons (such as chrism:wheel )。

Defaults: Use the username and user group that started supervisord.
Required:no.
Introduction:3.0

4.2.1.4 username

The username required to authenticate to this HTTP service.

Defaults: No username required.
Required:no.
Introduction:3.0

4.2.1.5 password

The password required to authenticate this HTTP service. This can be a plaintext password, or it can be specified as a SHA-1 hash (if the string As a prefix). E.g, 82ab876d1387bfafe46cc1c8a2ef074eae50cb1d Is the SHA stored version of the password «thepassword».

Note that the hash password must be in hexadecimal format.

Defaults: No password required.
Required:no.
Introduction:3.0

4.2.2 [unix_http_server] Example

4.3 [inet_http_server] Set up

supervisord.conf The file contains the file named [inet_http_server] The configuration parameters of the HTTP service monitoring TCP (internet) sockets should be inserted under this part. If the configuration file does not [inet_http_server] Part, the inet HTTP service will not be started. The allowed configuration values ​​are as follows.

caveat:
By default, the inet HTTP service is not enabled. If you choose to enable it, please read the following security warning. The inet HTTP service is only used in a trusted environment. It should only be bound to localhost or can only be accessed from an isolated, trusted network. The inet HTTP service does not support any form of encryption. By default, the inet HTTP service does not use authentication (see username= with password= Option). Can be fromsupervisorctlRemote control of Inet HTTP service. It also provides a web interface that allows to start or stop the child process and view the child process log.Do not expose the inet HTTP service to the public network.

4.3.1 [inet_http_server] value

4.3.1.1 port

TCP host:port value (for example 127.0.0.1:9001 ), the supervisor will listen for HTTP/XML-RPC requests on this value.supervisorctlWill use XML-RPC to communicate withsupervisordCommunication. To listen to all interfaces in the machine, use :9001 or *:9001 . Please read the safety warning above.

Defaults: No default value.
Required:Yes.
Introduction:3.0

4.3.1.2 username

The username required to authenticate to this HTTP service.

Defaults: No username required.
Required:no.
Introduction:3.0

4.3.1.3 password

The password required to authenticate this HTTP service. This can be a plain text password, or it can be specified as a SHA-1 hash (if the string As a prefix). E.g, 82ab876d1387bfafe46cc1c8a2ef074eae50cb1d Is the SHA stored version of the password «thepassword».

Note that the hash password must be in hexadecimal format.

Defaults: No password required.
Required:no.
Introduction:3.0

4.3.2 [inet_http_server] Example

4.4 [supervisord] Set up

supervisord.conf The file contains the file named [supervisord] Should be inserted withsupervisordProcess-related global settings. details as follows.

4.4.1 [supervisord] value

4.4.1.1 logfile

The path to the activity log of the supervisord process. This option can contain values %(here)s , The value will expand to the directory where the supervisord configuration file is found.

note:
If you change logfile Special files that are not viewable (such as /dev/stdout ), you must set logfile_maxbytes = 0 To disable log rotation.

Defaults: $CWD/supervisord.log 。
Required:no.
Introduction:3.0

4.4.1.2 logfile_maxbytes

The maximum number of bytes that the activity log file may consume before being rotated (the value can use suffix multipliers such as «KB», «MB», and «GB»). Setting this value to 0 means that the log size is unlimited.

4.4.1.3 logfile_backups

The active log file rotation produces the number of backups to keep. If set to 0, no backup will be kept.

4.4.1.4 loglevel

Logging level, indicating what to write to supervisord activity log. critical 、 error 、 warn 、 info 、 debug 、 trace or blather one. Note that at the log level debug , The supervisord log file will record the stderr/stdout output of its child processes and extended information about process state changes, which is useful for debugging processes that have not started normally. See also:Activity log level

4.4.1.5 pidfile

supervisord reserves the location of its pid file. This option can contain values %(here)s , The value will expand to the directory where the supervisord configuration file is found.

Defaults: $CWD/supervisord.pid 。
Required:no.
Introduction:3.0

4.4.1.6 umask

4.4.1.7 nodaemon

If true, the supervisor will start in the foreground instead of a daemon.

4.4.1.8 silent

If true and not guarded, the log will not be directed to stdout.

4.4.1.9 minfds

The minimum number of file descriptors that must be available before supervisord can be successfully started. Will call setrlimit to try to increase the soft limit and hard limit of the supervisord process to meet minfds . The hard limit can be increased only when supervisord is running as root. Supervisord uses file descriptors unrestrictedly, and when it cannot obtain file descriptors from the operating system, it will enter a failure mode, so it is useful to be able to specify a minimum value to ensure that they are not exhausted during execution. These restrictions will be inherited by the managed child process. This option is particularly useful on Solaris, because Solaris has a lower fd limit per process by default.

4.4.1.10 minprocs

The minimum number of process descriptors that must be available before supervisord can be successfully started. Setrlimit will be called to try to increase the soft and hard limits of the supervisord process to meet minprocs . The hard limit can be increased only when supervisord is running as root. When the operating system’s process descriptors are used up, supervisord will enter failure mode, so make suresupervisordIt is useful to have enough process descriptors available at startup.

4.4.1.11 nocleanup

Prevent supervisord from clearing any existing AUTO Sub log file. Useful for debugging.

4.4.1.12 childlogdir

Used for AUTO The directory of the sub-log file. This option can contain values %(here)s , The value will expand to findsupervisordThe directory of the configuration file.

Defaults: Python tempfile.get_tempdir() Value.
Required:no.
Introduction:3.0

4.4.1.13 user

InstructionssupervisordSwitch the user to the UNIX user account before performing any meaningful processing. If started as root usersupervisordTo switch users.

Defaults: Do not switch users.
Required:no.
Introduction:3.0

Changed: 3.3.4. in casesupervisordCannot switch to the specified user, it will send stderr Write an error message and exit immediately. In earlier versions, it will continue to run, but will critical Level records a message.

4.4.1.14 directory

whensupervisordWhen the daemon, switch to this directory. This option can contain values %(here)s , The value will expand to findsupervisordThe directory of the configuration file.

4.4.1.15 strip_ansi

Remove all ANSI escape sequences from the child log file.

4.4.1.16 environment

To KEY=»val»,KEY2=»val2″ List of key/value pairs in the form ofsupervisordThe environment of the process (and therefore the environment of all its child processes). This option can contain values %(here)s , The value will expand to the directory where the supervisord configuration file is found. Values ​​containing non-alphanumeric characters should be quoted (e.g. KEY=»val:123″,KEY2=»val,456″ ). Otherwise, the quoted value is optional, but recommended. To escape the percent character, just use two (e.g. URI=»/first%%20name» )。note, The child process will inherit the startsupervisordEnvironment variables of the shell, but here and the program environment Except for variables rewritten in options. SeeChild process environment

4.4.1.17 identifier

The identifier string of this supervisor process used by the RPC interface.

4.4.2 [supervisord] Example

4.5 [supervisorctl] Set up

The configuration file can containsupervisorctlInteractive shell program settings. These options are listed below.

4.5.1 [supervisorctl] value

4.5.1.1 serverurl

URL used to access supervisord service, for example http://localhost:9001 . For UNIX domain sockets, use unix:///absolute/path/to/file.sock 。

Defaults: http://localhost:9001 。
Required:no.
Introduction:3.0

4.5.1.2 username

The username passed to the supervisord service for authentication. The name should match the port you are trying to access or in the supervisord service configuration of the UNIX domain socket username the same.

Defaults: No username.
Required:no.
Introduction:3.0

4.5.1.3 password

The password passed to the supervisord service for authentication. This should be the port you want to access or in the supervisord service configuration of the UNIX domain socket password The plaintext version of. This value cannot be passed as a SHA hash. Unlike other passwords specified in this file, it must be provided in clear text.

Defaults: No password.
Required:no.
Introduction:3.0

4.5.1.4 prompt

The string used as supervisorctl prompt.

Defaults: supervisor 。
Required:no.
Introduction:3.0

4.5.1.5 history_file

Used as readline The path of the permanent history file. If you enable this feature by selecting the path, your supervisorctl commands will remain in the file, and you can use readline (for example, the up arrow) to call the commands you executed in the previous supervisorctl session.

4.5.2 [supervisorctl] Example

4.6 [program:x] Set up

The configuration file must contain one or more program Part so that supervisord knows which programs should be started and controlled. The header value is a composite value. It is the word «program», followed by a colon, and then the program name. Head value [program:foo] Describe a program named «foo». The name is used for the client application that controls the process created by this configuration. Create no name program Part is wrong. The name must not contain colon or bracket characters. The value of the name is used as %(program_name)s The string expression expands to the value within the specified other value.

note:
[program:x] The part actually represents the «similar process group» of the supervisor (since version 3.0). The members of this group are configured by numprocs with process_name The combination of parameters is defined. By default, if numprocs and process_name keep the default values ​​unchanged, then [program:x] The indicated group will be named x And it will contain the name x Single process. This provides backward compatibility with earlier supervisor versions, which do not treat program parts as homogeneous process group definitions.

But, for example, if you have a [program:foo] Part, its numprocs Is 3, and process_name The expression is %(program_name)s_%(process_num)02d , The «foo» group will contain three processes named foo_00 、 foo_01 with foo_02 . This makes using a single [program:x] It is possible to partially start many very similar processes. All log file names, all environment strings, and program commands can also contain similar Python string expressions to pass slightly different parameters to each process.

4.6.1 [program:x] value

4.6.1.1 command

The command that will be run when the program is started. The command can be an absolute command (for example /path/to/programname ), or a relative command (e.g. programname ). If it is relative, it will be in the supervisord environment $PATH Search for executable files. The program can accept parameters, such as /path/to/program foo bar . The command line can use double quotes to group parameters with spaces to pass to the program, for example /path/to/program/name -p «foo bar» . note, command The value of may contain Python string expressions, for example /path/to/programname —port=80%(process_num)02d May expand to /path/to/programname —port=8000 . The string expression is based on the containing key group_name 、 host_node_name 、 program_name 、 process_num 、 numprocs 、 here (Directory of supervisord configuration file), and all supervisord environment variables ENV_ At the beginning) of the dictionary. The controlled program itself should not be a daemon, because supervisord assumes that it is responsible for guarding its child processes (seeNondaemonization of child processes)。

note:
If the command looks like a configuration file comment, it will be truncated. E.g, command=bash -c ‘foo ; bar’ Will be truncated to command=bash -c ‘foo . Quotation marks will not prevent this behavior, because the profile reader will not parse commands like a shell.

Defaults: No default.
Required:Yes.
Introduction:3.0

Changed: 4.2.0. Added pair numprocs Extended support.

4.6.1.2 process_name

A Python string expression used to compose the supervisor process name of the process. Unless you change numproc , Otherwise there is usually no need to worry about setting this configuration. Will be included according to group_name 、 host_node_name 、 process_num 、 program_name with here The dictionary (directory of supervisord configuration files) calculates string expressions.

Defaults: %(program_name)s 。
Required:no.
Introduction:3.0

4.6.1.3 numprocs

Supervisor will start as many instances as the program named by numprocs. Note that if numprocs> 1, then process_name The expression must contain %(process_num)s (Or any other containing process_num Valid Python string expressions).

4.6.1.4 numprocs_start

An integer offset used to calculate numprocs The starting number.

4.6.1.5 priority

The relative priority of the program in the startup and shutdown sequence. The lower priority indicates the program that is started first and closed last when the program is started and when aggregate commands are used in various clients (for example, «start all» / «stop all»). A higher priority means that the program starts last and then closes first.

4.6.1.6 autostart

If true, the program will be automatically started when supervisord is started.

4.6.1.7 startsecs

The program needs to keep running after startup to consider the total number of seconds for successful startup (change the process from STARTING State moved to RUNNING status). Setting to 0 means that the program does not need to keep running for any specific time.

note:
even if the process exits with the «expected» code (see exitcodes ) Exit, but if the process exits faster than startsecs Faster, the startup will still be regarded as a failure.

4.6.1.8 startretries

Giving up and making the process enter FATAL Before the state, when trying to start the program,supervisordThe number of serial failed attempts that will be allowed. related FATAL For a description of the status, seeProcess status

4.6.1.9 autorestart

Specify whensupervisordIn RUNNING In the state, if it exits, whether the process should be restarted automatically. maybe false 、 unexpected or true One of them. If false , The process will not restart automatically. If unexpected , When the program exits, the exit code is not one of the exit codes related to the configuration of this process (see exitcodes ), the process will restart. If true , The process will restart unconditionally when exiting, regardless of its exit code.

note:
autorestart If the control program exits after successful startup (the process is in RUNNING status),supervisordWhether to restart the program automatically.

When the process starts (the process is in STARTING status),supervisordThere are different restart mechanisms. Retry during process startup is caused by startsecs with startretries control.

4.6.1.10 exitcodes

versus autorestart A list of «expected» exit codes for the program used together. If autorestart The parameter is set to unexpected , And the process exits in any other way except the supervisor stop request, if the process exits and the exit code is not defined in this list, thensupervisordThe process will be restarted.

note:
In Supervisor versions prior to 4.0, the default value is 0,2 . In Supervisor 4.0, the default setting has been changed to 0.

4.6.1.11 stopsignal

A signal used to terminate the program when a stop is requested. It can be any of TERM, HUP, INT, QUIT, KILL, USR1 or USR2.

4.6.1.12 stopwaitsecs

After sending a stop signal to the program, wait for the operating system to return SIGCHLD tosupervisordOf seconds. in casesupervisordThis number of seconds has elapsed before receiving SIGCHLD from the process,supervisordWill try to kill it with the ultimate SIGKILL.

4.6.1.13 stopasgroup

If true, the flag causes the supervisor to send a stop signal to the entire process group and indicates killasgroup Is true. This is very useful for programs (such as Flask in debug mode) that do not propagate stop signals to their children, leaving them in an isolated state.

4.6.1.14 killasgroup

If true, when SIGKILL is sent to the program to terminate, it will be sent to the entire process group, while taking care of its child processes. multiprocessing The Python program is very useful.

4.6.1.15 user

InstructionssupervisordUse this UNIX user account as the account for running the program. Only ifsupervisordYou can switch users only when running as the root user. in casesupervisordIf you cannot switch to the specified user, the program will not start.

note:
will only be used setuid Change user. This will not start the login shell and will not change USER or HOME Such environment variables. For details, seeChild process environment

Defaults: Do not switch users.
Required:no.
Introduction:3.0

4.6.1.16 redirect_stderr

If true, send the stderr output of the process back to its stdout file descriptorsupervisord(In UNIX Shell terms, this is equivalent to executing /the/program 2>&1 )。

note:

a [eventlistener:x] Set in section redirect_stderr=true . Event listener Eventlisteners use stdout with stdin versus supervisord To communicate. If redirect stderr ,then stderr The output will interfere with the eventlistener protocol.

Defaults:false。
Required:no.
Introduction: 3.0, replacing 2.0 log_stdout with log_stderr

4.6.1.17 stdout_logfile

Put the process stdout output into this file (if redirect_stderr is true, also put the stderr output into this file). If not set stdout_logfile Or set it to AUTO , The supervisor will automatically select the file location. If you set it to NONE , Then supervisord will not create any log files.supervisordWhen restarting, will delete AUTO Log files and their backups. stdout_logfile The value can contain a Python string expression that will target the containing key group_name 、 host_node_name 、 process_num 、 program_name with here (The directory of supervisord configuration files) is calculated.

note:
Enable rotation ( stdout_logfile_maxbytes ), it is impossible for two processes to share a log file ( stdout_logfile ). This will result in file corruption.

note:
If you change stdout_logfile Special files that are not viewable (e.g. /dev/stdout ), you must set stdout_logfile_maxbytes = 0 To disable log rotation.

Defaults: AUTO 。
Required:no.
Introduction: 3.0, replacing 2.0 logfile

4.6.1.18 stdout_logfile_maxbytes

Rotation stdout_logfile The maximum number of bytes that may be consumed before (the value can use suffix multipliers such as «KB», «MB» and «GB»). Setting this value to 0 means that the log size is unlimited.

Defaults:50MB。
Required:no.
Introduction: 3.0, replacing 2.0 logfile_maxbytes

4.6.1.19 stdout_logfile_backups

Process stdout log file rotation produced to be retained stdout_logfile Number of backups. If set to 0, no backup will be kept.

Defaults:10。
Required:no.
Introduction: 3.0, replacing 2.0 logfile_backups

4.6.1.20 stdout_capture_maxbytes

When the process is in «stdout capture mode», the maximum number of bytes written to the capture FIFO (seeCapture mode). Should be an integer (suffix multipliers can be used in the value, such as «KB», «MB» and «GB»). If the value is 0, the process capture mode will be turned off.

4.6.1.21 stdout_events_enabled

If true, will be emitted when the process writes its stdout file descriptor PROCESS_LOG_STDOUT event. The event will only be emitted when the file descriptor is not in capture mode when the data is received (seeCapture mode)。

4.6.1.22 stdout_syslog

If true, direct stdout to syslog along with the process name.

4.6.1.23 stderr_logfile

unless redirect_stderr True, otherwise put the process stderr output into this file. Accept and stdout_logfile The same value type, and can contain the same Python string expression.

note:
Enable rotation ( stderr_logfile_maxbytes ), it is impossible for two processes to share a log file ( stderr_logfile ). This will result in file corruption.

note:
If you change stderr_logfile Special files that are not viewable (e.g. /dev/stderr ), you must set stderr_logfile_maxbytes = 0 To disable log rotation.

4.6.1.24 stderr_logfile_maxbytes

Rotation stderr_logfile The maximum number of bytes before the log file. Accept and stdout_logfile_maxbytes The same value type.

4.6.1.25 stderr_logfile_backups

Process stderr log file rotation produces the number of backups to keep. If set to 0, no backup will be kept.

4.6.1.26 stderr_capture_maxbytes

When the process is in «stderr capture mode», the maximum number of bytes written to the capture FIFO (seeCapture mode). Should be an integer (suffix multipliers can be used in the value, such as «KB», «MB» and «GB»). If the value is 0, the process capture mode will be turned off.

4.6.1.27 stderr_events_enabled

If true, will be emitted when the process writes its stderr file descriptor PROCESS_LOG_STDERR event. The event will only be emitted when the file descriptor is not in capture mode when the data is received (seeCapture mode)。

4.6.1.28 stderr_syslog

If true, stderr will be directed to syslog along with the process name.

4.6.1.29 environment

The format is KEY=»val»,KEY2=»val2″ A list of key/value pairs that will be placed in the environment of the child process. The environment string may contain Python string expressions, which will be group_name 、 host_node_name 、 process_num 、 program_name with here The dictionary (directory of supervisord configuration files) calculates Python string expressions. Values ​​containing non-alphanumeric characters should be quoted (e.g. KEY=»val:123″,KEY2=»val,456″ ). Otherwise, the quoted value is optional, but recommended.note, The child process will inherit the environment variables used to start the «supervisord» shell, except for the variables rewritten here. SeeChild process environment

Defaults: No additional environment.
Required:no.
Introduction:3.0

4.6.1.30 directory

Represents the file path of the directory,supervisordThe directory should be chdir temporarily before executing the child.

Defaults: Not chdir (inherited from supervisor).
Required:no.
Introduction:3.0

4.6.1.31 umask

The octal number representing the umask of the process (such as 002, 022).

Defaults: No special umask (inherited from supervisor).
Required:no.
Introduction:3.0

4.6.1.32 serverurl

In the environment as SUPERVISOR_SERVER_URL (Seesupervisor.childutils) The URL of the process passed to the child process so that the child process can easily communicate with the internal HTTP service. If provided, it should be the same as the one with the same name [supervisorctl] Some options have the same syntax and structure. If it is set to AUTO or not set, the supervisor will automatically construct the service URL, preferentially selecting services that are monitored on UNIX domain sockets, rather than services that are monitored on Internet sockets.

4.6.2 [program:x] Example

4.7 [include] Set up

supervisord.conf The file may contain a file named [include] part. If the configuration file contains [include] Part, it must contain a key named «files». The value in this entry specifies other configuration files to be included in the configuration.

note:
[include] Partly only by supervisord deal with. It is supervisorctl ignore.

4.7.1 [include] value

4.7.1.1 files

A sequence of file globs separated by spaces. Each file glob can be absolute or relative. If the file glob is relative, it is considered relative to the location of the configuration file that contains it. «Glob» is a file pattern that matches the specified pattern according to the rules used by the Unix shell. No tilde

Expand, but * 、 ? And use [] The indicated character range will match correctly. String expressions are based on host_node_name as well as here (Directory of supervisord configuration files). Recursive include from include files is not supported.

Defaults: No default value (required).
Required:Yes.
Introduction:3.0

Changed: 3.3.0. Added pair host_node_name Extended support.

4.7.2 [include] Example

4.8 [group:x] Set up

It is often useful to group «similar» process groups (also called «programs») into «heterogeneous» process groups so that they can be controlled as a unit from the various controller interfaces of Supervisor.

To put programs into a group so that they can be treated as a unit, define a [group:x] section. The group header value is a composite value. It is the word «group», followed by a colon, and then the group name. Head value [group:foo] Describes a group named «foo». This name is used in the client application that controls the process created by this configuration. It is an error to create a group part without a name. The name must not contain colon or bracket characters.

Correct [group:x] , There must be one or more in other positions in the configuration file [group:x] Part, and the group must be in programs Refer to them by name in the value.

If passed [group:x] part of programs If you put the «similar» process group (represented by the program part) into the «heterogeneous» group, the homogenous group implied by the program part will not exist in the supervisor at runtime. Instead, all processes belonging to each homogeneous group are placed into heterogeneous groups. For example, given the following group configuration:

In view of the above, when supervisord starts, bar with baz Similar groups will not exist, and the processes that originally belonged to them will now be moved into foo group.

4.8.1 [group:x] value

4.8.1.1 programs

A comma-separated list of program names. The listed programs become members of the group.

Defaults: No default value (required).
Required:Yes.
Introduction:3.0

4.8.1.2 priority

Similar to the one assigned to the group [program:x] The priority number of the priority value.

4.8.2 [group:x] Example

4.9 [fcgi-program:x] Set up

Supervisor can manage all monitoring on the same socketFastCGIProcess group. So far, FastCGI has limited deployment flexibility. In order to get comprehensive process management, you can use mod_fastcgi under Apache, but then you fall into Apache’s inefficient concurrency model, that is, one process or thread per connection. In addition to requiring more CPU and memory resources, the processes/threads of each connection model may quickly saturate due to slow resources, thereby preventing the use of other resources. In order to take advantage of newer event-driven web services (such as lighttpd or nginx), which do not include a built-in process manager, you must use scripts such as cgi-fcgi or spawn-fcgi. These can be used in conjunction with process managers (such as supervisord or daemontools), but require each FastCGI child process to be bound to its own socket. The disadvantages of this are: unnecessary complex Web service configuration, unnecessary restart and reduced fault tolerance. If the FastCGI process group can share sockets, the fewer sockets are configured, and the smaller the Web service configuration. Shared sockets allow normal restarts, because while any child process is restarting, the socket is still bound by the parent process. Finally, shared sockets have higher fault tolerance, because if a given process fails, other processes can continue to provide services for inbound connections.

With integrated FastCGI generation support, Supervisor provides you with the best of both worlds. You can get full-featured process management through the FastCGI process group sharing sockets, without having to bind to a specific Web service. This is a clear separation of concerns, allowing network services and process managers to do their best.

note:
The socket manager in Supervisor was originally developed to support the FastCGI process, but it is not limited to FastCGI. No special configuration is required, and other protocols can also be used. Any program that can access the opened socket from the file descriptor (for example, usingsocket.fromfd) Can use the socket manager. Supervisor will automatically create a socket, bind and listen before the first child spawned in the group. Socket will be numbered by file descriptor 0 (Zero) is passed to each offspring. When the last child in the group exits, the Supervisor will close the socket.

note:
Before Supervisor 3.4.0, you cannot be in the group ( [group:x] ) References the FastCGI program ( [fcgi-program:x] )。

fcgi-program Partially complied [program:x] Section of all available options.

4.9.1 [fcgi-program:x] value

[fcgi-program:x] Some [program:x] Some keys are not available.

4.9.1.1 socket

FastCGI socket, TCP or UNIX domain socket for this program. For TCP sockets, use the following format: tcp://localhost:9002 . For UNIX domain sockets, use unix:///absolute/path/to/file.sock . The string expression is calculated based on a dictionary containing the keys «program_name» and «here» (directory of supervisord configuration files).

Defaults: No default value.
Required:Yes.
Introduction:3.0

4.9.1.2 socket_backlog

Set up socket monitoring (2) backlog.

Defaults:socket.SOMAXCONN。
Required:no.
Introduction:3.4.0

4.9.1.3 socket_owner

For UNIX domain sockets, this parameter can be used to specify the user and group of the FastCGI socket. It can be a UNIX user name (such as chrism) or a UNIX user name and group separated by a colon (such as chrism:wheel).

Defaults: Use the users and groups set for fcgi-program.
Required:no.
Introduction:3.0

4.9.1.4 socket_mode

For UNIX domain sockets, this parameter can be used to specify the permission mode.

For other allowed keys, please refer to4.6 [program:x] settings, Increment the above constraints and supplements.

4.9.2 [fcgi-program:x] Example

4.10 [eventlistener:x] Set up

Supervisor allows the definition of a dedicated group of processes of the same type («event listener pool») in the configuration file. These pools contain processes for receiving and responding to event notifications from the supervisor’s event system. For an explanation of how events work and how to implement programs that can be declared as event listeners, seeevent

Note that the eventlistener part will comply with [program:x] Part of all available options, but stdout_capture_maxbytes except. Event listener cannot be stdout Process communication events are issued on the stderr Issued on (seeCapture mode)。

4.10.1 [eventlistener:x] value

[eventlistener:x] Some in the section [program:x] Some keys are not available.

4.10.1.1 buffer_size

The size of the event queue buffer of the event listener pool. When the event buffer of the listener pool overflows (for example, when the event listener pool cannot keep up with all the events sent to it), the oldest event in the buffer will be discarded.

4.10.1.2 events

A comma-separated list of event type names that this listener is «interested in» when receiving notifications, (for a list of valid event type names, seeEvent type)。

4.10.1.3 result_handler

Onepkg_resources entry point string, Can be parsed as callable Python. The default value is supervisor.dispatchers:default_handler . Specifying an alternate result handler is a very uncommon thing, so how to create a result handler is not documented.

For other allowed keys, please refer to4.6 [program:x] settings, Increment the above constraints and supplements.

4.10.2 [eventlistener:x] Example

4.11 [rpcinterface:x] Set up

Add in the configuration file rpcinterface:x The settings are only useful for users who wish to extend supervisor with other custom behaviors.

In the example configuration file, there is a file named [rpcinterface:supervisor] part. By default, as shown below.

[rpcinterface:supervisor] sectionhave toKeep it in the configuration to make the supervisor’s standard settings work properly. If you don’t want supervisor to do anything out of the box, this is all you need to know about this type of part.

However, if you want to add the rpc interface namespace to customize the supervisor, you can add additional [rpcinterface:foo] Part, where «foo» represents the interface namespace (starting from the web root directory), supervisor.rpcinterface_factory Named is a factory callable value, it should have a function signature that accepts a single positional parameter supervisord And any number of keyword parameters required to perform the configuration. in [rpcinterface:x] All additional key/value pairs defined in the section will be passed to the factory as keyword parameters.

The following is in the Python package my.package of __init__.py Example of factory function created in the file.

Part of the configuration file is used to configure it.

4.11.1 [rpcinterface:x] value

4.11.1.1 supervisor.rpcinterface_factory

pkg_resources Name the «entry point» as the factory function of the RPC interface.

Источник

Читайте также:  Виджет биржи для windows 10
Оцените статью