1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/bin/bash
- # Dynamically determine the project directory
- PROJECT_DIR=$(dirname "$(realpath "$0")")
- echo "Setting up the project in $PROJECT_DIR..."
- # Step 1: Create a virtual environment
- if [ ! -d "$PROJECT_DIR/venv" ]; then
- echo "Creating a virtual environment..."
- python3 -m venv "$PROJECT_DIR/venv"
- else
- echo "Virtual environment already exists."
- fi
- # Step 2: Activate the virtual environment
- echo "Activating the virtual environment..."
- source "$PROJECT_DIR/venv/bin/activate"
- # Step 3: Install dependencies
- echo "Installing dependencies..."
- pip install --upgrade pip
- pip install -r "$PROJECT_DIR/requirements.txt"
- # Ensure Gunicorn is installed
- if ! "$PROJECT_DIR/venv/bin/gunicorn" --version &>/dev/null; then
- echo "Installing Gunicorn..."
- pip install gunicorn
- else
- echo "Gunicorn is already installed."
- fi
- # Step 4: Create a systemd service
- SERVICE_FILE="/etc/systemd/system/gogmilestone.service"
- if [ ! -f "$SERVICE_FILE" ]; then
- echo "Creating systemd service..."
- sudo bash -c "cat > $SERVICE_FILE" <<EOL
- [Unit]
- Description=Gunicorn instance to serve gogmilestone
- After=network.target
- [Service]
- User=$USER
- Group=www-data
- WorkingDirectory=$PROJECT_DIR
- Environment="PATH=$PROJECT_DIR/venv/bin"
- ExecStart=$PROJECT_DIR/venv/bin/gunicorn -w 4 -b 0.0.0.0:4001 gogmilestone2:app
- [Install]
- WantedBy=multi-user.target
- EOL
- echo "Reloading systemd daemon..."
- sudo systemctl daemon-reload
- echo "Enabling gogmilestone service..."
- sudo systemctl enable gogmilestone
- echo "Starting gogmilestone service..."
- sudo systemctl start gogmilestone
- echo "Service created and started successfully."
- else
- echo "Service already exists. Skipping service creation."
- fi
- 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."
|