Managing a VPS means managing Linux. Understanding systemd, services, and processes is the foundation of server administration.
Systemd Basics
Systemd manages everything that runs on your server:
Essential Commands
| Command | Purpose |
|---------|---------|
| systemctl status nginx | Check service status |
| systemctl start nginx | Start a service |
| systemctl stop nginx | Stop a service |
| systemctl restart nginx | Restart a service |
| systemctl enable nginx | Start at boot |
| systemctl disable nginx | Don't start at boot |
| systemctl list-units --type=service | List all services |
Service States
| State | Meaning | |-------|---------| | active (running) | Service is running normally | | active (exited) | Started successfully and exited (one-shot) | | inactive (dead) | Service is stopped | | failed | Service crashed or failed to start | | activating | Service is starting up |
Creating Custom Services
Run your own applications as managed services:
# /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=myuser
WorkingDirectory=/home/myuser/app
ExecStart=/usr/bin/node /home/myuser/app/server.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable myapp
sudo systemctl start myapp
Your app now:
- Starts automatically on boot
- Restarts automatically if it crashes
- Can be managed with
systemctlcommands - Logs to journalctl
Process Management
Viewing Processes
# Real-time process monitor
htop
# Process tree
ps auxf
# Find a specific process
ps aux | grep nginx
# Top CPU consumers
ps aux --sort=-%cpu | head -10
# Top memory consumers
ps aux --sort=-%mem | head -10
Process Signals
| Signal | Command | Effect |
|--------|---------|--------|
| SIGTERM (15) | kill PID | Graceful shutdown |
| SIGKILL (9) | kill -9 PID | Force kill (last resort) |
| SIGHUP (1) | kill -1 PID | Reload configuration |
| SIGUSR1 | kill -USR1 PID | Application-defined (often log rotation) |
Always try SIGTERM first. Only use SIGKILL when SIGTERM fails.
Resource Monitoring
Disk Usage
# Overall disk usage
df -h
# Directory sizes
du -sh /var/log/*
# Find large files
find / -type f -size +100M -exec ls -lh {} \;
Memory Usage
# Memory overview
free -h
# Detailed memory info
cat /proc/meminfo
CPU Usage
# CPU info
lscpu
# Load average
uptime
# Per-core usage
mpstat -P ALL 1
Journalctl (Log Management)
# View service logs
journalctl -u nginx
# Follow logs in real time
journalctl -u myapp -f
# Logs from last hour
journalctl -u nginx --since "1 hour ago"
# Logs from today only
journalctl -u nginx --since today
# Disk space used by logs
journalctl --disk-usage
# Clean old logs
sudo journalctl --vacuum-time=7d
Cron Jobs
Schedule recurring tasks:
crontab -e
| Schedule | Cron Expression | Example |
|----------|----------------|---------|
| Every minute | * * * * * | Health checks |
| Every 5 minutes | */5 * * * * | Queue processing |
| Every hour | 0 * * * * | Log rotation |
| Daily at midnight | 0 0 * * * | Backups |
| Weekly on Sunday | 0 0 * * 0 | Cleanup |
| Monthly | 0 0 1 * * | Reports |
System Hardening
| Action | Command | Purpose |
|--------|---------|---------|
| Disable unused services | systemctl disable cups | Reduce attack surface |
| Set resource limits | Edit /etc/security/limits.conf | Prevent resource exhaustion |
| Configure log rotation | Edit /etc/logrotate.conf | Prevent disk filling |
| Monitor failed logins | journalctl -u sshd | Security awareness |
Space-Node's VPS hosting provides KVM virtualization, meaning you get a real Linux kernel with full systemd support. No containerized limitations, just a real server you fully control.
