The long way is to promise your config file, and set a class if the file
is repaired using that class to issue a restart command. Roughly
files:
"/var/cache/cfengine/etc/ntp.conf"
comment => "Copy from policy_server",
create => 'true',
copy_from => remote_cp( "${sys.workdir}/sitefiles/ntp.conf",
"${sys.policy_hub}");
"/etc/ntp.conf"
comment => "Copy from local cache. Useful if server not reachable",
create => 'true',
copy_from => local_cp( "/var/cache/cfengine/etc/ntp.conf" );
classes => if_repaired( "restart_ntp" );
"/etc/ntp.conf"
comment => "Promise perms but don't trigger a restart",
perms => mog( "640", "root", "root" );
processes:
"ntpd"
comment => "Trigger restart if process is not running",
process_select => by_name( "/usr/sbin/ntpd -p /var/run/ntpd.pid
-g -u 112:120" ),
restart_class => "restart_ntp";
commands:
restart_ntp::
"/sbin/service ntp restart"
contain => in_shell_and_silent;
Or, all this can be done using an existing framework like EFL.
methods:
"services"
usebundle => efl_service( "${sys.workdir}/inputs/efl_data/services.json" );
Where services.json contains this and other services not shown:
[
{
"config_file_src" : "/var/cfengine/sitefiles/ntp.conf",
"restart_cmd" : "${paths.path[service]} ntp restart",
"config_file" : "/etc/ntp.conf",
"server" : "list_backup.policy_servers",
"owner" : "root",
"group" : "root",
"template" : "no",
"promisee" : "Neil Watson",
"mode" : "640",
"process_regex" : "/usr/sbin/ntpd -p /var/run/ntpd.pid.*",
"encrypt" : "no",
"class" : "any"
},
....
]
For more info see:
https://github.com/evolvethinking/evolve_cfengine_freelib
--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting:
https://github.com/evolvethinking/delta_reporting
CFEngine policy:
https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim:
https://github.com/neilhwatson/vim_cf3
CFEngine support:
http://evolvethinking.com