Xicheng Chang 2d8b4a210a Remove first-boot.json and related code in chef snippet
Change-Id: I8832b8deee3c895d87c0559f74e41a2991a018d5
2014-04-08 18:59:28 +00:00

87 lines
1.6 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
while true; do
pgrep chef-client
if [ "\$?" == "0" ]; then
exit 1
fi
chef-client -L /var/log/chef-client.log &> /tmp/chef.log
if [ "\$?" != "0" ]; then
sleep 1m
else
break
fi
done
#end raw
EOF
cat << EOF > /etc/chef/rerun.sh
#raw
#!/bin/bash
pgrep chef-client
if [ "\$?" == "0" ]; then
exit 1
fi
chef-client &> /tmp/chef.log
#end raw
EOF
## 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
#if $getVar('ntp_server', '') != ""
echo "old date is: \`date\`" 2>&1 > /tmp/ntp.log
echo "path: \$PATH" 2>&1 >> /tmp/ntp.log
/sbin/service ntpd stop 2>&1 >> /tmp/ntp.log
/usr/sbin/ntpdate $server 2>&1 >> /tmp/ntp.log
/sbin/service ntpd start 2>&1 >> /tmp/ntp.log
echo "new date is: \`date\`" 2>&1 >> /tmp/ntp.log
#end if
chmod +x /etc/chef/firstrun.sh
chmod +x /etc/chef/rerun.sh
/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