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

Add trigger watch to exec command #772

Open
Hiexy opened this issue Sep 11, 2024 · 3 comments
Open

Add trigger watch to exec command #772

Hiexy opened this issue Sep 11, 2024 · 3 comments

Comments

@Hiexy
Copy link

Hiexy commented Sep 11, 2024

In the exec resource, we sometimes resort to creating a trigger to know to run some commands if a file has been modified. A trigger file is created to compare the modified time of the file and the trigger file that has been created, and then the command is run based on that check.

For example, this exec resource is complex

$watch_file = "/path/to/watch_file"
$trigger_file = "/path/to/trigger_file"

file "${trigger_file} {
        state => $const.res.file.state.exists,
}

exec "foo" {
        watchcmd => "/usr/bin/inotifywait -e modify -m ${watch_file}",
        ifcmd => "test '${virtual_file}' -nt '${trigger_file}'",
        ifshell => "/bin/bash",
        cmd => "/path/to/bin ${watch_file}",
        donecmd => "/usr/bin/touch '${trigger_file}'",
    }

Can be written like this instead

exec "foo" {
        cmd => "/path/to/some/command',
        trigger_watch => "/etc/postfix/virtual",
}

The trigger_watch option would take in a file that it should watch. Mgmt would create the trigger file, manage it, and mgmt would do the checks on that file and run the command if a change has been made.

@purpleidea
Copy link
Owner

Thanks for posting the idea!

As we write more modules, we'll see if we see this pattern over and over again, and if so, it might be worth implementing something like this!

Some technical underpinnings: We may wish to implement this as a combination of watchfiles (to watch the input file) and donecmd (to touch the mtime file which we could hide in the res $vardir) and ifcmd which we have an mtime check done automatically with golang stat.

@purpleidea
Copy link
Owner

Note watchfiles is described in #771

If we could come up with an elegant API, we may similarly want to implement an mtimeif so that we can compare mtimes without using bash.

On bikeshedding: I don't love the name trigger_watch, if we get there, we should consider what to do instead. Maybe trigger_file ? Or mtime_file or ???

@purpleidea
Copy link
Owner

(And lastly, all the autoedges magic could be done here too!)

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

No branches or pull requests

2 participants