Linux system uses Python to monitor Apache server process script sharing

Source: Internet
Author: User
crtrl.py python script to monitor Apache server processes

Copy the Code code as follows:


!/usr/bin/env Python
Import OS, sys, time

While True:
Time.sleep (4)
Try
ret = Os.popen (' ps-c apache-o pid,cmd '). ReadLines ()
If Len (ret) < 2:
Print "Apache process quits unexpectedly, restarts after 4 seconds"
Time.sleep (3)
Os.system ("Service apache2 restart")
Except
Print "Error", Sys.exc_info () [1]

Set file permissions to execute properties (using command chmod +x crtrl.py), and then join to/etc/rc.local, which automatically checks and restarts once the Apache server process exits abnormally. A brief description of listing 5 This script is not based on the/proc pseudo file system, but is based on some of the modules provided by Python itself. This is the embedded time template for Python, which provides functions for various operating times.

  • Related Article

    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.