Skip to main content

Lab 8.4 - Automation Services

Objectives​

  • Create service management scripts
  • Automate start/stop
  • Monitor services

Exercise 1: Management Script​

# Script to manage multiple services
cat > manage-services.sh << 'EOF'
#!/bin/bash
SERVICES=("nginx" "mysql" "redis")

for service in "${SERVICES[@]}"; do
if systemctl is-active --quiet "$service"; then
echo "$service: active"
else
echo "$service: inactive"
sudo systemctl start "$service"
fi
done
EOF

chmod +x manage-services.sh

Lab created on: December 2024 - Tested on Ubuntu 24.04