forked from getumbrel/umbrel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mayank <mayankchhabra9@gmail.com> Co-authored-by: Aaron Dewes <aaron.dewes@web.de> Co-authored-by: Lounès Ksouri <dev@louneskmt.com>
- Loading branch information
1 parent
95e4437
commit 2fb71be
Showing
18 changed files
with
695 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
.ssh | ||
.viminfo | ||
|
||
# Python bytecode | ||
__pycache__ | ||
*.py[cod] | ||
|
||
# umbrel-dev | ||
docker-compose.override.yml | ||
|
||
|
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 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
25 changes: 25 additions & 0 deletions
25
scripts/umbrel-os/services/umbrel-status-server-iptables-update.service
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,25 @@ | ||
# Umbrel Status Server iptables Update | ||
# Installed at /etc/systemd/system/umbrel-status-server-iptables-update.service | ||
|
||
# This is needed because when Docker starts it appends its own iptables rules | ||
# after ours. This means traffic on port 80 will never arrive at a Docker container | ||
# because we always redirect it. We can remove the rule and then re-apply it so | ||
# it gets appended after the Docker rule so port 80 will only continue to be | ||
# routed to the status server until a Docker container listens on port 80. | ||
|
||
[Unit] | ||
Description=Status Server iptables Update | ||
Wants=docker.service | ||
After=docker.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/status-server/setup-iptables | ||
User=root | ||
Group=root | ||
StandardOutput=syslog | ||
StandardError=syslog | ||
SyslogIdentifier=status server iptables | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,21 @@ | ||
# Umbrel Status Server | ||
# Installed at /etc/systemd/system/umbrel-status-server.service | ||
|
||
[Unit] | ||
Description=Status Server | ||
Before=umbrel-external-storage-sdcard-update.service | ||
Before=umbrel-external-storage.service | ||
Before=umbrel-startup.service | ||
|
||
[Service] | ||
Type=exec | ||
ExecStartPre=/home/umbrel/umbrel/scripts/umbrel-os/status-server/setup | ||
ExecStart=/status-server/status-server | ||
User=root | ||
Group=root | ||
StandardOutput=syslog | ||
StandardError=syslog | ||
SyslogIdentifier=status server | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
STATUS_FILE_PATH="/umbrel-status" | ||
|
||
service_id="${1}" | ||
status="${2}" | ||
error_code="${3}" | ||
|
||
source /etc/default/umbrel 2> /dev/null | ||
if [[ -z "${UMBREL_OS:-}" ]]; then | ||
echo "Skipping status update when not on Umbrel OS" | ||
exit | ||
fi | ||
|
||
if [[ "${service_id}" == "" ]]; then | ||
echo "Error: Missing ID" | ||
exit 1 | ||
fi | ||
|
||
if [[ "${status}" == "" ]]; then | ||
echo "Error: Missing Status" | ||
exit 1 | ||
fi | ||
|
||
entry="${service_id}:${status}" | ||
|
||
if [[ "${error_code}" != "" ]]; then | ||
entry="${entry}:${error_code}" | ||
fi | ||
|
||
echo "${entry}" >> "${STATUS_FILE_PATH}" |
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 bash | ||
|
||
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../..)" | ||
BIND_MOUNT_PATH="/status-server" | ||
STATUS_FILE_PATH="/umbrel-status" | ||
|
||
# Bind mount status server to new location so we always run on the SD card | ||
echo "Bind mounting status server to ${BIND_MOUNT_PATH}..." | ||
[[ ! -d "${BIND_MOUNT_PATH}" ]] && mkdir -p "${BIND_MOUNT_PATH}" | ||
mount --bind "${UMBREL_ROOT}/scripts/umbrel-os/status-server/" "${BIND_MOUNT_PATH}" | ||
sync | ||
sleep 1 | ||
|
||
# Clear status file | ||
echo "clearing status file..." | ||
echo "" > "${STATUS_FILE_PATH}" | ||
|
||
# Append iptables rule to forward port 80 to port 8000 | ||
# The status server runs on port 8000 but this rule will route all port 80 | ||
# HTTP traffic to it. | ||
# When the Umbrel service has started Docker will overwrite this rule and | ||
# instead forward port 80 to the Umbrel HTTP server container. | ||
echo "Setting iptables rules..." | ||
"${BIND_MOUNT_PATH}/setup-iptables" |
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,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../..)" | ||
|
||
check_root () { | ||
if [[ $UID != 0 ]]; then | ||
echo "This script must be run as root" | ||
exit 1 | ||
fi | ||
} | ||
|
||
main () { | ||
check_root | ||
|
||
# Remove and then re-append iptables rule | ||
rule=(PREROUTING \ | ||
--table nat \ | ||
--proto tcp \ | ||
--dport 80 \ | ||
--jump REDIRECT \ | ||
--to-port 8000) | ||
if iptables --delete ${rule[@]} 2> /dev/null; then | ||
echo "Removed existing iptables entry." | ||
else | ||
echo "No existing iptables entry found." | ||
fi | ||
iptables --append ${rule[@]} | ||
echo "Appended new iptables entry." | ||
} | ||
|
||
main |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.