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 :