パペット サービスの背後にあるソフトウェアを置き換えるときに、競合状態を回避しようとしています。
これを行うには、パペットはサービスを停止し、実行可能ファイルを置き換えてから、サービスを開始する必要があります。パペットにそれをさせる方法はありますか? 実行可能ファイルを置き換えてから、ステータスを確認し、必要に応じてサービスを再度開始することを推奨する方法のようです。
(この例は不自然です。実際の競合状態は、この単純なものにはほど遠いものです...)
この問題をシミュレートするために使用しているパペット マニフェストは次のとおりです。
$O = '1'
$I = '2'
exec { hi :
command => '/bin/echo "$(/bin/date +%s) puppet says hello" >> /tmp/freebird.log' ,
}
file { exe :
name => "/tmp/freebird" ,
ensure => present ,
owner => "root" ,
group => "root" ,
mode => "0555" ,
source => "/root/test-v$I" ,
}
file { init :
name => '/etc/init.d/freebird' ,
ensure => present,
owner => "root",
group => "root",
mode => "0555",
source => "/root/test.init" ,
}
service { freebird :
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
require => [ File[init], File[exe] ],
}
これがtest-v1ファイルです。test-v2ファイルは同じですが、v=2
.
#!/bin/bash
v=1
while true
do
echo "$(date +%s) $v" >> /tmp/freebird-v.log
sleep 1
done
そして init.d スクリプト:
#!/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 () {
echo "$(date +%s) $*" 1>&2
echo "$(date +%s) $*" >> /tmp/$xme.log
}
case "$1" in
(start) L $1 $xme
( /tmp/$xme &)
;;
(stop) L $1 $xme
fuser -k /tmp/$xme
;;
(status) L $1 $xme
/sbin/fuser /tmp/$xme >/dev/null 2>&1
;;
(restart) L $1 $xme
$0 stop
$0 start
;;
(*)
echo "Usage: $xme {start|stop|status|restart]"
exit 1
;;
esac