Skip to content

Instantly share code, notes, and snippets.

@esradev
Created December 19, 2024 10:14
Show Gist options
  • Save esradev/3fdc7dcd7e0195e587616f8b1f239f1c to your computer and use it in GitHub Desktop.
Save esradev/3fdc7dcd7e0195e587616f8b1f239f1c to your computer and use it in GitHub Desktop.
manage-servers.sh
#!/bin/bash
# Function to start the services
start_services() {
echo "Starting Apache2 and MySQL..."
sudo systemctl start apache2
sudo systemctl start mysql
echo "Apache2 and MySQL started."
}
# Function to stop the services
stop_services() {
echo "Stopping Apache2 and MySQL..."
sudo systemctl stop apache2
sudo systemctl stop mysql
echo "Apache2 and MySQL stopped."
}
# Function to restart the services
restart_services() {
echo "Restarting Apache2 and MySQL..."
sudo systemctl restart apache2
sudo systemctl restart mysql
echo "Apache2 and MySQL restarted."
}
# Function to check the status of the services
status_services() {
echo "Checking status of Apache2 and MySQL..."
sudo systemctl status apache2
sudo systemctl status mysql
}
# User input to choose the action
echo "Choose an action:"
echo "1) Start servers"
echo "2) Stop servers"
echo "3) Restart servers"
echo "4) Check status of servers"
read -p "Enter the number of your choice: " choice
case $choice in
1)
start_services
;;
2)
stop_services
;;
3)
restart_services
;;
4)
status_services
;;
*)
echo "Invalid choice, exiting."
;;
esac
@esradev
Copy link
Author

esradev commented Dec 19, 2024

make public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment