Last active
February 9, 2023 18:00
-
-
Save ferki/7c63147444aa2fe3cb2e24ebe79f0a5f to your computer and use it in GitHub Desktop.
rex_on_change_trigger_restarts_shared_var
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.012; | |
use warnings; | |
use Rex -feature => [ '1.4', 'exec_autodie' ]; | |
BEGIN { | |
use Rex::Shared::Var; | |
share qw($should_restart @services_to_restart); | |
} | |
$should_restart = FALSE; | |
@services_to_restart = (); | |
task 'configure', sub { | |
file '/etc/configfile', | |
content => 'write this into the file', | |
# source => 'upload/this/file', | |
on_change => sub { $should_restart = TRUE }; | |
}; | |
after 'configure', sub { | |
if ($should_restart) { | |
service myservice => 'restart'; | |
} | |
}; | |
task 'configure_many', sub { | |
my %service_for = ( configfile1 => 'service1', configfile2 => 'service2' ); | |
for my $configfile ( keys %service_for ) { | |
file $configfile, | |
content => 'write this into each file', | |
# source => 'upload/this/file', | |
on_change => sub { push @services_to_restart, $service_for{$configfile} }; | |
} | |
}; | |
after 'configure_many', sub { | |
for my $service (@services_to_restart) { | |
service $service => 'restart'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment