-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_data.sh
151 lines (104 loc) · 3.99 KB
/
user_data.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# Define working directory
WORK_DIR="/home/opc/expense_report"
VENV_PATH="/home/opc/expense_report/venv"
SYSTEMD_SERVICE_FILE="/etc/systemd/system/expense-report-webapp.service"
# Update package manager
sudo yum update -y && echo "Package manager updated successfully"
# Install Git, Python 3.8, and Python 3.8 Development package
sudo yum install git python38 python38-devel -y && echo "Git and Python 3.8 installed successfully"
# Navigate to opc's home directory
cd /home/opc/ && echo "Navigated to /home/opc"
# Clone the Expense Report Webapp repository
git clone https://github.com/tsmith4014/expense_report.git && echo "Repository cloned successfully"
# Navigate to the cloned repository
cd $WORK_DIR && echo "Navigated to $WORK_DIR"
# Install Python-Pip
sudo yum install python3-pip -y && echo "Python-Pip installed successfully"
# Edit requirements.txt to include gunicorn
echo "gunicorn" >> requirements.txt && echo "Added gunicorn to requirements.txt"
# Create a Python virtual environment using Python 3.8
python3.8 -m venv venv && echo "Python virtual environment created successfully"
# Activate the virtual environment
source $VENV_PATH/bin/activate && echo "Virtual environment activated"
# Install Python dependencies
pip install -r requirements.txt && echo "Python dependencies installed successfully"
# Create Gunicorn config file
echo "bind = '0.0.0.0:8000'
workers = 4" > gunicorn_config.py && echo "Gunicorn config file created successfully"
# Create systemd service file
sudo bash -c "cat > $SYSTEMD_SERVICE_FILE" << EOF
[Unit]
Description=Gunicorn instance to serve expense-report-webapp
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
User=opc
Group=opc
WorkingDirectory=$WORK_DIR
Environment="PATH=$VENV_PATH/bin"
ExecStart=$VENV_PATH/bin/gunicorn -w 4 -b 0.0.0.0:8000 app:app
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
echo "Systemd service file created successfully"
# Reload systemd daemon
sudo systemctl daemon-reload && echo "Systemd daemon reloaded successfully"
# Enable the service
sudo systemctl enable expense-report-webapp.service && echo "Service enabled successfully"
# Start the service
sudo systemctl start expense-report-webapp.service && echo "Service started successfully"
# Check the service status
systemctl status expense-report-webapp.service
# # Define working directory
# WORK_DIR="/home/opc/expense_report" # Corrected the directory name
# VENV_PATH="/home/opc/expense_report/venv"
# SYSTEMD_SERVICE_FILE="/etc/systemd/system/expense-report-webapp.service"
# # Update package manager
# yum update -y
# # Install Git and Python3
# yum install git python3 -y
# # Navigate to opc's home directory
# cd /home/opc/
# # Clone the Expense Report Webapp repository
# git clone https://github.com/tsmith4014/expense_report.git
# # Navigate to the cloned repository
# cd $WORK_DIR
# # Install Python-Pip
# yum install python3-pip -y
# # Edit requirements.txt to include gunicorn
# echo "gunicorn" >> requirements.txt
# # Create a Python virtual environment
# python3 -m venv venv
# # Activate the virtual environment
# source $VENV_PATH/bin/activate
# # Install Python dependencies
# pip install -r requirements.txt
# # Create Gunicorn config file
# echo "bind = '0.0.0.0:8000'
# workers = 4" > gunicorn_config.py
# # Create systemd service file
# echo "[Unit]
# Description=Gunicorn instance to serve expense-report-webapp
# Wants=network.target
# After=syslog.target network-online.target
# [Service]
# Type=simple
# WorkingDirectory=$WORK_DIR
# Environment=\"PATH=$VENV_PATH/bin\"
# ExecStart=$VENV_PATH/bin/gunicorn -w 4 -b 0.0.0.0:8000 app:app
# Restart=always
# RestartSec=10
# [Install]
# WantedBy=multi-user.target" > $SYSTEMD_SERVICE_FILE
# # Reload systemd daemon
# systemctl daemon-reload
# # Enable the service
# systemctl enable expense-report-webapp.service
# # Start the service
# systemctl start expense-report-webapp.service
# # Check the service status
# systemctl status expense-report-webapp.service