Skip to content

Instantly share code, notes, and snippets.

@jacksoncage
Last active September 7, 2024 02:00
Show Gist options
  • Save jacksoncage/3833854 to your computer and use it in GitHub Desktop.
Save jacksoncage/3833854 to your computer and use it in GitHub Desktop.
Auto install Jenkins slave on Debian
#!/bin/bash
# Input
newhost=$1
applicationStart=$2
###
# Functions
###
updateBaseInstall() {
apt-get update
apt-get upgrade -y
DEBIAN_FRONTEND=noninteractive apt-get install -y curl sudo wget git maven2 mencoder git-core build-essential openssl libssl-dev ntp zip make gcc uuid-runtime etckeeper
echo "Common applications is now installed"
}
installJava() {
# Install Java
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" > /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" >> /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install -y oracle-java7-installer
echo "Java is now installed"
}
installPhp() {
#Install phpunit
DEBIAN_FRONTEND=noninteractive apt-get install -y phpunit php5-sqlite php5-mcrypt python-dev
# Export environment variables
export VIAACCOUNT_COMMON_PATH=/var/jenkins/workspace/ViaCommon
export VIAACCOUNT_YII_PATH=/var/jenkins/workspace/YiiFramework
}
installRuby() {
curl -L https://get.rvm.io | bash -s stable --ruby
gem install couchrest_model
gem install sass
}
installCouchApp() {
cd /tmp/
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
pip install couchapp
pip install --upgrade couchapp
echo "CouchApp is now installed"
}
installNode() {
cd /tmp/
git clone https://github.com/joyent/node.git
cd node
git checkout v0.10.21
./configure --openssl-libpath=/usr/lib/ssl
make
make test
make install
cd /tmp/
rm -rf /tmp/node
npm install -g grunt-cli bower
}
setHostname() {
newhost=$1
#Assign existing hostname to $hostn
hostn=$(cat /etc/hostname)
#change hostname in /etc/hosts & /etc/hostname
sed -i "s/$hostn/$newhost/g" /etc/hosts
sed -i "s/$hostn/$newhost/g" /etc/hostname
#display new hostname
echo "Your new hostname is $newhost"
}
setupJenkinsNode() {
cd /tmp/
wget https://gist.github.com/jacksoncage/5974695/raw/1b211823061b6a85d7e38a92d9b934c6697c7a9b/jenkins-slave
cat jenkins-slave > /etc/init.d/jenkins-slave
sed -i "s/http\:\/\/www\.domain\.com\/https\:\/\/test\.viaplay\.tv\/jenkins/g" /etc/init.d/jenkins-slave
cd /root/
wget https://gist.github.com/jacksoncage/5974695/raw/627b992e0f91ee5a6c065c27e653e4a3dd877748/jenkinsRestart.sh
sed -i "s/http\:\/\/www\.domain\.com\/https\:\/\/test\.viaplay\.tv\/jenkins/g" /root/jenkinsRestart.sh
crontab -l | sed ‘*/5 * * * * /root/jenkinsOnline.sh > /root/jenkins.log 2>&1| crontab -
# Add data runtime folder
mkdir -p /var/jenkins/workspace/data/runtime
}
startJenkinsNode() {
service jenkins-slave restart
}
installJmeter() {
cd /tmp/
wget http://apache.mirrors.spacedump.net//jmeter/binaries/apache-jmeter-2.9.tgz
tar -xvf apache-jmeter-2.9.tgz
mv apache-jmeter-2.9 /opt/
}
# Auto install Jenkins slave on Debian
echo "# Start auto install Jenkins/Jmeter node on Debian #"
setHostname "$newhost"
updateBaseInstall
installJava
installPhp
installRuby
installCouchApp
installNode
installJmeter
setupJenkinsNode
if [[ applicationStart == "jenkins" ]]; then
startJenkinsNode
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment