mirror of
https://github.com/karl0ss/AnotterKiosk.git
synced 2025-04-28 18:43:41 +01:00
Merge pull request #2 from karl0ss/scheduled-reboot
logic to schedule reboot based on time in ini file
This commit is contained in:
commit
df89a6b54e
@ -2,6 +2,11 @@
|
|||||||
[general]
|
[general]
|
||||||
hostname = "kioskpi"
|
hostname = "kioskpi"
|
||||||
|
|
||||||
|
[reboot]
|
||||||
|
; can be used to set an automatic reboot on a specific time (time in 24 horus format)
|
||||||
|
enabled=0
|
||||||
|
reboot_time = 04:00
|
||||||
|
|
||||||
[screen]
|
[screen]
|
||||||
; can be used to force 1080p on 4k screens or workaround broken EDID communication
|
; can be used to force 1080p on 4k screens or workaround broken EDID communication
|
||||||
;force_resolution = "1920x1080"
|
;force_resolution = "1920x1080"
|
||||||
|
@ -78,6 +78,8 @@ systemctl enable ntpdate
|
|||||||
systemctl enable lightdm
|
systemctl enable lightdm
|
||||||
systemctl enable nginx
|
systemctl enable nginx
|
||||||
systemctl enable ssh
|
systemctl enable ssh
|
||||||
|
systemctl enable schedule-reboot.service
|
||||||
|
|
||||||
|
|
||||||
# generate a version info/build info file
|
# generate a version info/build info file
|
||||||
echo -n "Chromium version: " >> /version-info
|
echo -n "Chromium version: " >> /version-info
|
||||||
|
10
kiosk_skeleton/etc/systemd/system/schedule-reboot.service
Normal file
10
kiosk_skeleton/etc/systemd/system/schedule-reboot.service
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Schedule Reboot from kioskbrowser.ini
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/bin/schedule-reboot
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
51
kiosk_skeleton/usr/bin/schedule-reboot
Normal file
51
kiosk_skeleton/usr/bin/schedule-reboot
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
INI_FILE="/boot/kioskbrowser.ini"
|
||||||
|
REBOOT_ENABLED=$(awk -F '=' '/^\[reboot\]/ { in_reboot=1; next }
|
||||||
|
in_reboot && /^\[/ { in_reboot=0 }
|
||||||
|
in_reboot && $1 ~ /enabled/ { gsub(/ /, "", $2); print $2 }' "$INI_FILE")
|
||||||
|
|
||||||
|
REBOOT_TIME=$(awk -F '=' '/^\[reboot\]/ { in_reboot=1; next }
|
||||||
|
in_reboot && /^\[/ { in_reboot=0 }
|
||||||
|
in_reboot && $1 ~ /reboot_time/ { gsub(/ /, "", $2); print $2 }' "$INI_FILE")
|
||||||
|
|
||||||
|
if [[ "$REBOOT_ENABLED" -eq 1 ]] && [[ "$REBOOT_TIME" =~ ^[0-2][0-9]:[0-5][0-9]$ ]]; then
|
||||||
|
echo "Scheduling reboot for $REBOOT_TIME..."
|
||||||
|
|
||||||
|
TARGET_TIME=$(date -d "$REBOOT_TIME" +%s)
|
||||||
|
NOW=$(date +%s)
|
||||||
|
|
||||||
|
if [ "$TARGET_TIME" -le "$NOW" ]; then
|
||||||
|
TARGET_TIME=$(date -d "tomorrow $REBOOT_TIME" +%s)
|
||||||
|
fi
|
||||||
|
|
||||||
|
TARGET_ISO=$(date -d "@$TARGET_TIME" --iso-8601=seconds)
|
||||||
|
|
||||||
|
REBOOT_UNIT="/etc/systemd/system/reboot-at.timer"
|
||||||
|
cat <<EOF > "$REBOOT_UNIT"
|
||||||
|
[Unit]
|
||||||
|
Description=One-off reboot timer
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=$TARGET_ISO
|
||||||
|
Persistent=false
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Create the associated service
|
||||||
|
cat <<EOF > /etc/systemd/system/reboot-at.service
|
||||||
|
[Unit]
|
||||||
|
Description=Scheduled Reboot
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/sbin/reboot
|
||||||
|
EOF
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now reboot-at.timer
|
||||||
|
else
|
||||||
|
echo "Reboot not scheduled (disabled or invalid time)"
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user