Supervisor helps you keep programs running on your Raspberry Pi. It restarts them if they stop and makes managing many programs easy.
Process management with supervisor in Raspberry Pi
[program:your_program_name] command=python3 /path/to/your_script.py autostart=true autorestart=true stderr_logfile=/var/log/your_program.err.log stdout_logfile=/var/log/your_program.out.log
program: This names your program in Supervisor.
command: The command to run your program.
[program:hello_world] command=python3 /home/pi/hello.py autostart=true autorestart=true stderr_logfile=/var/log/hello.err.log stdout_logfile=/var/log/hello.out.log
[program:web_server] command=/usr/bin/node /home/pi/server.js autostart=true autorestart=true stderr_logfile=/var/log/web_server.err.log stdout_logfile=/var/log/web_server.out.log
This example shows how to set up Supervisor to manage a Python script that blinks an LED on your Raspberry Pi. It will start automatically and restart if it stops.
[program:blink_led] command=python3 /home/pi/blink_led.py autostart=true autorestart=true stderr_logfile=/var/log/blink_led.err.log stdout_logfile=/var/log/blink_led.out.log # To use this: # 1. Save this config as /etc/supervisor/conf.d/blink_led.conf # 2. Run 'sudo supervisorctl reread' and 'sudo supervisorctl update' # 3. Start the program with 'sudo supervisorctl start blink_led' # 4. Check status with 'sudo supervisorctl status blink_led'
After adding or changing Supervisor configs, always run sudo supervisorctl reread and sudo supervisorctl update to apply changes.
Logs help you see what your program is doing or why it stopped. Check the log files if something goes wrong.
You can control programs with sudo supervisorctl start|stop|restart program_name.
Supervisor keeps your Raspberry Pi programs running smoothly by restarting them if they stop.
You write simple config files to tell Supervisor what to run and how.
Use Supervisor commands to manage your programs easily from the terminal.
Practice
supervisor on a Raspberry Pi?Solution
Step 1: Understand Supervisor's role
Supervisor is a tool designed to keep programs running by restarting them if they crash or stop.Step 2: Compare options with Supervisor's function
Updating the operating system, managing network connections, or installing software packages are tasks Supervisor does not do.Final Answer:
To automatically restart programs if they stop unexpectedly -> Option DQuick Check:
Supervisor restarts stopped programs = B [OK]
- Confusing Supervisor with system update tools
- Thinking Supervisor manages network or installs software
- Assuming Supervisor only monitors without restarting
Solution
Step 1: Recall Supervisor service management
Supervisor runs as a system service managed by systemctl on modern Raspberry Pi OS.Step 2: Identify correct command syntax
The correct command to start Supervisor service issudo systemctl start supervisor. Other options are incorrect or incomplete.Final Answer:
sudo systemctl start supervisor -> Option CQuick Check:
Use systemctl to start services = A [OK]
- Omitting sudo and getting permission errors
- Using incomplete or wrong command like 'supervisor start'
- Confusing with older init.d commands
[program:myapp] command=python3 /home/pi/myapp.py autostart=true autorestart=true stderr_logfile=/var/log/myapp.err.log stdout_logfile=/var/log/myapp.out.log
What happens if
myapp.py crashes?Solution
Step 1: Analyze config options autostart and autorestart
autostart=true means program starts with Supervisor; autorestart=true means it restarts if it crashes.Step 2: Understand Supervisor behavior on crash
With autorestart=true, Supervisor will restartmyapp.pyautomatically after a crash.Final Answer:
Supervisor restartsmyapp.pyautomatically -> Option AQuick Check:
autorestart=true means auto restart = C [OK]
- Thinking logs are deleted on crash
- Assuming Supervisor only logs errors without restart
- Confusing autostart with autorestart
[program:myapp] command=python3 /home/pi/myapp.py autostart=false autorestart=true
What is the problem?
Solution
Step 1: Check autostart setting
autostart=false means Supervisor will NOT start the program automatically when it launches.Step 2: Understand effect on program start
Because autostart is false, the program must be started manually; this explains why it does not start automatically.Final Answer:
autostart is set to false, so program won't start on Supervisor launch -> Option AQuick Check:
autostart=false means no auto start = D [OK]
- Confusing autorestart with autostart
- Assuming command syntax is wrong without checking
- Thinking missing logs stop program start
app1.py and app2.py, but only restart app2.py if it crashes. Which config setup is correct?Solution
Step 1: Identify requirements for app1 and app2
app1 should run automatically but NOT restart on crash (autorestart=false). app2 should run automatically and restart on crash (autorestart=true).Step 2: Match config options to requirements
[program:app1] command=python3 /home/pi/app1.py autostart=true autorestart=false [program:app2] command=python3 /home/pi/app2.py autostart=true autorestart=true sets autostart=true for both, autorestart=false for app1, and autorestart=true for app2, matching the requirements exactly.Final Answer:
[program:app1] command=python3 /home/pi/app1.py autostart=true autorestart=false [program:app2] command=python3 /home/pi/app2.py autostart=true autorestart=true -> Option BQuick Check:
app1 no restart, app2 restart = A [OK]
- Setting autostart false prevents program from running automatically
- Confusing autostart and autorestart settings
- Setting autorestart true for programs that shouldn't restart
Ready to prove it?
Pass the test and this pattern moves unknown
