Skip to content

Instantly share code, notes, and snippets.

@gabtastic
Last active September 1, 2015 19:04
Show Gist options
  • Save gabtastic/173d1143b60b2cf2b65f to your computer and use it in GitHub Desktop.
Save gabtastic/173d1143b60b2cf2b65f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Supervisor Agent Easy install
# Execute like this:
# curl -k https://gist.githubusercontent.com/gabtastic/b9bfafc0fbda37f42729/raw -s | sh
hostname=`hostname`
function installpackage {
echo "Installing $1"
if rpm -q $1 > /dev/null;
then
echo " $1 package already installed ..."
else
sudo yum install -y $1 > /dev/null;
fi
}
function removepackage {
if rpm -q $1 > /dev/null;
then
sudo yum remove -y $1 > /dev/null;
else
echo "$1 package not installed."
fi
}
# Install gem fury repo
echo "Installing gemfury repo"
if [ ! -e /etc/yum.repos.d/gemfury.repo ]
then
sudo bash -c 'cat << EOF > /etc/yum.repos.d/gemfury.repo
[fury]
name=Gemfury Private Repo
baseurl=https://repo.fury.io/wQUZrGXsyxMh5KMQx3W4/intello/
enabled=1
gpgcheck=0
'
fi
# Remove ruby 1.8.5 if installed
yum list installed ruby |grep -q "1.9.3"
rc=$?;
if [[ $rc != 0 ]];
then
removepackage ruby
fi
# install dependencies
installpackage epel-release
installpackage libyaml
installpackage ruby.i386
installpackage rubygem-eventmachine
installpackage rubygem-websocket-extensions
installpackage rubygem-websocket-driver
installpackage rubygem-hiredis
installpackage rubygem-unf_ext
installpackage rubygem-hitimes
installpackage rubygem-mysql
installpackage redis
# Start REDIS
sudo chkconfig redis on
sudo /etc/init.d/redis start
## You should definitely have a configuration file
if [ ! -e /etc/ihotel/supervisor_agent.json ]
then
mkdir -p /etc/ihotel
echo 'Creating agent configuration'
sudo bash -c 'cat << EOF > /etc/ihotel/supervisor_agent.json
{
"device_id": "<hostname>",
"url": "https://supervisor.intello.com",
"auth_token": "3b675e29854e2c05e3a8c74384c013fe69b109c6",
"retry_delay": 5,
"distribution": "centos5",
"log_channel": "logger",
"scripts_destination": "/usr/local/bin"
}
'
fi
sed -i "s/<hostname>/`hostname`/" /etc/ihotel/supervisor_agent.json
# Your environment should be set properly
# Missing /etc/profile.d/panorama.sh
if [ ! -e /etc/profile.d/panorama.sh ]
then
echo 'You are missing the environment profile panorama.sh in /etc/profile.d'
echo 'Creating basic config'
sudo bash -c 'cat << EOF > /etc/profile.d/panorama.sh
export PEPLINK_USERNAME="admin"
export PEPLINK_PASSWORD="ihintl"
export PEPLINK_PORT="22"
export ZONEDIRECTOR_USERNAME="support"
export ZONEDIRECTOR_PASSWORD="ihintl"
'
fi
# Supervisor Agent Connect wrapper
sudo bash -c 'cat << EOF > /usr/local/bin/supervisor_agent_connect
#!/bin/bash
source /etc/profile.d/panorama.sh
export PATH=$PATH:/usr/local/bin
exec /usr/bin/supervisor_agent -c /etc/ihotel/supervisor_agent.json -l /var/log/iHotel/supervisor_connect.log connect
'
# Supervisor Agent Scheduler wrapper
sudo bash -c 'cat << EOF > /usr/local/bin/supervisor_agent_scheduler
#!/bin/bash
source /etc/profile.d/panorama.sh
export PATH=$PATH:/usr/local/bin
exec /usr/bin/supervisor_agent -c /etc/ihotel/supervisor_agent.json -l /var/log/iHotel/supervisor_scheduler.log start_scheduler
'
# Inittab entry
grep -q "666" /etc/inittab
rc=$?;
if [[ $rc != 0 ]];
then
sudo bash -c 'cat << EOF >> /etc/inittab
666:345:respawn:/usr/local/bin/supervisor_agent_connect
'
fi
# Inittab entry
grep -q "667" /etc/inittab
rc=$?;
if [[ $rc != 0 ]];
then
sudo bash -c 'cat << EOF >> /etc/inittab
667:345:respawn:/usr/local/bin/supervisor_agent_scheduler
'
fi
chmod +x /usr/local/bin/supervisor_agent_connect
chmod +x /usr/local/bin/supervisor_agent_scheduler
# Install supervisor gem ...
echo "Installing supervisor-agent gem"
sudo gem install supervisor-agent --pre --no-ri --no-rdoc --source https://[email protected]/intello/
echo "Re-reading inittab"
init q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment