Created
September 17, 2015 16:22
-
-
Save gabtastic/bcb3891472056d747af3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Supervisor Agent Easy install | |
# Execute like this: | |
# curl -k https://gist.githubusercontent.com/gabtastic/9bc87fc469e56f497795/raw/2e6b6d5c3879b70bf2022fc292a39cae74133268/bootstrap.sh -s | sh | |
hostname=`hostname` | |
function installpackage { | |
echo "Installing $1" | |
if rpm -q $1 > /dev/null; | |
then | |
echo " $1 package already installed ..." | |
else | |
yum install -y $1 > /dev/null; | |
fi | |
} | |
function removepackage { | |
if rpm -q $1 > /dev/null; | |
then | |
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 | |
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 | |
installpackage fping | |
# Start REDIS | |
chkconfig redis on | |
/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' | |
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' | |
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" | |
export KAYAKO_API_KEY="3115DAFE-3B3D-5B20-991C-A49V6518CAC9" | |
' | |
fi | |
# Supervisor Agent Connect wrapper | |
bash -c 'cat << EOF > /usr/local/bin/supervisor_agent_connect | |
#!/bin/bash | |
source /etc/profile.d/panorama.sh | |
export PATH=$PATH:/usr/local/bin:/usr/sbin | |
export LANG=en_US.UTF-8 | |
exec /usr/bin/supervisor_agent -c /etc/ihotel/supervisor_agent.json -l /var/log/iHotel/supervisor_connect.log connect | |
' | |
# Supervisor Agent Scheduler wrapper | |
bash -c 'cat << EOF > /usr/local/bin/supervisor_agent_scheduler | |
#!/bin/bash | |
source /etc/profile.d/panorama.sh | |
export PATH=$PATH:/usr/local/bin:/usr/sbin | |
export LANG=en_US.UTF-8 | |
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 | |
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 | |
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" | |
gem install supervisor-agent --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