On Tuesday, July 29, 2014 7:58:32 AM UTC-5, Satish Katuru wrote:
Hi
Here is my flow:
Stop service-->copy required files from Master server-->Start service
Once this is done,I am taking a copy of files on Master Server and removing the files from original location.
Why? It would be easier and better to leave the master copy where it is on the master.
I wanted to add this condition (if files are not there at that location no need stop and restart the service )
The reason behind this question is for every 30 minutes deployment will be done on agent machine automatically.I just wanted to make sure that if files are there then only I have to stop and start the service.
To begin, if you (may) need to stop and start the service at different points in the run, then you will need to use an Exec for one of those points. The stop would be a better one to do that way. The result would be something like this:
exec { 'Stop myservice to deploy new files':
command => 'service myservice stop',
path => '/usr/bin:/bin:/usr/sbin:/sbin'
# ... see below ...
}
->
file { '/var/myservice/deployed_file':
source => 'puppet:///modules/mymodule/deployed_file'
}
->
service { 'myservice':
ensure => 'running'
}
Having set up something along those lines, your question boils down to how to avoid executing the Exec's command if file deployment is not going to happen. Well, the Exec resource type has parameters 'onlyif' and 'unless' that it can use to determine whether the command needs to be run. The case you describe is a simple one: you can simply test for the existence of your deployed file:
...
unless => 'test -e /var/myservice/deployed_file'
...
Note that this general strategy doesn't work well if you remove the deployment file from the master. If you do, then the File resource will fail on every run, and the Service will not be ensured running (though it may be running anyway).
John