I will rephrase the question for clarity and search, and then provide a solution.
I would suggest, however, that if you have the opportunity to do this, use the pre-installation function of your own packaging system.
Q: How to emulate rpm before installing the script through the puppet. One use case is to stop the puppet service before installing the executable, and then run it again after replacing the file. This is contrary to the normal puppet file replacement order, and then restart the service.
Fortunately, my use case already requires a mess of symbolic links. If you do not, submit your decision.
To run a test consisting of the files below, I edit $tversion
in test.pp and paste it into my terminal:
fuser /tmp/freebird-v.log /tmp/freebird : > /tmp/freebird.log echo ==== >> /tmp/freebird.log ; puppet apply --verbose --onetime --no-daemonize test.pp 2>&1 | tee ~/D ; cat /tmp/freebird.log ps auxww|grep freebird fuser /tmp/freebird-v.log /tmp/freebird
File test.pp:
$tversion = '1' exec { hi : command => '/bin/echo "$(/bin/date +%s) puppet says hello" >> /tmp/freebird.log' , } file { exe : name => "/tmp/freebird-v$tversion" , ensure => present , owner => "root" , group => "root" , mode => "0555" , content => template("/root/test-template") , } file { exe_ln : name => "/tmp/freebird" , ensure => link , owner => "root" , group => "root" , mode => "0555" , target => "/tmp/freebird-v$tversion" , } file { init : name => '/etc/init.d/freebird' , ensure => present, owner => "root", group => "root", mode => "0555", source => "/root/test.init" , } exec { freebird_stop_if_incoherent : command => '/sbin/service freebird stop' , refreshonly => false ,
File template file:
#!/bin/bash v=<%= tversion %> while true do echo "$(date +%s) $v" >> /tmp/freebird-v.log sleep 1 done
File test.init:
#!/bin/bash # # /etc/rc.d/init.d/freebird # chkconfig: 2345 90 10 # description: freebird # Provides: freebird # Required-Start: $syslog $remote_fs # Should-Start: # Required-Stop: $syslog $remote_fs # Should-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: freebird # Source function library. . /etc/rc.d/init.d/functions xme=freebird export PATH=/sbin:/bin:/usr/sbin:/usr/bin function L () { local pid=$$ local ppid=$(ps l $pid |awk '{print $4}' |tail -1) local extra="-- $(ps $ppid|tail -1|sed 's,^[^/]*/,/, ; s,/[0-9][^/]*/,/,')" echo "$(date +%s) $pid $ppid $* $extra" 1>&2 echo "$(date +%s) $pid $ppid $* $extra" >>/tmp/$xme.log 2>&1 } case "$1" in (start) L $1 $xme fuser /tmp/$xme >/dev/null 2>&1 || ( /tmp/$xme &) ;; (stop) L $1 $xme fuser /tmp/$xme 2>&1 fuser -k /tmp/$xme 1>&2 ||true fuser /tmp/$xme 2>&1 true ;; (status) L $1 $xme /sbin/fuser /tmp/$xme >/dev/null 2>&1 ;; (restart) L $1 $xme fuser -k /tmp/$xme 1>&2 ||true ( /tmp/$xme &) ;; (*) echo "Usage: $xme {start|stop|status|restart]" exit 1 ;; esac