Skip to content

__file: --prechange parameter? #78

@sideeffect42

Description

@sideeffect42

Sometimes, when I use __file to put config files onto the target, I want to run a tool/script to check if the contents of the file are valid before reloading the service using the config and possibly breaking it.

Currently, it is possible to trigger a service reload conditionally using --onchange 'checkconf && service reload'.
However, checkconf is only executed after the config file was copied to the target.
The service will not be reloaded immediately, but the service will likely fail to come up on the next reboot at the latest.

So my idea would be to add a --prechange parameter to __file which, if set, makes the __file type only copy the file to the destination if the command given in --prechange exits with status 0.

Example use case:

__file /etc/service/config \
	--owner 0 --group 0 --mode 0644 \
	--source "${__files:?}/someconfig" \
	--prechange "checkconf-cmd %s" \
	--onchange "/etc/init.d/service reload"

I'm not sure about %s yet. Complex commands may have to use the path multiple times, or some services might not have the possibility to use an arbitrary path to check.
Maybe a "try or undo" logic would need to be implemented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions