VPS Episode 2

Table of Contents

VPS Episode 2

root@atulya:~# systemctl list-units --type=service
  UNIT                                 LOAD   ACTIVE SUB     DESCRIPTION                                >
  apache2.service                      loaded active running The Apache HTTP Server
  apparmor.service                     loaded active exited  Load AppArmor profiles
  cloud-config.service                 loaded active exited  Apply the settings specified in cloud-config
  cloud-final.service                  loaded active exited  Execute cloud user/final scripts
  cloud-init-local.service             loaded active exited  Initial cloud-init job (pre-networking)
  cloud-init.service                   loaded active exited  Initial cloud-init job (metadata service cr>
  coturn.service                       loaded active running coTURN STUN/TURN Server
  cron.service                         loaded active running Regular background program processing daemon
  dbus.service                         loaded active running D-Bus System Message Bus
  exim4.service                        loaded active running LSB: exim Mail Transport Agent
  getty@tty1.service                   loaded active running Getty on tty1
  kmod-static-nodes.service            loaded active exited  Create List of Static Device Nodes
  mariadb.service                      loaded active running MariaDB 10.11.11 database server
● nginx.service                        loaded failed failed  A high performance web server and a reverse>
  packagekit.service                   loaded active running PackageKit Daemon
  polkit.service                       loaded active running Authorization Manager
  postgresql.service                   loaded active exited  PostgreSQL RDBMS
  postgresql@15-main.service           loaded active running PostgreSQL Cluster 15-main
  prosody.service                      loaded active running Prosody XMPP Server
  qemu-guest-agent.service             loaded active running QEMU Guest Agent
  serial-getty@ttyS0.service           loaded active running Serial Getty on ttyS0
  ssh.service                          loaded active running OpenBSD Secure Shell server
  systemd-binfmt.service               loaded active exited  Set Up Additional Binary Formats
  systemd-growfs@-.service             loaded active exited  Grow File System on /
  systemd-journal-flush.service        loaded active exited  Flush Journal to Persistent Storage
  systemd-journald.service             loaded active running Journal Service
  systemd-logind.service               loaded active running User Login Management
  systemd-modules-load.service         loaded active exited  Load Kernel Modules
  systemd-network-generator.service    loaded active exited  Generate network units from Kernel command >
  systemd-networkd-wait-online.service loaded active exited  Wait for Network to be Configured
  systemd-networkd.service             loaded active running Network Configuration
  systemd-random-seed.service          loaded active exited  Load/Save Random Seed
  systemd-remount-fs.service           loaded active exited  Remount Root and Kernel File Systems
  systemd-resolved.service             loaded active running Network Name Resolution
  systemd-sysctl.service               loaded active exited  Apply Kernel Variables
  systemd-sysusers.service             loaded active exited  Create System Users
  systemd-timesyncd.service            loaded active running Network Time Synchronization
  systemd-tmpfiles-setup-dev.service   loaded active exited  Create Static Device Nodes in /dev
  systemd-tmpfiles-setup.service       loaded active exited  Create System Files and Directories
  systemd-udev-trigger.service         loaded active exited  Coldplug All udev Devices
  systemd-udevd.service                loaded active running Rule-based Manager for Device Events and Fi>
  systemd-update-utmp.service          loaded active exited  Record System Boot/Shutdown in UTMP
  systemd-user-sessions.service        loaded active exited  Permit User Sessions
  ufw.service                          loaded active exited  Uncomplicated firewall
  unattended-upgrades.service          loaded active running Unattended Upgrades Shutdown
  user-runtime-dir@0.service           loaded active exited  User Runtime Directory /run/user/0
  user@0.service                       loaded active running User Manager for UID 0

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
47 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
root@atulya:~# 
root@atulya:~# systemctl list-units --type=service
  UNIT                                 LOAD   ACTIVE SUB     DESCRIPTION                                >
  apache2.service                      loaded active running The Apache HTTP Server
  apparmor.service                     loaded active exited  Load AppArmor profiles
  cloud-config.service                 loaded active exited  Apply the settings specified in cloud-config
  cloud-final.service                  loaded active exited  Execute cloud user/final scripts
  cloud-init-local.service             loaded active exited  Initial cloud-init job (pre-networking)
  cloud-init.service                   loaded active exited  Initial cloud-init job (metadata service cr>
  coturn.service                       loaded active running coTURN STUN/TURN Server
  cron.service                         loaded active running Regular background program processing daemon
  dbus.service                         loaded active running D-Bus System Message Bus
  exim4.service                        loaded active running LSB: exim Mail Transport Agent
  getty@tty1.service                   loaded active running Getty on tty1
  kmod-static-nodes.service            loaded active exited  Create List of Static Device Nodes
  mariadb.service                      loaded active running MariaDB 10.11.11 database server
● nginx.service                        loaded failed failed  A high performance web server and a reverse>
  packagekit.service                   loaded active running PackageKit Daemon
  polkit.service                       loaded active running Authorization Manager
  postgresql.service                   loaded active exited  PostgreSQL RDBMS
  postgresql@15-main.service           loaded active running PostgreSQL Cluster 15-main
  prosody.service                      loaded active running Prosody XMPP Server
  qemu-guest-agent.service             loaded active running QEMU Guest Agent
  serial-getty@ttyS0.service           loaded active running Serial Getty on ttyS0
  ssh.service                          loaded active running OpenBSD Secure Shell server
  systemd-binfmt.service               loaded active exited  Set Up Additional Binary Formats
  systemd-growfs@-.service             loaded active exited  Grow File System on /
  systemd-journal-flush.service        loaded active exited  Flush Journal to Persistent Storage
  systemd-journald.service             loaded active running Journal Service
  systemd-logind.service               loaded active running User Login Management
  systemd-modules-load.service         loaded active exited  Load Kernel Modules
  systemd-network-generator.service    loaded active exited  Generate network units from Kernel command >
  systemd-networkd-wait-online.service loaded active exited  Wait for Network to be Configured
  systemd-networkd.service             loaded active running Network Configuration
  systemd-random-seed.service          loaded active exited  Load/Save Random Seed
  systemd-remount-fs.service           loaded active exited  Remount Root and Kernel File Systems
  systemd-resolved.service             loaded active running Network Name Resolution
  systemd-sysctl.service               loaded active exited  Apply Kernel Variables
  systemd-sysusers.service             loaded active exited  Create System Users
  systemd-timesyncd.service            loaded active running Network Time Synchronization
  systemd-tmpfiles-setup-dev.service   loaded active exited  Create Static Device Nodes in /dev
  systemd-tmpfiles-setup.service       loaded active exited  Create System Files and Directories
  systemd-udev-trigger.service         loaded active exited  Coldplug All udev Devices
  systemd-udevd.service                loaded active running Rule-based Manager for Device Events and Fi>
  systemd-update-utmp.service          loaded active exited  Record System Boot/Shutdown in UTMP
  systemd-user-sessions.service        loaded active exited  Permit User Sessions
  ufw.service                          loaded active exited  Uncomplicated firewall
  unattended-upgrades.service          loaded active running Unattended Upgrades Shutdown
  user-runtime-dir@0.service           loaded active exited  User Runtime Directory /run/user/0
  user@0.service                       loaded active running User Manager for UID 0

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
47 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
root@atulya:~# 

Your VPS Service Architecture: A Beautiful Layer-by-Layer Journey 🏗️

Welcome to the fascinating world of your VPS! Let’s explore how all these services work together like a perfectly orchestrated symphony. Think of your server as a digital city with different districts, each serving a unique purpose! 🏙️

🔍 The Current State of Your Digital Kingdom

First, let’s address the elephant in the room - you have a failed nginx service 🚨 while Apache is running perfectly. This is actually quite common when both web servers try to use port 80/443. We’ll dive into this later!


🏛️ LAYER 1: The Foundation (System Core)

These are the bedrock services that make everything else possible:

🧠 Systemd Services (The Operating System Brain)

systemd-journald.service     - Your system's memory keeper 📚
systemd-logind.service       - User session manager 👥
systemd-networkd.service     - Network configuration wizard 🌐
systemd-resolved.service     - DNS name resolver 🔍
systemd-timesyncd.service    - Time synchronization keeper ⏰

What they do: These are like the city’s infrastructure - power grid, water system, and transportation network. Without them, nothing else functions!

🔧 Device & Hardware Management

systemd-udevd.service        - Hardware device detective 🕵️
qemu-guest-agent.service     - VM communication bridge 🌉

The Magic: Your VPS runs as a virtual machine, and the QEMU guest agent lets it communicate with the host system. It’s like having a translator between your virtual world and the physical server!


🏛️ LAYER 2: Security & Access Control

Your digital bouncer and security team:

🛡️ Security Framework

apparmor.service             - Application security enforcer 🛡️
polkit.service              - Permission authorization manager 🗝️
ufw.service                 - Uncomplicated Firewall 🔥

🚪 Access & Authentication

ssh.service                  - Secure remote access gateway 🔐
getty@tty1.service          - Local console login 💻
serial-getty@ttyS0.service  - Serial console access 📺

Beautiful Architecture: SSH is your secure tunnel into the server (port 22), while getty services provide console access. It’s like having both a secure front door and emergency exits!


🏛️ LAYER 3: Data & Database Layer

The treasure vaults of your digital kingdom:

💾 Database Powerhouses

mariadb.service             - MySQL-compatible database 🗄️
postgresql.service          - PostgreSQL database cluster manager 🐘  
postgresql@15-main.service  - Specific PostgreSQL instance (v15) 🏗️

The Beauty: You’re running both MariaDB AND PostgreSQL! This gives you incredible flexibility:

  • MariaDB: Perfect for web applications, WordPress, etc.
  • PostgreSQL: Excellent for complex applications requiring advanced features

🏛️ LAYER 4: Web & Communication Layer

The face of your server to the outside world:

🌐 Web Server Battle Royale

apache2.service             - The reliable web server veteran ✅ RUNNING
nginx.service               - The high-performance newcomer ❌ FAILED

The Drama: You have both Apache and Nginx installed! Here’s what’s happening:

  • Apache is currently serving on port 80/443 (running perfectly) 🎭
  • Nginx failed to start because Apache already claimed those ports 🎪
  • This is like having two restaurants trying to use the same address!

📧 Communication Services

exim4.service               - Mail transport agent 📮
prosody.service             - XMPP chat server 💬
coturn.service              - STUN/TURN server for real-time communication 📞

The Communication Stack:

  • Exim4: Handles sending/receiving emails
  • Prosody: Powers instant messaging (like your own Discord!)
  • coTURN: Helps with video calls and peer-to-peer connections

🏛️ LAYER 5: Automation & Maintenance

The invisible workforce keeping everything running:

🤖 Background Workers

cron.service                - Task scheduler extraordinaire ⏰
packagekit.service          - Software package manager 📦
unattended-upgrades.service - Automatic security updater 🔄

☁️ Cloud Integration

cloud-init-local.service    - Pre-network cloud setup 🌤️
cloud-init.service          - Cloud metadata processor ☁️
cloud-config.service        - Cloud configuration applier ⚙️
cloud-final.service         - Final cloud setup tasks ✅

Cloud Magic: These services make your VPS “cloud-aware” - they automatically configure networking, SSH keys, and initial setup based on your cloud provider’s metadata!


🏛️ LAYER 6: User & Session Management

Managing who’s who and what they can do:

👤 User Services

user-runtime-dir@0.service  - Root user runtime directory 🏠
user@0.service              - Root user session manager 👑
systemd-user-sessions.service - User session coordinator 🎭

🎯 The Beautiful Architecture in Action

Here’s how a typical web request flows through your system:

1. 🌐 Internet Request arrives
2. 🛡️ UFW Firewall checks if allowed
3. 🌐 systemd-networkd handles network routing  
4. 🔍 systemd-resolved resolves domain names
5. 🎭 Apache receives and processes the request
6. 🗄️ Apache might query MariaDB for data
7. 📚 systemd-journald logs everything
8. 📮 If needed, Exim4 sends notification emails

🚨 The Nginx Mystery Solved

Your nginx service failed because:

  1. Port Conflict: Both Apache and Nginx want ports 80 and 443
  2. Apache Started First: It claimed the ports during boot
  3. Nginx Couldn’t Bind: Failed with “Address already in use”

🔧 Solutions:

Option 1: Choose One Winner

# If you prefer Nginx (faster, lighter)
sudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl start nginx
sudo systemctl enable nginx

# If you prefer Apache (more features, easier config)
sudo systemctl stop nginx
sudo systemctl disable nginx
# Keep Apache running (it's already working!)

Option 2: Use Both (Advanced)

# Configure Nginx as reverse proxy (port 80/443)
# Configure Apache on different ports (8080/8443)
# Nginx forwards requests to Apache when needed

🎉 Your Server’s Superpowers

With this setup, your VPS can handle:

  • 🌐 Multiple websites (Apache/Nginx)
  • 💾 Complex databases (MariaDB + PostgreSQL)
  • 📧 Email services (Exim4)
  • 💬 Chat applications (Prosody XMPP)
  • 📞 Video/voice calls (coTURN)
  • 🔄 Automatic maintenance (unattended-upgrades)
  • 🛡️ Enterprise security (AppArmor + UFW)
  • ☁️ Cloud-native features (cloud-init)

🎯 Pro Tips for Your VPS

🔍 Health Monitoring

# Check what's using your resources
systemd-cgtop

# Monitor your databases
sudo systemctl status mariadb postgresql

# Check web server performance  
sudo systemctl status apache2

# Monitor communication services
sudo systemctl status prosody coturn exim4

🚀 Performance Optimization

# Check boot time (find slow services)
systemd-analyze blame

# Monitor failed services
systemctl --failed

# Check service dependencies
systemctl list-dependencies apache2

🌟 Conclusion: Your Digital Masterpiece

Your VPS is a beautifully orchestrated system with multiple layers working in harmony! You’ve got:

  • 🏗️ Solid foundation (systemd core services)
  • 🛡️ Rock-solid security (AppArmor, UFW, SSH)
  • 💾 Dual database power (MariaDB + PostgreSQL)
  • 🌐 Web serving capability (Apache running, Nginx ready)
  • 📧 Full communication stack (Email, Chat, Video)
  • 🤖 Automated maintenance (Updates, scheduling)
  • ☁️ Cloud integration (Dynamic configuration)

The only “issue” is deciding between Apache and Nginx - but that’s a luxury problem to have! Both are excellent web servers, and having both available gives you flexibility for different projects.

Your server is ready to power websites, applications, communication platforms, and much more. It’s like having a Swiss Army knife of internet services! 🎯✨

Tags :