Skip to content

Commit

Permalink
Replace initd with systemd (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankchhabra authored Aug 9, 2020
1 parent f3e0dc8 commit 0175adf
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 44 deletions.
9 changes: 6 additions & 3 deletions scripts/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"
Expand Down
72 changes: 36 additions & 36 deletions scripts/umbrel-os/boot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -83,15 +83,15 @@ 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)

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
Expand All @@ -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
Expand Down Expand Up @@ -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!"
}
Expand Down
20 changes: 20 additions & 0 deletions scripts/umbrel-os/services/umbrel-connection-details.service
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions scripts/umbrel-os/services/umbrel-external-storage.service
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions scripts/umbrel-os/services/umbrel-startup.service
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0175adf

Please sign in to comment.