Daemon and supervisor

Source: Internet
Author: User
Daemon and supervisor Preface

It has been a long time since I started to contact the daemon, but I often forget it at work. This time, we ran tens of thousands of data processing jobs in the background. It took a long time to execute the scripts in the background, redirects standard output and error output to a log file. After doing other things, you can find that the process is inexplicably killed, even if you have been paying attention to all possible exceptions, then add the try again t exception handling in the appropriate place. However, no exception information was printed. Later, it was suddenly discovered that it was only because it ran through the backend, but it did not make the process a daemon out of the terminal. When the terminal connection fails or the user forgets that the terminal cannot be closed, the process is forcibly exited.

Daemon

Different from the background process, the daemon is not only separated from the console, but from the entire session and from the process group. In this way, the termination of the terminal has nothing to do with the daemon process. And does not affect each other.

The requirements of the daemon are generally as follows:
Disconnections from sessions and Process Groups
Change working directory
Change the permission mask
Disable input/output streams or redirect input/output streams
Set Signal Processing

A python daemon

Supervisor

Supervisor is a python process management tool. It consists of two parts: supervisord and supervisorctl. Supervisord is a daemon, and supervisorctl is a client control program used to manage the opening and closing of the controlled program.

?

Usage

After installation, You need to configure a configuration file such as/etc/supervisord. conf, which mainly configures the program name, command, logfile, log_stdout, and so on.

Enter supervisord on the terminal, and supervisord will be run by subsequent processes. If the program name and command are configured in the configuration file and autostart is set, the command will be automatically executed.

If you need to stop, close, and restart the program, directly supervisorctl start/stop/restart all/Program-name

Internal Principle

Supervisord is actually a python daemon, and then uses subprocess internally according to the configuration file. the popen module executes the command and enables an RPC server to listen to a port. supervisorctl is actually an RPC client that sends some requests to the supervisord for real execution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.