Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__file: --prechange parameter? #78

Open
sideeffect42 opened this issue May 28, 2023 · 0 comments
Open

__file: --prechange parameter? #78

sideeffect42 opened this issue May 28, 2023 · 0 comments

Comments

@sideeffect42
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant