#!/bin/sh
source /etc/profile
yum list installed | grep salt-minion
install_status=`echo $?`
localhostname=`hostname`
if [ $install_status == 0 ];then
saltid=`cat /etc/salt/minion | grep -v '#' | grep id | sed 's/id: //g'`
if [ "$saltid" == "$localhostname" ];then
service salt-minion status
runstatus=`echo $?`
if [ $runstatus != 0 ];then
echo "salt-minion is running"
exit 0
else
service salt-minion start
service salt-minion status
runstatus=`echo $?`
if [ $runstatus == 0 ];then
echo "salt-minion start sucessfully"
exit 0
else
echo "salt-minion start fail"
exit 0
fi
fi
else
mv /etc/salt/minion /etc/salt/minion_bak
echo "id: "$localhostname >> /etc/salt/minion
echo "user: root" >> /etc/salt/minion
echo "master : 10.44.86.222" >> /etc/salt/minion
echo "master_port: 4506" >> /etc/salt/minion
echo "backup_mode: minion" >> /etc/salt/minion
echo "output: nested" >> /etc/salt/minion
echo "acceptance_wait_time: 10" >> /etc/salt/minion
echo "acceptance_wait_time_max: 0" >> /etc/salt/minion
echo "random_reauth_delay: 60" >> /etc/salt/minion
service salt-minion status
runstatus=`echo $?`
if [ $runstatus == 0 ];then
service salt-minion restart
service salt-minion status
runstatus=`echo $?`
if [ $runstatus == 0 ];then
echo "salt-minion restart sucessfully"
exit 0
else
echo "salt-minion restart fail"
exit 0
fi
else
service salt-minion start
service salt-minion status
runstatus=`echo $?`
if [ $runstatus == 0 ];then
echo "salt-minion start sucessfully"
exit 0
else
echo "salt-minion start fail"
exit 0
fi
fi
fi
else
yum install -y salt-minion
mv /etc/salt/minion /etc/salt/minion_bak
echo "id: "$localhostname >> /etc/salt/minion
echo "user: root" >> /etc/salt/minion
echo "master : 10.44.86.222" >> /etc/salt/minion
echo "master_port: 4506" >> /etc/salt/minion
echo "backup_mode: minion" >> /etc/salt/minion
echo "output: nested" >> /etc/salt/minion
echo "acceptance_wait_time: 10" >> /etc/salt/minion
echo "acceptance_wait_time_max: 0" >> /etc/salt/minion
echo "random_reauth_delay: 60" >> /etc/salt/minion
service salt-minion start
service salt-minion status
runstatus=`echo $?`
if [ $runstatus == 0 ];then
echo "salt-minion start sucessfully"
exit 0
else
echo "salt-minion start fail"
exit 0
fi
fi