xiaodongwang 35e924912a run chef-client every 30min, make partition script more robust and more intelligent
Change-Id: Ic2f8a3d769a55653dff4824cd7abd1b1c92c8676
2014-01-24 22:30:13 -08:00

74 lines
1.4 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
## Generate first-boot.json
cat << EOL > /etc/chef/first-boot.json
$SNIPPET('first-boot.json')
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/rerun.sh
#raw
#!/bin/bash
pgrep chef-client
if [ "\$?" != "0" ]; then
chef-client -p /var/run/chef-client.pid -j /etc/chef/first-boot.json &> /tmp/chef.log
fi
#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/rerun.sh
/etc/chef/rerun.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