-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·72 lines (56 loc) · 1.66 KB
/
install.sh
File metadata and controls
executable file
·72 lines (56 loc) · 1.66 KB
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
#!/bin/bash
set -e
SERVICE_NAME="icoapi"
MODULE_NAME="icoapi"
INSTALL_DIR="/etc/icoapi"
SERVICE_PATH="/etc/systemd/system"
FORCE_REINSTALL=false
# Check for --force flag
if [[ "$1" == "--force" ]]; then
FORCE_REINSTALL=true
echo "Forcing reinstallation: Deleting existing installation..."
fi
echo "Stopping service..."
sudo systemctl stop $SERVICE_NAME.service || true
# Handle force reinstallation
if [ "$FORCE_REINSTALL" = true ]; then
sudo rm -rf $INSTALL_DIR
fi
echo "Creating installation directory if not exists..."
sudo mkdir -p $INSTALL_DIR
sudo chown $USER:$USER $INSTALL_DIR
echo "Copying application files..."
FILES_AND_DIRS=("$MODULE_NAME" "pyproject.toml" "README.md")
for ITEM in "${FILES_AND_DIRS[@]}"; do
#cp -r "$ITEM" "$INSTALL_DIR"
rsync -av --exclude='__pycache__' "$ITEM" "$INSTALL_DIR"
done
cd $INSTALL_DIR
echo "Checking for existing virtual environment..."
if [ "$FORCE_REINSTALL" = true ] || [ ! -d "venv" ]; then
echo "Setting up virtual environment..."
python3 -m venv venv
fi
source venv/bin/activate
pip install --upgrade pip
pip install .
deactivate
echo "Ensuring systemd service exists..."
sudo bash -c "cat << EOF > $SERVICE_PATH/$SERVICE_NAME.service
[Unit]
Description=ICOapi Service
After=network.target
[Service]
WorkingDirectory=$INSTALL_DIR
ExecStart=$INSTALL_DIR/venv/bin/python $INSTALL_DIR/$MODULE_NAME/api.py
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
EOF"
echo "Reloading systemd and restarting service..."
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE_NAME.service
sudo systemctl start $SERVICE_NAME.service
echo "Checking service status..."
sudo systemctl status $SERVICE_NAME.service