-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
52 lines (43 loc) · 1.79 KB
/
deploy.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
#!/bin/bash
# Script to deploy or redeploy the application as systemd services to run on boot.
# [USAGE]
# sudo bash deploy.sh reqs # first deployment (installs Python dependencies)
# sudo bash deploy.sh # newer deployments (does not install Python dependencies)
set -e
REQS_FLAG=$1
WORK_DIR=$(pwd)
APP_DIR=/home/pi/water-level-app
# Install Python dependencies.
if [ "$REQS_FLAG" == "reqs" ]
then
pip3.11 install -r requirements.txt --break-system-packages
fi
# Copy source files to installation dir.
echo "[INFO] Copying source files to execution paths..."
[ -d "$APP_DIR" ] && rm -rf $APP_DIR
mkdir $APP_DIR
cp -r $WORK_DIR/src/ $APP_DIR
cp -r $WORK_DIR/iot/ $APP_DIR
cp -r $WORK_DIR/static/ $APP_DIR
cp -r $WORK_DIR/templates/ $APP_DIR
cp -r $WORK_DIR/level_sensor.env $APP_DIR
cp -r $WORK_DIR/level_publisher.env $APP_DIR
# Copy service files to the right location for systemd.
echo "[INFO] Installing service files..."
SYSTEMDIR="/etc/systemd/system/"
LEVEL_SENSOR_SERVICE="level_sensor.service"
LEVEL_PUBLISHER_SERVICE="level_publisher.service"
[ -d "${SYSTEMDIR}" ] || mkdir -p ${SYSTEMDIR}
cp ${LEVEL_SENSOR_SERVICE} ${LEVEL_PUBLISHER_SERVICE} ${SYSTEMDIR}
# Assert services got copied to their right location.
echo "[INFO] Verifying service files..."
SERVICE_FILE="${SYSTEMDIR}/${LEVEL_SENSOR_SERVICE}"
[ -f "$SERVICE_FILE" ] || ( echo "Missing level sensor service file in right location" && exit 1)
SERVICE_FILE="${SYSTEMDIR}/${LEVEL_PUBLISHER_SERVICE}"
[ -f "$SERVICE_FILE" ] || ( echo "Missing level publisher service file in right location" && exit 1)
# Enable services to run on boot.
echo "[INFO] Enabling services to run on boot..."
systemctl enable ${LEVEL_SENSOR_SERVICE}
systemctl restart ${LEVEL_SENSOR_SERVICE}
systemctl enable ${LEVEL_PUBLISHER_SERVICE}
systemctl restart ${LEVEL_PUBLISHER_SERVICE}