Created
May 19, 2025 16:47
-
-
Save difome/c3db7b70755251672504beb85d47a3fb to your computer and use it in GitHub Desktop.
bot_run.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USERNAME=$(whoami) | |
WORKING_DIR=$(pwd) | |
if [ ! -d "$WORKING_DIR" ]; then | |
echo "Working directory $WORKING_DIR does not exist" | |
exit 1 | |
fi | |
VENV_DIR=$(find "$WORKING_DIR" -type d -name "venv") | |
if [ -z "$VENV_DIR" ]; then | |
echo "Creating virtual environment..." | |
python3.12 -m venv venv | |
VENV_DIR="$WORKING_DIR/venv" | |
fi | |
PYTHON_EXEC="$VENV_DIR/bin/python3.12" | |
if [ ! -f "$PYTHON_EXEC" ]; then | |
echo "Python executable not found in $VENV_DIR" | |
exit 1 | |
fi | |
# Install dependencies if requirements.txt exists | |
if [ -f "requirements.txt" ]; then | |
echo "Installing dependencies..." | |
source "$VENV_DIR/bin/activate" | |
pip install -r requirements.txt | |
fi | |
SERVICE_NAME=$(basename "$WORKING_DIR") | |
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" | |
echo "[Unit] | |
Description=$SERVICE_NAME Bot Service for $USERNAME | |
After=network.target | |
[Service] | |
User=$USERNAME | |
WorkingDirectory=$WORKING_DIR | |
ExecStart=$PYTHON_EXEC main.py | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target" | sudo tee $SERVICE_FILE | |
sudo systemctl daemon-reload | |
sudo systemctl start $SERVICE_NAME | |
sudo systemctl enable $SERVICE_NAME | |
echo "Service $SERVICE_NAME created and started successfully"% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment