Original Use daemon for permanent server survival under Linux

Source: Internet
Author: User

Many server-side designers rarely take into account the problem of permanent server survival or hot swap, which seems to be really rare

One of the biggest theoretical support for permanent survival is how do we really guarantee that a group of servers is constantly in existence, even if it goes down?

In fact, no one can guarantee that their code is so flawless, because it is the existence of the need to collapse, must expose more errors to be more perfect, so in addition to their own a lot of test code, in fact, the program itself is a lot of testing is not achievable, then we need more external support, So in the actual operation, the best is daemon such a system.

1. What is daemon

In fact, Daemon is a process keeper (daemon), a mechanism or system that protects your system from crashes caused by external or abnormal errors and restores it quickly in the shortest possible time.

Of course I'm not here to teach you how to write a daemon, because for many teams, that cost is unnecessary (we have more money to do it).

That's http://libslack.org/'s home-made software daemon, which automatically protects any process and keeps the program running steadily until you kill it or stop it, as a natural turn off the daemon itself.

2, Installation daemon

First directly from the address: http://libslack.org/daemon/download/daemon-0.6.4.tar.gz Download daemon the latest source code.

Then upload to the Linux server

TAR-XVF daemon-0.6.4.tar.gz

CD daemon-0.6.4

Note: In this step it is not possible to configure the daemon installation path, it will be installed by default into/usr/local/bin, but a global shortcut will be created to run the program directly using daemon.

./config

Make-j8

Make Install-daemon

Note: This step is to install the daemon configuration file by default to be installed to/etc/daemon.conf

Make install-daemon-conf

3. Configuration daemon and parameter description

In fact, the parameters of daemon itself can be placed directly into the/etc/daemon.conf, then basically the configuration file is very easy to use.

Open the remote daemon.conf

Its configuration file format is

Configuration name (between configuration name and parameter list, separated by spaces) parameter list (multiple parameters are separated by commas), for example:

Test_server Respwan

Parameter description (partial):

-H,--help-print help information

-V,--version-print version information

-V,--verbose[=level]-set redundancy level

-D,--debug[=level]-set debug level

-C,--config=path-Specifies a special profile path, which defaults to:/etc/daemon.conf

-N,--noconfig-will not read any profile information without reading/etc/daemon.conf

-N,--name=name-the name of the configuration item, which will load the target name parameter information

-X,--command=cmd-defines special suffix parameters, such as when a parameter is required to start

-D,--chdir=path-Change the Run directory

-M,--umask=umask-Change the mask of the target execution program

-U,--unsafe-run no security state execution program

-S,--safe-run Safe Execution program

-C,--core-generates a core file for debugging

-R,--respawn-whether to restart the program when the program is closed

-F,--foreground-foreground run program

-P,--pty[=noecho]-Allocate a pseudo terminal for the client

-L,--errlog=spec-defines the target error log location for the daemon

-B,--dbglog=spec-debug Log location

-O,--output=spec-outputs the log of the running program

-O,--stdout=spec-outputs of the output running program

-E,--stderr=spec-output error log of the running program

--running-whether a program that detects this name is already running

--restart-Restart this program name program

--stop-Program to end this name

4. Start using daemon

When used, the parameters of the target program are configured first, and by default, the parameter respawn is used to detect the restart program when the program is closed, such as adding this option in daemon.conf

Test_server Respwan,chdir=/home/test_server

For example, I'm going to start test_server now, so, just type in the shell.

Daemon--name=test_server/home/test_server/test_server

This process will be guarded until the entire run cycle is complete.

The Test_server program that starts here is located under:/home/test_server

5. Application and expansion exploration

This system is well suited for applications that require strong protection, such as with other exception-catching systems, and will provide a good guarantee of the operation of the entire server and the repair of crash bugs.

It is also possible to control or monitor the operation of the daemon through other external programs, which can reasonably control the opening and closing of the whole system. This thing

Original Use daemon for permanent server survival under Linux

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.