Skip to content

Instantly share code, notes, and snippets.

@braindevices
Last active December 20, 2023 17:39
Show Gist options
  • Select an option

  • Save braindevices/c5c0d0664af43164729296ca8e5a7f21 to your computer and use it in GitHub Desktop.

Select an option

Save braindevices/c5c0d0664af43164729296ca8e5a7f21 to your computer and use it in GitHub Desktop.

Revisions

  1. braindevices revised this gist Dec 20, 2023. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions systemd-timer-restart-bug.sh
    Original file line number Diff line number Diff line change
    @@ -44,20 +44,26 @@ systemctl status test-timer.timer
    systemctl status test-timer.service
    cat ${logfile}

    touch /etc/systemd/system/test-timer.service
    touch /etc/systemd/system/test-timer.timer
    # touch /etc/systemd/system/test-timer.service
    # touch /etc/systemd/system/test-timer.timer
    sleep 10
    echo "now is $(date)"
    systemctl -T -o verbose daemon-reload
    systemctl -T -o verbose stop test-timer.timer
    systemctl -T -o verbose start test-timer.timer
    sleep 1
    systemctl status --no-pager test-timer.timer
    systemctl status --no-pager test-timer.service
    cat ${logfile}

    touch /etc/systemd/system/test-timer.service
    touch /etc/systemd/system/test-timer.timer
    # touch /etc/systemd/system/test-timer.service
    # touch /etc/systemd/system/test-timer.timer
    sleep 10
    echo "now is $(date)"
    systemctl -T -o verbose daemon-reload
    systemctl -T -o verbose stop test-timer.timer
    systemctl -T -o verbose start test-timer.timer
    sleep 1
    systemctl status --no-pager test-timer.timer
    systemctl status --no-pager test-timer.service
    cat ${logfile}
  2. braindevices created this gist Dec 17, 2023.
    63 changes: 63 additions & 0 deletions systemd-timer-restart-bug.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    #!/bin/bash
    set -x
    systemctl -T -o verbose daemon-reload
    systemctl -T -o verbose disable --now test-timer.timer
    set -e
    wait_secs=20
    run_at_time=$(date -d "+${wait_secs}sec" +"%H:%M:%S")
    logfile=/tmp/test-timer-output
    if [ -f ${logfile} ]
    then
    rm ${logfile}
    fi
    cat > /etc/systemd/system/test-timer.service <<EOL
    [Unit]
    Description=Run test
    [Service]
    ExecStart=/bin/bash -c "date >> ${logfile}"
    EOL

    cat > /etc/systemd/system/test-timer.timer <<EOL
    [Unit]
    Description=A test timer at ${run_at_time}
    [Timer]
    OnCalendar=*-*-* ${run_at_time}
    Unit=test-timer.service
    [Install]
    WantedBy=timers.target
    EOL

    systemctl -T -o verbose daemon-reload
    systemctl -T -o verbose enable --now test-timer.timer

    set +e

    echo "expect run at ${run_at_time}"

    echo "now is $(date), wait ${wait_secs}secs"
    sleep ${wait_secs}
    echo "now is $(date)"
    systemctl status test-timer.timer
    systemctl status test-timer.service
    cat ${logfile}

    touch /etc/systemd/system/test-timer.service
    touch /etc/systemd/system/test-timer.timer
    sleep 10
    echo "now is $(date)"
    systemctl -T -o verbose daemon-reload
    systemctl -T -o verbose stop test-timer.timer
    systemctl -T -o verbose start test-timer.timer
    cat ${logfile}

    touch /etc/systemd/system/test-timer.service
    touch /etc/systemd/system/test-timer.timer
    sleep 10
    echo "now is $(date)"
    systemctl -T -o verbose daemon-reload
    systemctl -T -o verbose stop test-timer.timer
    systemctl -T -o verbose start test-timer.timer
    cat ${logfile}