xiaodongwang 41676f96c9 update cobbler snippets
Change-Id: I74a4c844da915a51cc714c5a30919f5863e7ae26
2014-04-14 11:36:07 -07:00

91 lines
1.9 KiB
Plaintext

## Generate client.rb
mkdir -p /etc/chef
## Generate validation.pem
cat << EOL > /etc/chef/validation.pem
$SNIPPET('chef-validator.pem')
EOL
cat << EOL > /etc/chef/client.rb
$SNIPPET('client.rb')
EOL
## Register Server in Rsyslog
cat << EOL > /etc/rsyslog.d/chef.conf
$SNIPPET('rsyslogchef')
EOL
cat << EOL > /etc/rsyslog.conf
$SNIPPET('rsyslogconf')
EOL
service rsyslog restart
cat << EOF > /etc/chef/firstrun.sh
#raw
#!/bin/bash
touch /tmp/chef.log
while true; do
echo "firstrun chef-client on `date`" &>> /tmp/chef.log
clients=\$(pgrep chef-client)
if [ "\$?" == "0" ]; then
echo "there are chef-clients '\$clients' running" &>> /tmp/chef.log
sleep 1m
else
chef-client -L /var/log/chef-client.log &>> /tmp/chef.log
if [ "\$?" != "0" ]; then
echo "chef-client run failed" &>> /tmp/chef.log
sleep 1m
else
echo "chef-client run success" &>> /tmp/chef.log
break
fi
fi
done
#end raw
EOF
cat << EOF > /etc/chef/rerun.sh
#raw
#!/bin/bash
echo "rerun chef-client on `date`" &>> /tmp/chef.log
clients=\$(pgrep chef-client)
if [ "\$?" == "0" ]; then
echo "there are chef-clients '\$clients' running" &>> /tmp/chef.log
exit 1
fi
chef-client &>> /tmp/chef.log
if [ "\$?" != "0" ]; then
echo "chef-client run failed" &>> /tmp/chef.log
else
echo "chef-client run success" &>> /tmp/chef.log
fi
#end raw
EOF
chmod +x /etc/chef/firstrun.sh
chmod +x /etc/chef/rerun.sh
## A self-destruct service to boot chef client and register cron job
cat << EOF > /etc/init.d/chef
#!/bin/bash
# chkconfig: 2345 95 20
# description: Description of the script
# processname: chef-agent
/etc/chef/firstrun.sh
crontab -l > mycron
echo "*/30 * * * * /etc/chef/rerun.sh" >> mycron
crontab mycron
rm mycron
chkconfig chef off
mv /etc/init.d/chef /tmp/chef
EOF
chmod +x /etc/init.d/chef
chkconfig --level 2345 chef on