Search tutorial by keyword

How to Install & configure Supervision

 

Supervision is used to schedule scripts and from this we can execute a script after every second which is not possible in crontab but still as a script needs some time to execute so we will install Supervision and test a script to run after every two or three seconds 

First of all install python packages 

# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

# yum install python-pip

# pip install supervisor

Generate the config file

# echo_supervisord_conf > /etc/supervisord.conf

#  /usr/bin/supervisord -c /etc/supervisord.conf

Now make a test script that will print uptime

# vim /tmp/test.sh

 

#!/bin/bash

 

exec "uptime"

sleep(3)

Save and exit the file

 

# chmod 777 /tmp/test.sh

Now add the following lines to your supervisor config file

# vim /etc/supervisord.conf

[program:test_script]

command=/tmp/test.sh

autostart=true

autorestart=true

stderr_logfile=/tmp/err.log

 

stdout_logfile=/tmp/sri.log

Now execute the following command

#/usr/bin/supervisorctl reread

The result of the command should be test_script : available

# /usr/bin/supervisorctl update

The result of the command should be like this test_script: added process group

# /usr/bin/supervisorctl 

This will log you into console of supervisor where you can see the status of the script where you will write

start test_script

And then see the logs you will see like this 

[root@localhost tmp]# tail -f /tmp/sri.log

 04:10:15 up 2 days,  2:14,  2 users,  load average: 0.02, 0.04, 0.06

 04:10:16 up 2 days,  2:14,  2 users,  load average: 0.02, 0.04, 0.06

 04:10:18 up 2 days,  2:14,  2 users,  load average: 0.02, 0.04, 0.06

 04:10:21 up 2 days,  2:14,  2 users,  load average: 0.02, 0.04, 0.06

 04:13:10 up 2 days,  2:17,  2 users,  load average: 0.00, 0.02, 0.05

 04:13:11 up 2 days,  2:17,  2 users,  load average: 0.00, 0.02, 0.05

 04:13:13 up 2 days,  2:17,  2 users,  load average: 0.00, 0.02, 0.05

 04:13:16 up 2 days,  2:17,  2 users,  load average: 0.00, 0.02, 0.05

 

This shows that script is executing again and again

Michael Dudli

Cloud Specialist with more than 10 years experience in the Hosting Business.

Website: www.cloudserver24.com
More in this category: « How to Install TOMCAT on Linux

Contact

Ventas

sales@cloudserver24.com

Soporte

support@cloudserver24.com