Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 bug fixes #40

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ log() {
echo -n "$(date): "
}
fi
echo "$(date_log)$1" | tee -a $SYSTEM_API_FIFO
echo "$(date_log)$1" >&2 | tee -a $SYSTEM_API_FIFO
}

start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ log() {
echo -n "$(date): "
}
fi
echo "$(date_log)$1" | tee -a $SYSTEM_API_FIFO
echo "$(date_log)$1" >&2 | tee -a $SYSTEM_API_FIFO
}

start() {
Expand Down
2 changes: 1 addition & 1 deletion recipes-core/date-sync/init
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ log() {
echo -n "$(date --iso-8601=seconds): "
}
fi
echo "$(date_log)$1" | tee -a $SYSTEM_API_FIFO
echo "$(date_log)$1" >&2 | tee -a $SYSTEM_API_FIFO
}

monitor_and_restart() {
Expand Down
4 changes: 2 additions & 2 deletions recipes-core/disk-encryption/disk-encryption.bb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ do_install() {
# Create environment file for init service
install -d ${D}${sysconfdir}/default ${D}${sysconfdir}/disk-encryption
echo "TARGET_LUN=${TARGET_LUN}
DISK_ENCRYPTION_KEY_STORAGE=${DISK_ENCRYPTION_KEY_STORAGE}" > ${D}${sysconfdir}/default/disk-encryption
if [ "$DISK_ENCRYPTION_KEY_STORAGE" = "file" ]; then
DISK_ENCRYPTION_KEY_STORAGE=${DISK_ENCRYPTION_KEY_STORAGE}" > ${D}${sysconfdir}/default/disk-encryption
if [ "${DISK_ENCRYPTION_KEY_STORAGE}" = "file" ]; then
echo "DISK_ENCRYPTION_KEY_FILE=/etc/disk-encryption/key" >> ${D}${sysconfdir}/default/disk-encryption
install -m 0644 ${WORKDIR}/disk-encryption-key.mustache ${D}${sysconfdir}/disk-encryption/key.mustache
fi
Expand Down
32 changes: 23 additions & 9 deletions recipes-core/disk-encryption/init
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -eux -o pipefail
set -eu -o pipefail

### BEGIN INIT INFO
# Provides: disk-encryption
Expand Down Expand Up @@ -34,20 +34,33 @@ log() {
echo -n "$(date): "
}
fi
echo "$(date_log)$1" | tee -a $SYSTEM_API_FIFO $LOGFILE
echo "$(date_log)$1" >&2 | tee -a $SYSTEM_API_FIFO $LOGFILE
}

find_target_disk() {
local target_path
local attempt=0
local max_attempts=30
local wait_interval=10

# Try to find disk by LUN with retries
while [ $attempt -lt $max_attempts ]; do
target_path=$(readlink -f /dev/disk/by-path/*scsi-0:0:0:${TARGET_LUN} 2>/dev/null || true)

if [ -n "$target_path" ] && [ -b "$target_path" ]; then
log "Found target disk at ${target_path} using LUN ${TARGET_LUN}"
echo "$target_path"
return 0
fi

# First try to find disk by LUN
target_path=$(readlink -f /dev/disk/by-path/*scsi-0:0:0:${TARGET_LUN} 2>/dev/null || true)
attempt=$((attempt + 1))
if [ $attempt -lt $max_attempts ]; then
log "Attempt ${attempt}/${max_attempts}: Waiting ${wait_interval} seconds for target disk to become available..."
sleep $wait_interval
fi
done

if [ -n "$target_path" ] && [ -b "$target_path" ]; then
log "Found target disk at ${target_path} using LUN ${TARGET_LUN}"
echo "$target_path"
return 0
fi
log "Target disk not found after ${max_attempts} attempts, falling back to largest disk detection"

# Fallback: Simply find largest disk
local largest_disk
Expand Down Expand Up @@ -167,6 +180,7 @@ start() {
fi
log "Using disk: ${TARGET_DISK}"

exit_code=0
KEY=$(get_key) || exit_code=$?
if [ $exit_code -ne 0 ] || [ -z "$KEY" ]; then
if [ "$DISK_ENCRYPTION_KEY_STORAGE" = "tpm2" ]; then
Expand Down
2 changes: 1 addition & 1 deletion recipes-core/system-api-fake-fifo/system-api-fake-fifo.bb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LICENSE = "CLOSED"

FILESEXTRAPATHS:prepend := "${THISDIR}:"

SRC_URI += "file://init"
SRC_URI += "file://system-api-fake-fifo"

INITSCRIPT_NAME = "system-api-fake-fifo"
INITSCRIPT_PARAMS = "defaults 60"
Expand Down
10 changes: 6 additions & 4 deletions recipes-core/system-api/files/system-api-init
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ log() {
echo -n "$(date): "
}
fi
echo "$(date_log)$1" | tee -a $SYSTEM_API_FIFO
echo "$(date_log)$1" >&2 | tee -a $SYSTEM_API_FIFO
}

start() {
mkdir -p /persistent/rbuilder /persistent/system-api
mv $SYSTEM_API_FIFO $SYSTEM_API_FIFO.bak
log "Starting $NAME"
start-stop-daemon -S --make-pidfile -p $PIDFILE -m -b -a $DAEMON -- $DAEMON_ARGS > $LOGFILE 2>&1
mv $SYSTEM_API_FIFO $SYSTEM_API_FIFO.bak
start-stop-daemon -S --make-pidfile -p $PIDFILE -m -b --exec /bin/sh -- -c "exec $DAEMON $DAEMON_ARGS >> $LOGFILE 2>&1"
# Wait for the service to start
sleep 2
cat $SYSTEM_API_FIFO.bak > $SYSTEM_API_FIFO
rm $SYSTEM_API_FIFO.bak
rm -f $SYSTEM_API_FIFO.bak
chmod 644 $LOGFILE
log "Started $NAME"
}

stop() {
rm -f $SYSTEM_API_FIFO
log "Stopping $NAME"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ basic_auth_secret_salt = "1_drink_coffee:|"
# TLS configuration
tls_enabled = true
tls_create_if_missing = true
tls_cert_hosts = "127.0.0.1,localhost,{{public_ip}},{{dns_name}}"
tls_cert_hosts = ["127.0.0.1,localhost,{{public_ip}},{{dns_name}}"]
tls_cert_path = "/persistent/system-api/cert.pem"
tls_key_path = "/persistent/system-api/key.pem"

Expand Down