Linux: Supervisor

Al-MooradiAl-Mooradi
1 min read

What is a "Supervisor"?

"Supervisor" is a process manager which provides a singular interface for managing and monitoring several long-running programs.

Run a PHP command using Supervisor

To run a PHP command using Linux Supervisor, you must follow the steps below:

  1. Install "Supervisor"

     sudo apt-get install supervisor
    
  2. Create a "Supervisor" program configuration file:

     sudo nano /etc/supervisor/conf.d/your_program.conf
    
  3. Add the following content to the configuration file:

     [program:your_program_name]
     command=your_command_here
     autostart=true
     autorestart=true
     stderr_logfile=/var/log/idle.err.log # Remove this line if "error log" isn't nedded
     stdout_logfile=/var/log/idle.out.log # Remove this line if "output log" isn't nedded
    
  4. Save and close the file

  5. Update the "Supervisor" configuration:

     sudo supervisorctl reread
    
  6. Next, run the command below, to update the "Supervisor" process group with any new or changed programs:

     sudo supervisorctl update
    
  7. Start the program:

     sudo supervisorctl start your_program_name
    
  8. To check the status of the program:

     sudo supervisorctl status your_program_name
    
  9. To stop the program:

     sudo supervisorctl stop your_program_name
    

As a result, your PHP script should be run as a process managed by "Supervisor," which will restart it if it crashes or stops for any other reason.

Reference: How To Install and Manage Supervisor | DigitalOcean

0
Subscribe to my newsletter

Read articles from Al-Mooradi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Al-Mooradi
Al-Mooradi