-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
47 lines (38 loc) · 1.01 KB
/
setup.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
#!/bin/sh
# Variables
VENV="venv"
WORK_DIR="$PWD"
cd ..
EXEC_API="$PWD/$VENV/bin/uwsgi --socket 0.0.0.0:8080 --protocol=http -w api:app"
EXEC_DRIVER="$PWD/$VENV/bin/python $WORK_DIR/wsleds.py"
# Python config
echo "Virtual environment creating..."
python3 -m venv "$VENV"
echo "Dependencies installing..."
"$VENV/bin/python" -m pip install -r "$WORK_DIR/requirements.txt"
# Services create
echo "Services creating..."
sudo bash -c 'cat > /etc/systemd/system/ws2811-api.service' << EOF
[Unit]
Description=WS2811 REST API
After=network.target
[Service]
User=pi
Group=www-data
WorkingDirectory=$WORK_DIR
ExecStart=$EXEC_API
Requires=ws2811-driver.service
[Install]
WantedBy=multi-user.target
EOF
sudo bash -c 'cat > /etc/systemd/system/ws2811-driver.service' << EOF
[Unit]
Description=WS2811 driver
[Service]
WorkingDirectory=$WORK_DIR
ExecStart=$EXEC_DRIVER
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable ws2811-api.service ws2811-driver.service
sudo systemctl start ws2811-api.service ws2811-driver.service