Commit 76238359 authored by Seblu's avatar Seblu
Browse files

systemd-analyze wants systemd finished to boot

When called from mailboot.service, the systemd-analyze output was missing
because systemd-analyze print the following line on stderr (not in mail):
Bootup is not yet finished. Please try again later.

To workaround this, we will test systemd-analyze during a configurable time.
If systemd-analyze is not ready at the time left, the information will be
ignored.

systemd unit type is now Tyep=idle, to:
- don't block (particulary when waiting systemd-analyze)
- we don't need to be executed fastly (we can be more fair than Type=simple).
parent 7ba1088d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -5,3 +5,8 @@
## It's a bash array. You can specify more than one email address
## default is: targets=('root')
#targets=('root' 'root@localhost.42')

## systemd-analyze needs to wait user login is available
## default values are 5s interval and 10 retries
#systemd_analyze_retry=10
#systemd_analyze_interval=5
+20 −4
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@
VERSION=@VERSION@

# default settings
targets=('root')
declare -a targets=('root')
declare -i systemd_analyze_retry=10
declare -i systemd_analyze_interval=5

# source config file if exists
[[ -r @sysconfdir@/mailboot.conf ]] && source @sysconfdir@/mailboot.conf
@@ -37,6 +39,22 @@ print_version() {
    echo $VERSION
}

# systemd-analyse detects if systemd has finished to boot up
# we try during 60s to have a valid answer.
print_systemd-analyze() {
    declare -i count=0
    while (($count <= $systemd_analyze_retry)); do
        if systemd-analyze &>/dev/null; then
            echo
            systemd-analyze
            echo
            return
        fi
        count+=1
        sleep $systemd_analyze_interval
    done
}

print_mail() {
    source /etc/os-release

@@ -50,9 +68,7 @@ print_mail() {
    echo "Kernel is $(uname -s) $(uname -r) on $(uname -m)"
    echo
    echo "System is up since $(date -d "$(uptime -s)" -R)"
    echo
    echo "$(systemd-analyze)"
    echo
    print_systemd-analyze
    echo 'Last:'
    last -5 -FRwx|head -n 5
    echo
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ Description=Send report mail at boot
After=network.target

[Service]
Type=oneshot
Type=idle
ExecStart=@bindir@/mailboot -s

[Install]