From f49134271e6b719733dbf8d6cf7bc762cd4eac61 Mon Sep 17 00:00:00 2001 From: xiaodongwang Date: Wed, 3 Dec 2014 11:55:01 -0800 Subject: [PATCH] avoid multi chef client run starts Change-Id: Ie676e4200f2ce4574d53021b28b6c000641645ea Closes-Bug: 1398963 --- cobbler/snippets/kickstart_chef_run.sh | 11 ++++++++++- cobbler/snippets/kickstart_pre_anamon | 8 ++++---- cobbler/snippets/preseed_chef_run.sh | 11 ++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cobbler/snippets/kickstart_chef_run.sh b/cobbler/snippets/kickstart_chef_run.sh index aca8b4a..1652d01 100644 --- a/cobbler/snippets/kickstart_chef_run.sh +++ b/cobbler/snippets/kickstart_chef_run.sh @@ -24,10 +24,19 @@ cat << EOF > /etc/chef/chef_client_run.sh #!/bin/bash touch /tmp/chef.log +PIDFILE=/tmp/chef_client_run.pid +if [ -f \\$PIDFILE ]; then + pid=\\$(cat \\$PIDFILE) + if [ -f /proc/\\$pid/exe ]; then + echo "there are chef_client_run.sh running with pid \\$pid" &>> /tmp/chef.log + exit 1 + fi +fi +echo \\$$ > \\$PIDFILE while true; do echo "run chef-client on \`date\`" &>> /tmp/chef.log clients=\\$(pgrep chef-client) - if [ "\\$?" == "0" ]; then + if [[ "\\$?" == "0" ]]; then echo "there are chef-clients '\\$clients' running" &>> /tmp/chef.log break else diff --git a/cobbler/snippets/kickstart_pre_anamon b/cobbler/snippets/kickstart_pre_anamon index 179919c..70b8469 100644 --- a/cobbler/snippets/kickstart_pre_anamon +++ b/cobbler/snippets/kickstart_pre_anamon @@ -1,9 +1,9 @@ #if $str($getVar('anamon_enabled','')) == "1" -#if $getVar("compass_server", "") != "" + #if $getVar("compass_server", "") != "" wget -O /tmp/anamon "http://$compass_server:$http_port/cobbler/aux/anamon" python /tmp/anamon --name "$name" --server "$compass_server" --port "$http_port" -#else + #else wget -O /tmp/anamon "http://$server:$http_port/cobbler/aux/anamon" -python /tmp/anamon --name "$name" --server "$_server" --port "$http_port" -#end if +python /tmp/anamon --name "$name" --server "$server" --port "$http_port" + #end if #end if diff --git a/cobbler/snippets/preseed_chef_run.sh b/cobbler/snippets/preseed_chef_run.sh index 46699f9..be1d3b8 100644 --- a/cobbler/snippets/preseed_chef_run.sh +++ b/cobbler/snippets/preseed_chef_run.sh @@ -23,10 +23,19 @@ cat << EOF > /etc/chef/chef_client_run.sh #!/bin/bash touch /tmp/chef.log +PIDFILE=/tmp/chef_client_run.pid +if [ -f \\$PIDFILE ]; then + pid=\\$(cat \\$PIDFILE) + if [ -f /proc/\\$pid/exe ]; then + echo "there are chef_client_run.sh running with pid \\$pid" &>> /tmp/chef.log + exit 1 + fi +fi +echo \\$$ > \\$PIDFILE while true; do echo "run chef-client on \`date\`" &>> /tmp/chef.log clients=\\$(pgrep chef-client) - if [ "\\$?" == "0" ]; then + if [[ "\\$?" == "0" ]]; then echo "there are chef-clients '\\$clients' running" &>> /tmp/chef.log break else