kdave / btrfsmaintenance

Scripts for btrfs maintenance tasks like periodic scrub, balance, trim or defrag on selected mountpoints or directories.
GNU General Public License v2.0
900 stars 79 forks source link

Add support for systemd timers. #36

Closed comio closed 6 years ago

comio commented 7 years ago

@kdave

Is this repo still alive? Or we need to fork to add these PR?

kdave commented 6 years ago

Alive it is, sorry for late reply. The way the timers are implemented looks ok, there's a switch for the cron/timer, etc. I'm going to merge that, with some additional documentation. Thanks.

comio commented 6 years ago

Ok. Thank you.

thkukuk commented 6 years ago

The logic in refresh_timer() is in my opinion wrong: You should not check for "daily|weekly|monthly" and else uninstall, instead you should check if the first argument is "uninstall" and only then uninstall the timers, else use the first argument as new OnCalendar argument. Else you limit the possibilities of systemd timers to three values without any benefit.

comio commented 6 years ago

interesting PoV.

Something like this?


    case "$PERIOD" in
        uninstall)
            systemctl stop "$SERVICE".timer &> /dev/null
            systemctl disable "$SERVICE".timer &> /dev/null
            rm -rf /etc/systemd/system/"$SERVICE".timer.d
            ;;
        *)
            mkdir -p /etc/systemd/system/"$SERVICE".timer.d/
            cat << EOF > /etc/systemd/system/"$SERVICE".timer.d/schedule.conf
[Timer]
OnCalendar=$PERIOD
EOF
            systemctl enable "$SERVICE".timer &> /dev/null
            systemctl start "$SERVICE".timer &> /dev/null
            ;;
    esac
super7ramp commented 6 years ago

Two things:

kdave commented 6 years ago

The first 2 patches merged and pushed to master.

kdave commented 6 years ago

The default itmer periods should be the same as in the sysconfig file.

kdave commented 6 years ago

Aha, that's just a minor issue, the timers are run indirectly from /etc/systemd/system/*.timer.d/schedule.conf with the proper period. Ok I don't know enough about the timer magic.

kdave commented 6 years ago

https://github.com/kdave/btrfsmaintenance/commit/9ac81bd7b956fb893acaa23c68df322e27b3039b a bit of documentation

kdave commented 6 years ago

Patch "Use BTRFS_{SCRUB,DEFRAG,BALANCE,TRIM}_PERIOD=none in order to disable the associated systemd timer" applied, enhanced changelog based on your oriignal comment.

kdave commented 6 years ago

All patches now applied and will be included in the next release, thanks.