Skip to content

Instantly share code, notes, and snippets.

@hunterloftis
Created June 14, 2011 21:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hunterloftis/1025903 to your computer and use it in GitHub Desktop.
Save hunterloftis/1025903 to your computer and use it in GitHub Desktop.
prepare linode server
# This should be run on a new Linode Ubuntu 32-bit image to prepare it for hosting GTG
# To start, something like this works:
# scp prepare_server.sh root@123.456.789.10:/root
# First, install basic linux utilities (compilers, git, libssl)
cd /root
apt-get update
apt-get upgrade
apt-get install build-essential git libssl-dev
# Install node v0.4.8
wget https://github.com/joyent/node/zipball/v0.4.8
unzip v0.4.8
cd joyent-node*
export JOBS=4
./configure
make
make install
cd ..
cd /opt/
# Install npm
curl http://npmjs.org/install.sh | sh
# Install mongodb
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.1.tgz
tar zxvf mongodb-linux-i686-1.8.1.tgz
mv mongodb-linux-i686-1.8.1 /opt/mongodb
mkdir -p /srv/db/mongodb
touch /srv/db/mongodb.log
mkdir /opt/bin/
mkdir /opt/config/
cd /opt/bin/
wget -O mongodb-start http://library.linode.com/assets/619-mongodb-start.sh
wget -O mongodb-stop http://library.linode.com/assets/620-mongodb-stop.sh
chmod +x *
# MongoDB Configuration
echo "
# Configuration Options for MongoDB
#
# For More Information, Consider:
# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters
# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration
dbpath = /srv/db/mongodb
logpath = /srv/db/mongodb.log
logappend = true
bind_ip = 127.0.0.1
port = 27017
fork = true
auth = true
# noauth = true
" > /opt/config/mongodb
wget -O init-deb.sh http://library.linode.com/assets/618-mongodb-init-deb.sh
mv init-deb.sh /etc/init.d/mongodb
chmod +x /etc/init.d/mongodb
/usr/sbin/update-rc.d -f mongodb defaults
adduser --system --no-create-home --disabled-login --disabled-password --group mongodb
chown mongodb:mongodb -R /srv/db/
/etc/init.d/mongodb start
# Install Redis
cd /opt/
mkdir /opt/redis
wget http://redis.googlecode.com/files/redis-2.2.8.tar.gz
tar -zxvf /opt/redis-2.2.8.tar.gz
cd /opt/redis-2.2.8/
make
cp /opt/redis-2.2.8/redis.conf /opt/redis/redis.conf.default
cp /opt/redis-2.2.8/src/redis-benchmark /opt/redis/
cp /opt/redis-2.2.8/src/redis-cli /opt/redis/
cp /opt/redis-2.2.8/src/redis-server /opt/redis/
cp /opt/redis-2.2.8/src/redis-check-aof /opt/redis/
cp /opt/redis-2.2.8/src/redis-check-dump /opt/redis/
echo "
daemonize yes
pidfile /var/run/redis.pid
logfile /var/log/redis.log
port 6379
bind 127.0.0.1
timeout 300
loglevel notice
## Default configuration options
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /opt/redis/
appendonly no
glueoutputbuf yes
" > /opt/redis/redis.conf
cd /opt/
wget -O init-deb.sh http://library.linode.com/assets/630-redis-init-deb.sh
adduser --system --no-create-home --disabled-login --disabled-password --group redis
mv /opt/init-deb.sh /etc/init.d/redis
chmod +x /etc/init.d/redis
chown -R redis:redis /opt/redis
touch /var/log/redis.log
chown redis:redis /var/log/redis.log
update-rc.d -f redis defaults
# Set up GTG repository
git init --bare /git/gtg
# Add hooks to check out the latest push into the hosting area
echo "
GIT_WORK_TREE=/var/node/gtg git checkout -f
/var/node/gtg/deploy/deploy.sh
chmod +x /var/node/gtg/server.js
" > /git/gtg/hooks/post-receive
chmod +x /git/gtg/hooks/post-receive
# Create upstart script
echo "
pre-start script
mkdir -p /var/log/node
end script
respawn
respawn limit 15 5
start on runlevel [2345]
stop on runlevel [06]
script
su - root -c \"NODE_ENV=development exec /var/node/gtg/server.js 2>&1\" >> /var/log/node/gtg.log
end script
" > /etc/init/gtg.conf
# Create hosting area
mkdir -p /var/node/gtg
echo ""
echo "Now add this server as a remote and push to it:"
echo ""
echo "git remote add myservername ssh://root@myipaddress/git/gtg"
echo "git push myservername master"
@cballou
Copy link

cballou commented Jun 15, 2011

You can save this as a private StackScript and initialize new server instances with it to have it auto run on creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment