Install daemontools in CentOS 7

Source: Internet
Author: User

Install daemontools in CentOS 7

Daemontools is a tool used to manage Unix services. It provides a set of tools to manage a series of user processes. After a process is down for some reason, daemontools automatically restarts the process.

Note:

The managed process cannot run in the form of daemon. For example, nginx. conf must disable daemon and daemon off;
Do not create any directory in/service/./service/only stores some symbol links.
You only need to complete the installation/configuration steps.
Install

$ mkdir  ~/tools$ cd /tools$ wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz$ tar xvzf daemontools-0.76.tar.gz$ cd admin/daemontools-0.76$ package/install

If an error occurs during installation

/Usr/bin/ld: errno: TLS defini tion in/lib/libc. so.6 section. tbss mismatches non-TLS reference in envdir. o will admin/daemontools-0.76/src/error. in h, replace extern int errno with # include <errno. h>

After the installation is complete, two directories,/service/command, will be created.

Start daemontools

Daemontools is a set of service management tools. The svscanboot tool is used to start the svscan tool. Run the following command to start svscanboot:

# /command/svscanboot &

You can also set boot startup. For more information, see

After the process is started, view the process and find that the sub-process of svscan as svscanboot is running

# ps -ef|grep svs  root      9134  9072  0 04:05 pts/2    00:00:00 /bin/sh /command/svscanbootroot      9136  9134  0 04:05 pts/2    00:00:00 svscan /service

Configuration

After svscanboot is started, the corresponding svscan process is started. The parameter/service/is the directory for managing the configuration file.

Create the services Directory, for example

# mkdir -p /opt/svc/{nginx, tornado}

Create a run script in the services Directory (the name must be run and the permission is 755), such as the nginx directory

# Touch/opt/svc/nginx/run & chmod 755/opt/svc/nginx/run # cat/opt/svc/nginx/run #! /Bin/shexec/home/vagrant/nginx/sbin/nginx # start the process command

Create a symbol link. After creation, daemontools automatically starts the nginx process.

#ln -s /opt/svc/nginx/  /service/ #ln -s /opt/svc/tornado/  /service/ # pstree -a  -p 9134svscanboot,9134 /command/svscanboot  |-readproctitle,9137 service errors:...  `-svscan,913      6 /service      |-supervise,9138 nginx      |   `-nginx,913       9      |       `-nginx,9140               `-supervise,9164      tornado          `-python,9165 /home/vagrant/tornado/main.py

Svscanboot is responsible for starting the svscan service and managing the supervise process. The specific customer processes are managed in a unified manner through the supervise process.

Now nginx and tornado are managed by daemontool. Try to kill the tornado application process.

root@precise32:/service# kill 9165root@precise32:/service# !psps -ef|grep torroot          9164  9136  0 04:06 pts/2    00:00:00 supervise tornadoroot          9181  9164  2 04:09 pts/2    00:00:00 python /home/vagrant/tornado/main.py

As you can see, although the tornado application is manually killed, the daemontool automatically restarts the application.

Common commands

Start the managed process (no svc command is required after configuration)

Svc-u/service/nginx/(if nginx fails after startup, daemontools will automatically restart nginx)

Shut down the managed process (daemontools supervise process is not disabled)

svc -d /service/nginx/

View service status

svstat /service/nginx/

Remove service

Rm/service/nginx # Remove soft connection svc-dx/opt/svc/nginx/

Pouting

Q: What should I do if the daemontools process crashes ??
A: Check the document and manually kill the svscanboot/svscan/supervisor process?

The above content from http://linbo.github.io/2013/02/24/daemontools

Some modifications are required on CentOS 7 as follows:

Cut 'n' paste fromhttp: // www.productionmonkeys.net/guides/qmail-server/daemontools

CentOS 7 uses systemd

Create a new file/etc/systemd/system/daemontools. service, with the startup code in it:
Create a file/etc/systemd/system/daemontools. service with the following content:

[Unit]Description=daemontools Start superviseAfter=getty.target[Service]Type=simpleUser=rootGroup=rootRestart=alwaysExecStart=/command/svscanboot /dev/ttyS0TimeoutSec=0[Install]WantedBy=multi-user.target
Start the service. Start the service:

Systemctl start daemontools. service

Test that it is running, Test whether to run:

Systemctl status daemontools. service

Enable it to start at boot:

Systemctl enable daemontools. service

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.