-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-scaling
41 lines (30 loc) · 1.34 KB
/
auto-scaling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Update packages and install Apache2
apt update
apt install -y apache2
# Enable the CGI module for Apache
a2enmod cgid
# Modify the Apache configuration to enable ExecCGI and correct the directory
sed -i '/<Directory \/var\/www\/>/!b;n;c\ Options Indexes FollowSymLinks ExecCGI' /etc/apache2/apache2.conf
sed -i 's|<Directory /var/www/>|<Directory /var/www/html>|' /etc/apache2/apache2.conf
# Modify the dir.conf file to set index.py as the DirectoryIndex
sed -i 's/DirectoryIndex .*/DirectoryIndex index.py/' /etc/apache2/mods-available/dir.conf
# Modify the mime.conf file to add support for Python scripts
sed -i 's|#AddHandler cgi-script .cgi|AddHandler cgi-script .py|' /etc/apache2/mods-available/mime.conf
# Remove the default index.html file
rm -rf /var/www/html/index.html
# Create the index.py script
cat << EOF > /var/www/html/index.py
#!/usr/bin/env python3
import socket
import time
time.sleep(5)
print('Content-type: text/html\n\n')
print('<h1><p style="text-align: center;">Apache CloudStack Autoscaling Demo</p></h1>')
print('<h2><p style="text-align: center;"><strong> Instance: </strong>{}</p></h2>'.format(socket.gethostname()))
EOF
# Set permissions for the index.py script
chmod 705 /var/www/html/index.py
# Enable and start the Apache2 service
systemctl enable --now apache2.service
systemctl restart apache2.service