Browse Source

Replace initd with systemd (#100)

mount-script-check
Mayank Chhabra 4 years ago
committed by GitHub
parent
commit
0175adf527
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      scripts/configure
  2. 72
      scripts/umbrel-os/boot
  3. 2
      scripts/umbrel-os/external-storage/is-mounted
  4. 10
      scripts/umbrel-os/external-storage/mount
  5. 20
      scripts/umbrel-os/services/umbrel-connection-details.service
  6. 19
      scripts/umbrel-os/services/umbrel-external-storage.service
  7. 25
      scripts/umbrel-os/services/umbrel-startup.service

9
scripts/configure

@ -42,7 +42,11 @@ if [ "$BITCOIN_NETWORK" != "mainnet" ] && [ "$BITCOIN_NETWORK" != "testnet" ] &&
fi
echo
echo "Configuring Umbrel for $BITCOIN_NETWORK"
if [[ -f "${UMBREL_ROOT}/statuses/configured" ]]; then
echo "Reconfiguring Umbrel for $BITCOIN_NETWORK"
else
echo "Configuring Umbrel for $BITCOIN_NETWORK"
fi
echo
@ -189,8 +193,7 @@ echo "Pulling Umbrel Docker images"
echo
docker-compose pull --quiet
# Create configured status (used by the boot script on Umbrel OS
# to check if Umbrel is configured or not)
# Create configured status
touch "$UMBREL_ROOT"/statuses/configured
echo "Configuration successful"

72
scripts/umbrel-os/boot

@ -3,49 +3,49 @@
UMBREL_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/../.."
UMBREL_OS_SCRIPTS="${UMBREL_ROOT}/scripts/umbrel-os"
# Mount and/or format external storage
"${UMBREL_OS_SCRIPTS}/external-storage-mounter" || exit 1
# Creates, enables and starts a systemd service
enable_service() {
service="${1}"
if [ ! -f "/etc/systemd/system/${service}" ]; then
echo "Setting up ${service}"
if [ ! -f "${UMBREL_OS_SCRIPTS}/services/${service}" ]; then
echo "Error: No service file found at ${UMBREL_OS_SCRIPTS}/services/${service}"
exit 1
fi
echo "Copying ${service} to /etc/systemd/system/${service}"
cp "${UMBREL_OS_SCRIPTS}/services/${service}" "/etc/systemd/system/${service}"
if [ ! -f "$UMBREL_ROOT"/statuses/configured ]; then
echo "statuses/configured not found. Looks like the first boot..."
echo "Configuring Umbrel now..."
echo "Enabling ${service}..."
systemctl enable "${service}"
echo "Starting ${service}..."
systemctl start "${service}"
fi
}
# Configure Umbrel on first boot
# We assume that it's the first boot if Umbrel hasn't been configured
if [ ! -f "${UMBREL_ROOT}/statuses/configured" ]; then
echo
echo "======================================"
echo "============ FIRST BOOT =============="
echo "=========== hello world! ============="
echo "======================================"
echo
echo "Configuring Umbrel..."
echo
if [ -f "$UMBREL_ROOT"/scripts/configure ]; then
if [ -f "${UMBREL_ROOT}/scripts/configure" ]; then
cd "$UMBREL_ROOT"
./scripts/configure || exit 1
NETWORK=mainnet ./scripts/configure || exit 1
else
echo "Error: No configuration script not found at $UMBREL_ROOT/scripts/configure"
echo "Error: No configuration script found at ${UMBREL_ROOT}/scripts/configure"
exit 1
fi
echo
echo "Configuration complete. Setting up Umbrel initd startup service..."
echo
if [ ! -f /etc/rc2.d/S01umbrel ]; then
echo "Creating multiple runlevel symlinks..."
ln -s /etc/init.d/umbrel /etc/rc0.d/K01umbrel
ln -s /etc/init.d/umbrel /etc/rc1.d/K01umbrel
ln -s /etc/init.d/umbrel /etc/rc2.d/S01umbrel
ln -s /etc/init.d/umbrel /etc/rc3.d/S01umbrel
ln -s /etc/init.d/umbrel /etc/rc4.d/S01umbrel
ln -s /etc/init.d/umbrel /etc/rc5.d/S01umbrel
ln -s /etc/init.d/umbrel /etc/rc6.d/K01umbrel
echo "Enabling service defaults..."
update-rc.d umbrel defaults || exit 1
echo "Enabling startup service..."
update-rc.d umbrel enable || exit 1
echo "Starting service now..."
/etc/init.d/umbrel start
else
echo "Umbrel initd startup service already exists..."
fi
fi
# Display connection details on the TTY
if [ -x "$(command -v umbrel-details)" ]; then
# We run this in the background because it waits for the Tor hidden service
# to be created on first boot. rc.local needs to exit so the boot process
# can continue.
umbrel-details &
fi
# Enable all services
enable_service "umbrel-external-storage.service"
enable_service "umbrel-startup.service"
enable_service "umbrel-connection-details.service"
exit 0

2
scripts/umbrel-os/is-on-external-storage → scripts/umbrel-os/external-storage/is-mounted

@ -5,6 +5,6 @@ set -euo pipefail
# This script returns a non-zero exit code if $UMBREL_ROOT is NOT
# mounted on external storage.
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../..)"
df -h "${UMBREL_ROOT}" | grep --quiet '/dev/sd'

10
scripts/umbrel-os/external-storage-mounter → scripts/umbrel-os/external-storage/mount

@ -13,7 +13,7 @@ set -euo pipefail
# - - Install Umbrel on it
# - Bind mount the external installation on top of the local installation
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../..)"
MOUNT_POINT="/mnt/data"
EXTERNAL_UMBREL_ROOT="${MOUNT_POINT}/umbrel"
@ -83,7 +83,7 @@ unmount_partition () {
main () {
echo "Running external storage mount script..."
check_root
check_dependencies sed wipefs parted mount sync
check_dependencies sed wipefs parted mount sync umount
block_devices=$(list_block_devices)
no_of_block_devices=$(list_block_devices | wc -l)
@ -91,7 +91,7 @@ main () {
if [[ $no_of_block_devices -lt 1 ]]; then
echo "No block devices found"
echo "Exiting mount script without doing anything"
exit
exit 1
fi
if [[ $no_of_block_devices -gt 1 ]]; then
@ -107,7 +107,9 @@ main () {
echo "Found device \"${block_device_model}\""
echo "Checking if device contains an Umbrel install..."
mount_partition "${partition_path}"
if [[ -f "${EXTERNAL_UMBREL_ROOT}"/.umbrel ]]; then
echo "Yes, it does"
else
@ -136,7 +138,7 @@ main () {
echo "Checking Umbrel root is now on external storage..."
sync
sleep 1
"${UMBREL_ROOT}/scripts/umbrel-os/is-on-external-storage"
"${UMBREL_ROOT}/scripts/umbrel-os/external-storage/is-mounted"
echo "Mount script completed successfully!"
}

20
scripts/umbrel-os/services/umbrel-connection-details.service

@ -0,0 +1,20 @@
# Umbrel Connection Details Logger (TTY)
# Installed at /etc/systemd/system/umbrel-connection-details.service
[Unit]
Description=Connection Details
Requires=umbrel-startup.service
After=umbrel-startup.service
[Service]
Type=oneshot
Restart=no
ExecStart=/usr/local/bin/umbrel-details
User=root
Group=root
StandardOutput=tty
TTYPath=/dev/tty1
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

19
scripts/umbrel-os/services/umbrel-external-storage.service

@ -0,0 +1,19 @@
# Umbrel External Storage Mounter
# Installed at /etc/systemd/system/umbrel-external-storage.service
[Unit]
Description=External Storage Mounter
[Service]
Type=oneshot
Restart=no
ExecStart=/home/umbrel/umbrel/scripts/umbrel-os/external-storage/mount
User=root
Group=root
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=external storage mounter
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

25
scripts/umbrel-os/services/umbrel-startup.service

@ -0,0 +1,25 @@
# Umbrel Startup Service
# Installed at /etc/systemd/system/umbrel-startup.service
[Unit]
Description=Umbrel Startup Service
Requires=umbrel-external-storage.service
After=umbrel-external-storage.service
Wants=network-online.target
After=network-online.target
Wants=docker.service
After=docker.service
[Service]
Type=forking
TimeoutSec=infinity
ExecStart=/home/umbrel/umbrel/scripts/start
User=root
Group=root
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=umbrel startup
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save