Browse Source

create installation

Tontowi Prasetyo 5 months ago
parent
commit
a87eef4021

+ 0 - 0
.gitignore


BIN
__pycache__/auth.cpython-310.pyc


BIN
__pycache__/milestone.cpython-310.pyc


BIN
__pycache__/utils.cpython-310.pyc


+ 68 - 0
install.sh

@@ -0,0 +1,68 @@
1
+#!/bin/bash
2
+
3
+# Dynamically determine the project directory
4
+PROJECT_DIR=$(dirname "$(realpath "$0")")
5
+
6
+echo "Setting up the project in $PROJECT_DIR..."
7
+
8
+# Step 1: Create a virtual environment
9
+if [ ! -d "$PROJECT_DIR/venv" ]; then
10
+    echo "Creating a virtual environment..."
11
+    python3 -m venv "$PROJECT_DIR/venv"
12
+else
13
+    echo "Virtual environment already exists."
14
+fi
15
+
16
+# Step 2: Activate the virtual environment
17
+echo "Activating the virtual environment..."
18
+source "$PROJECT_DIR/venv/bin/activate"
19
+
20
+# Step 3: Install dependencies
21
+echo "Installing dependencies..."
22
+pip install --upgrade pip
23
+pip install -r "$PROJECT_DIR/requirements.txt"
24
+
25
+# Ensure Gunicorn is installed
26
+if ! "$PROJECT_DIR/venv/bin/gunicorn" --version &>/dev/null; then
27
+    echo "Installing Gunicorn..."
28
+    pip install gunicorn
29
+else
30
+    echo "Gunicorn is already installed."
31
+fi
32
+
33
+
34
+# Step 4: Create a systemd service
35
+SERVICE_FILE="/etc/systemd/system/gogmilestone.service"
36
+if [ ! -f "$SERVICE_FILE" ]; then
37
+    echo "Creating systemd service..."
38
+    sudo bash -c "cat > $SERVICE_FILE" <<EOL
39
+[Unit]
40
+Description=Gunicorn instance to serve gogmilestone
41
+After=network.target
42
+
43
+[Service]
44
+User=$USER
45
+Group=www-data
46
+WorkingDirectory=$PROJECT_DIR
47
+Environment="PATH=$PROJECT_DIR/venv/bin"
48
+ExecStart=$PROJECT_DIR/venv/bin/gunicorn -w 4 -b 0.0.0.0:4001 gogmilestone2:app
49
+
50
+[Install]
51
+WantedBy=multi-user.target
52
+EOL
53
+
54
+    echo "Reloading systemd daemon..."
55
+    sudo systemctl daemon-reload
56
+
57
+    echo "Enabling gogmilestone service..."
58
+    sudo systemctl enable gogmilestone
59
+
60
+    echo "Starting gogmilestone service..."
61
+    sudo systemctl start gogmilestone
62
+
63
+    echo "Service created and started successfully."
64
+else
65
+    echo "Service already exists. Skipping service creation."
66
+fi
67
+
68
+echo "Setup complete. You can now access the application. Visit http://localhost:4001 to see it in action. use systemctl [start/stop] gogmilestone.service to start/stop the service."

+ 3 - 0
requirements.txt

@@ -0,0 +1,3 @@
1
+flask
2
+requests
3
+gunicorn