Managing supervisor effectively is a crucial skill for any system administrator. This tutorial provides step-by-step instructions for process configuration, along with best practices for production environments.
Environment Setup
The supervisor configuration requires careful attention to resource limits and security settings. On a VPS with limited resources, it's important to tune these parameters according to your available RAM and CPU cores.
# Set up the development environment
sudo apt update
sudo apt install -y build-essential curl git
# Install the runtime
curl -fsSL https://get.supervisor.org | bash
supervisor --version
Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.
- Test your backup restore procedure monthly
- Enable automatic security updates for critical patches
- Keep your system packages updated regularly
- Monitor disk space usage and set up alerts
Project Configuration
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
# Create a systemd service for the application
sudo tee /etc/systemd/system/myapp.service << 'EOF'
[Unit]
Description=My Application
After=network.target
[Service]
User=deploy
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/supervisor /opt/myapp/server.js
Restart=always
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable myapp
sudo systemctl start myapp
Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.
Deployment Process
If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.
# Set up the development environment
sudo apt update
sudo apt install -y build-essential curl git
# Install the runtime
curl -fsSL https://get.supervisor.org | bash
supervisor --version
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
- Enable automatic security updates for critical patches
- Test your backup restore procedure monthly
- Monitor disk space usage and set up alerts
- Keep your system packages updated regularly
Process Management
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# Create a systemd service for the application
sudo tee /etc/systemd/system/myapp.service << 'EOF'
[Unit]
Description=My Application
After=network.target
[Service]
User=deploy
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/supervisor /opt/myapp/server.js
Restart=always
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable myapp
sudo systemctl start myapp
The output should show the service running without errors. If you see any warning messages, address them before proceeding to the next step.
Summary
You've successfully configured supervisor on your VPS. Remember to monitor performance, keep your software updated, and maintain regular backups. If you run into issues, consult the official documentation or open a support ticket for assistance.