-
Notifications
You must be signed in to change notification settings - Fork 509
/
start
executable file
·197 lines (157 loc) · 5.89 KB
/
start
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
set -euo pipefail
# Start Umbrel
if [[ $UID != 0 ]]; then
echo "Umbrel must be started as root"
echo "Please re-run this script as"
echo " sudo ./scripts/start"
exit 1
fi
check_dependencies () {
for cmd in "$@"; do
if ! command -v $cmd >/dev/null 2>&1; then
echo "This script requires \"${cmd}\" to be installed"
exit 1
fi
done
}
# Check system's dependencies
check_dependencies readlink dirname ip docker docker-compose
# Check karen's dependencies
check_dependencies fswatch
# Check OTA update scripts' dependencies
check_dependencies rsync jq curl
UMBREL_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/.."
UMBREL_LOGS="${UMBREL_ROOT}/logs"
USER_FILE="${UMBREL_ROOT}/db/user.json"
REMOTE_TOR_ACCESS="false"
if [[ -f "${USER_FILE}" ]]; then
REMOTE_TOR_ACCESS=$(cat "${USER_FILE}" | jq 'has("remoteTorAccess") and .remoteTorAccess')
fi
set_status="${UMBREL_ROOT}/scripts/umbrel-os/status-server/set-status"
$set_status umbrel started
if [[ ! -d "$UMBREL_ROOT" ]]; then
echo "Root dir does not exist '$UMBREL_ROOT'"
$set_status umbrel errored umbrel-root-missing
exit 1
fi
# Configure Umbrel if it isn't already configured
if [[ ! -f "${UMBREL_ROOT}/statuses/configured" ]]; then
NGINX_PORT=${NGINX_PORT:-80} NETWORK="${NETWORK:-mainnet}" "${UMBREL_ROOT}/scripts/configure"
fi
UMBREL_UPDATE_REBOOT_PERFORMED="${UMBREL_ROOT}/statuses/umbrel-update-reboot-performed"
if [[ -f "${UMBREL_UPDATE_REBOOT_PERFORMED}" ]]; then
# Cleanup status file
rm "${UMBREL_UPDATE_REBOOT_PERFORMED}"
# Mark update status as successful
cat <<EOF > "${UMBREL_ROOT}/statuses/update-status.json"
{"state": "success", "progress": 100, "description": "", "updateTo": ""}
EOF
fi
echo
echo "======================================"
echo "============= STARTING ==============="
echo "============== UMBREL ================"
echo "======================================"
echo
echo "Setting environment variables..."
echo
# Check Umbrel OS
[[ -f "/etc/default/umbrel" ]] && source "/etc/default/umbrel"
if [[ -z "${UMBREL_OS:-}" ]]; then
export IS_UMBREL_OS="false"
else
export IS_UMBREL_OS="true"
fi
# Increase default Docker and Compose timeouts to 240s
# as bitcoin can take a long while to respond
export DOCKER_CLIENT_TIMEOUT=240
export COMPOSE_HTTP_TIMEOUT=240
cd "$UMBREL_ROOT"
echo "Starting karen..."
echo
./karen &>> "${UMBREL_LOGS}/karen.log" &
echo "Starting status monitors..."
pkill -f ./scripts/status-monitor || true
./scripts/status-monitor memory 60 &>> "${UMBREL_LOGS}/status-monitor.log" &
./scripts/status-monitor storage 60 &>> "${UMBREL_LOGS}/status-monitor.log" &
./scripts/status-monitor temperature 15 &>> "${UMBREL_LOGS}/status-monitor.log" &
./scripts/status-monitor uptime 15 &>> "${UMBREL_LOGS}/status-monitor.log" &
# Automatically update app repo every 5 minutes
# If the app repo has not yet been cloned (ie it's a fresh Umbrel install)
# Then this will do the intial pull/initialisation
./scripts/status-monitor repo 300 &>> "${UMBREL_LOGS}/status-monitor.log" &
if [[ "${IS_UMBREL_OS}" == "true" ]]; then
# Set a default value for the SD card health (healthy)
echo "false" > "${UMBREL_ROOT}/statuses/sd-card-health-status.json"
# Check the SD card health every 7 days
# ./scripts/status-monitor sd-card-health 604800 &>> "${UMBREL_LOGS}/status-monitor.log" &
fi
echo "Starting memory monitor..."
echo
./scripts/memory-monitor &>> "${UMBREL_LOGS}/memory-monitor.log" &
echo "Starting backup monitor..."
echo
./scripts/backup/monitor &>> "${UMBREL_LOGS}/backup-monitor.log" &
echo "Starting decoy backup trigger..."
echo
./scripts/backup/decoy-trigger &>> "${UMBREL_LOGS}/backup-decoy-trigger.log" &
if [[ "${@}" != *"--no-start-server"* ]]; then
echo "Starting umbreld..."
echo
pkill --full 'caxa.*umbreld' || true
./bin/umbreld --port 81 --data-directory "${UMBREL_ROOT}" &>> "${UMBREL_LOGS}/umbreld.log" &
fi
compose_files=()
if [[ "${REMOTE_TOR_ACCESS}" == "true" ]]; then
compose_files+=( "--file" "docker-compose.tor.yml" )
fi
compose_files+=( "--file" "docker-compose.yml" )
UMBREL_DEV_FILE="${UMBREL_ROOT}/.umbrel-dev"
if [[ -f "${UMBREL_DEV_FILE}" ]]; then
compose_files+=( "--file" "${UMBREL_ROOT}/docker-compose.dev.yml" )
fi
echo
echo "Starting Docker services..."
echo
docker-compose "${compose_files[@]}" up --detach --build --remove-orphans || {
echo "Failed to start containers"
$set_status umbrel errored docker-failed
exit 1
}
echo
echo "Removing status server iptables entry..."
"${UMBREL_ROOT}/scripts/umbrel-os/status-server/setup-iptables" --delete
echo
echo "Starting installed apps..."
echo
# Unlock the user file on each start of Umbrel to avoid issues
# Normally, the user file shouldn't ever be locked, if it is, something went wrong, but it could still be working
if [[ -f "${UMBREL_ROOT}/db/user.json.lock" ]]; then
echo "WARNING: The user file was locked, Umbrel probably wasn't shut down properly"
rm "${UMBREL_ROOT}/db/user.json.lock"
fi
"${UMBREL_ROOT}/scripts/app" start installed
echo
# If a backup of resolv.conf exists
# (that got created during the Umbrel update process)
# then we'll now restore this after Umbrel
# and the apps have started
# That way if e.g. a Docker image is still missing,
# we would use public DNS servers
RESOLV_CONF_FILE="/etc/resolv.conf"
RESOLV_CONF_BACKUP_FILE="/tmp/resolv.conf"
if [[ -f "${RESOLV_CONF_BACKUP_FILE}" ]]; then
cat "${RESOLV_CONF_BACKUP_FILE}" > "${RESOLV_CONF_FILE}" || true
rm --force "${RESOLV_CONF_BACKUP_FILE}" || true
fi
DEVICE_HOSTNAME="$(hostname).local"
DEVICE_IP="$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')"
TOR_HS_WEB_HOSTNAME_FILE="${UMBREL_ROOT}/tor/data/web/hostname"
echo "Umbrel is now accessible at"
echo " http://${DEVICE_HOSTNAME}"
echo " http://${DEVICE_IP}"
if [[ "${REMOTE_TOR_ACCESS}" == "true" ]] && [[ -f "${TOR_HS_WEB_HOSTNAME_FILE}" ]]; then
echo " http://$(cat "${TOR_HS_WEB_HOSTNAME_FILE}")"
fi
$set_status umbrel completed