-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5 another question about booting (#6)
* first try * second try * try three * type 🐜 * Updated product URLS 👍 Fixed the cron update code. Sam Dennon // 2023 * Dumb bug in booter.py 🐜 * stumped 👎 * didn't save * Finally working correctly 👍 Sam Dennon // 2023 * moved some stuff around... really working now * ready for merge
- Loading branch information
Showing
9 changed files
with
87 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
## balenaPhono/Dockerfile.template ## | ||
## Sam Dennon//2021 ## | ||
## Sam Dennon//2023 ## | ||
|
||
# Use balena distros, they have extra Charlie Unicorn magic built in! | ||
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.9-buster | ||
# Use balena base images, they have extra Charlie Unicorn magic built in! | ||
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.10.10-bullseye | ||
|
||
# Set the working directory | ||
WORKDIR /balenaPhono | ||
|
||
# Install required packages | ||
RUN install_packages alsa-utils darkice icecast2 mime-support | ||
RUN install_packages alsa-utils darkice icecast2 mime-support curl tzdata dbus | ||
|
||
# Copy all the things | ||
COPY . ./ | ||
|
||
# Check for balena device variables, apply or set defaults... build configs | ||
RUN python3 phonoConfig.py | ||
RUN python3 /balenaPhono/phonoConfig.py | ||
|
||
# Makes stuff dynamically available in the container | ||
ENV UDEV=1 | ||
|
||
# Start the services | ||
CMD ["bash", "start.sh"] | ||
CMD ["bash", "/balenaPhono/start.sh"] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## booter/Dockerfile.template ## | ||
## Sam Dennon//2023 ## | ||
|
||
# Use balena base images, they have extra Charlie Unicorn magic built in! | ||
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.10.10-bullseye | ||
|
||
# Set the working directory | ||
WORKDIR /booter | ||
|
||
# Install required packages | ||
RUN install_packages tzdata cron dbus | ||
|
||
RUN pip install requests python-dotenv pathlib | ||
|
||
# Copy all the things | ||
COPY . ./ | ||
|
||
# Start the booter | ||
CMD ["bash", "/booter/booter.sh"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python | ||
|
||
## balenaPhono/booter.py ## | ||
## Sam Dennon // 2023 ## | ||
|
||
import os | ||
import requests | ||
from dotenv import load_dotenv | ||
from pathlib import Path | ||
|
||
|
||
dotenv_path = Path('/booter/.env') | ||
load_dotenv(dotenv_path=dotenv_path) | ||
|
||
# Get some stuff from env | ||
BALENA_SUPERVISOR_ADDRESS = os.environ['BALENA_SUPERVISOR_ADDRESS'] | ||
BALENA_SUPERVISOR_API_KEY = os.environ['BALENA_SUPERVISOR_API_KEY'] | ||
|
||
# POST variables | ||
URL = f"{BALENA_SUPERVISOR_ADDRESS}/v1/reboot?apikey={BALENA_SUPERVISOR_API_KEY}" | ||
HEADERS = {"Content-Type": "application/json"} | ||
|
||
# Send the reboot signal to the BALENA SUPERVISOR | ||
requests.post(URL, headers=HEADERS) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Need to copy the env to a .env file so the booter.py script can access | ||
# the environment variables. I could not figure out a better way to do this. | ||
env >> /booter/.env | ||
echo "Variables copied to .env" | ||
|
||
# Let's update the crond to reboot the system every 24 hours | ||
# at the time specified in the REBOOT_TIME env variable. | ||
# (defaults to 4am in the timezone specified in the TZ variable.) | ||
REBOOT_TIME="${REBOOT_TIME:=4}" | ||
INCREMENT="${INCREMENT:=0}" | ||
(echo "${INCREMENT} ${REBOOT_TIME} * * * /usr/local/bin/python /booter/booter.py > /proc/1/fd/1 2>&1") | crontab - | ||
echo "cron updated" | ||
exec cron -f |
This file contains 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