File tree Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # This script installs the apache web server on the given host.
3
+ # This script assumes the user running it has sudo privs on the remote host.
4
+
5
+ usage () {
6
+ # Display the usage and exit.
7
+ echo " Usage: ${0} HOST [HOSTN...]" >&2
8
+ exit 1
9
+ }
10
+
11
+ # Make sure the script is not being executed with superuser privileges.
12
+ # if [[ "${UID}" -eq 0 ]]
13
+ # then
14
+ # echo 'Do not execute this script as root.' >&2
15
+ # usage
16
+ # fi
17
+
18
+ # If the user doesn't supply at least one argument, give them help.
19
+ if [[ " ${# } " -lt 1 ]]
20
+ then
21
+ usage
22
+ fi
23
+
24
+ # Expect the best, prepare for the worst.
25
+ EXIT_STATUS=' 0'
26
+
27
+ # Loop through the provided servers.
28
+ for SERVER in " ${@ } "
29
+ do
30
+ echo " Starting installation process on: ${SERVER} "
31
+
32
+ # Ping the server to make sure it's up.
33
+ ping -c 1 ${SERVER} & > /dev/null
34
+
35
+ if [[ " ${?} " -ne 0 ]]
36
+ then
37
+ echo " ${SERVER} down."
38
+ EXIT_STATUS=' 1'
39
+ continue
40
+ fi
41
+
42
+ # Install the httpd package
43
+ ssh ${SERVER} sudo yum install -y httpd
44
+
45
+ # Create an index.html file.
46
+ ssh ${SERVER} ' echo "${HOSTNAME}" | sudo tee /var/www/html/index.html >/dev/null'
47
+
48
+ # Start httpd
49
+ ssh ${SERVER} sudo systemctl start httpd
50
+
51
+ # Enable httpd
52
+ ssh ${SERVER} sudo systemctl enable httpd
53
+
54
+ # Test that the web server is accessible.
55
+ curl http://${SERVER}
56
+
57
+ if [[ " ${?} " -ne 0 ]]
58
+ then
59
+ echo " Could not access the web server on ${SERVER} ." >&2
60
+ EXIT_STATUS=' 1'
61
+ continue
62
+ fi
63
+
64
+ echo " Finished installation process on: ${SERVER} "
65
+ done
66
+
67
+ exit ${EXIT_STATUS}
68
+
69
+
You can’t perform that action at this time.
0 commit comments