Skip to content

Commit

Permalink
added draft systemd services
Browse files Browse the repository at this point in the history
  • Loading branch information
benjym committed Jul 26, 2024
1 parent 31ba4a6 commit e5ed723
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
dist/
.DS_Store
.DS_Store
*.log
__pycache__/
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Augmented reality city project. [See the live version here](https://transportlab
2. three.js scene rendered in chrome sent to a projector
3. flask server to communicate between the components
4. traffic assignment simulation
5. systemd services to start everything on boot (see`SETUP_INSTRUCTIONS.md`)

## Installation
1. Download or clone this repository
1. Download or clone this repository. Save it into `/opt/ARCity/`.
2. Set up the zed camera SDK by following the instructions [here](https://www.stereolabs.com/developers/release/)
2. Install `python3` and make sure you have the required packages by running `pip install -r requirements.txt`
3. Open a terminal and `cd` to the directory you saved this repository
4. In the terminal, run the local server with `FLASK_APP=app.py` then `flask run` OR if that doesn't work, try `python app.py`
5. Open Google Chrome (or possibly Firefox, but untested)
6. In Chrome, go to the following URL: `http://localhost:5000/src/index.html`
3. Install `python3` and make sure you have the required packages by running `pip install -r requirements.txt`
4. Follow instructions in `SETUP_INSTRUCTIONS.md` to set up the systemd services.
5. Reboot the computer and everything should start automatically.


## Usage
Many system parameters are controlled by URL flags, which can be used as, e.g.:
Expand Down
13 changes: 13 additions & 0 deletions SETUP_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How this works
I have the following systemd services running:
1. Send a webhook on reboot (ARCity-webhook.service)
2. Run webpack (ARCity-webpack.service)
3. Run the server (ARCity-server.service)
4. Open firefox fullscreen in kiosk mode (ARCity-browser.service)
5. Check the github repo for updates and pull them (ARCity-auto-git-pull.service & ARCity-auto-git-pull.timer)

These need to be copied across to `/etc/systemd/system/` and then enabled and started with `systemctl enable <service-name>`. The git pull service doesnt need to be enabled, just the timer.

We also need to set up the BIOS to restart the computer when it loses power. This is done by going into the BIOS (keep pushing F2 after restart) and setting the power loss option to restart.

In principle from then everything should just work!
File renamed without changes.
8 changes: 8 additions & 0 deletions sys/ARCity-auto-git-pull.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Auto Git Pull Service
After=network.target

[Service]
Type=simple
ExecStart=/opt/ARCity/auto-pull.sh
WorkingDirectory=/opt/ARCity/
10 changes: 10 additions & 0 deletions sys/ARCity-auto-git-pull.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Run Git Auto Pull every 5 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=ARCity-auto-git-pull.service

[Install]
WantedBy=timers.target
16 changes: 16 additions & 0 deletions sys/ARCity-browser.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Start browser fullscreen
Wants=network-online.target
Requires=graphical.target
After=network-online.target ARCity-server.service

[Service]
Environment=DISPLAY=:0.0
Environment=XAUTHORITY=/home/%u/.Xauthority
Type=simple
ExecStart=firefox -kiosk http://localhost:8080
Restart=on-abort

[Install]
WantedBy=graphical.target

12 changes: 12 additions & 0 deletions sys/ARCity-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=ARCity communications server
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
WorkingDirectory=/opt/ARCity/
ExecStart=npx nodemon /opt/ARCity/src/js/server.js

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions sys/ARCity-webhook.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Startup webhook
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
User=smartcity
WorkingDirectory=/opt/ARCity/
ExecStart=/opt/ARCity/sys/webhook.sh
ExecStartPost=/opt/ARCity/sys/start_kiosk.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions sys/ARCity-webpack.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Startup webhook
Wants=network-online.target
After=network-online.target

[Service]
Type=simpley
WorkingDirectory=/opt/ARCity/
ExecStart=npx webpack serve

[Install]
WantedBy=multi-user.target
7 changes: 7 additions & 0 deletions sys/auto-pull.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Navigate to the directory of your Git repository
cd /opt/ARCity || exit

# Pull the latest changes
git pull origin main
6 changes: 6 additions & 0 deletions sys/start_kiosk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

npx webpack serve &
npx nodemon --legacy-watch --delay 2.5 src/js/server.js &
# sleep 1
firefox -kiosk http://localhost:8080
5 changes: 5 additions & 0 deletions sys/webhook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

IPADDRESS=$(curl ifconfig.me)

curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "'"ARCity installation ${hostname} has turned back on with IP Address ${IPADDRESS} :tada:"'"}' https://mattermost.scigem.com/hooks/5cwtdg8cupds5n5hiehby75mwe

0 comments on commit e5ed723

Please sign in to comment.