Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@reddit
Created December 13, 2010 01:10
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save reddit/738525 to your computer and use it in GitHub Desktop.
Save reddit/738525 to your computer and use it in GitHub Desktop.
reddit installation script draft
#!/bin/bash -e
# Neil Williams, reddit
REDDITUSER=reddit
REDDITHOME=/home/reddit
GITREPO=git://github.com/reddit/reddit.git
APTITUDE_OPTIONS="-y" # limit bandwidth: -o Acquire::http::Dl-Limit=100"
# make sure we're running as root
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi
# add some external ppas for packages
DEBIAN_FRONTEND=noninteractive aptitude install $APTITUDE_OPTIONS python-software-properties
apt-add-repository ppa:cassandra-ubuntu/stable
apt-add-repository ppa:jason-alioth/reddit
# install prerequisites
aptitude update
DEBIAN_FRONTEND=noninteractive aptitude install $APTITUDE_OPTIONS g++ python-dev python-setuptools python-profiler python-imaging cython git-core subversion libpng12-dev libjpeg62-dev libfreetype6-dev libxml2-dev libxslt1-dev gettext memcached postgresql postgresql-client libpqxx-dev libssl-dev curl daemontools daemontools-run rabbitmq-server haproxy libmemcached5 libmemcached-dev cassandra
# add the reddit user if not already present
# note: the user will have a password of 'password'
egrep "^$REDDITUSER:" /etc/passwd > /dev/null || useradd -m -p TGya1gjhpZi82 $REDDITUSER
# grab the source
cd $REDDITHOME
if [ ! -d $REDDITHOME/reddit ]; then
sudo -u $REDDITUSER git clone $GITREPO
fi
# set up cassandra directories and configuration
CASSANDRADIRS="/cassandra/commitlog /cassandra/data /cassandra/saved_caches"
CASSANDRAFILE=/etc/cassandra/cassandra.yaml
mkdir -p $CASSANDRADIRS
chown -R reddit:reddit /cassandra
chmod 755 /cassandra
chmod 700 $CASSANDRADIRS
if [ -L $CASSANDRAFILE ]; then
rm $CASSANDRAFILE
fi
if [ -f $CASSANDRAFILE ]; then
mv $CASSANDRAFILE /etc/cassandra/cassandra.orig.yaml
fi
# modify the cassandra settings for use on a single node
# this:
# - changes the replicationfactor to 1
# - adds a savedcachesdirectory
sed -e "s/replication_factor: 3/replication_factor: 1/g" -e "s/pmc01/127.0.0.1/" -e "s/listen_address:/listen_address: 127.0.0.1/" $REDDITHOME/reddit/config/cassandra/cassandra.yaml | grep -v "pmc" > $REDDITHOME/reddit/config/cassandra/cassandra-vm.yaml
ln -s $REDDITHOME/reddit/config/cassandra/cassandra-vm.yaml $CASSANDRAFILE
# fix the run script for using the .deb of cassandra
cat > /home/reddit/reddit/srv/cassandra/run <<CASSRUN
#!/bin/sh
ulimit -n 32768
exec 2>&1
exec setuidgid reddit cassandra -f
CASSRUN
# create the reddit keyspace and permacache CF
CASS_SETUP=$(mktemp)
cat > $CASS_SETUP <<COMMANDS
connect localhost/9160;
create keyspace reddit with replication_factor = 1;
use reddit;
create column family permacache with column_type = 'Standard' and comparator = 'BytesType';
COMMANDS
cassandra-cli -B -f $CASS_SETUP
rm $CASS_SETUP
# fix a weird directory expectation issue
if [ ! -L /usr/include/libxml ]; then
ln -s /usr/include/libxml2/libxml /usr/include/libxml
fi
ldconfig
# set up postgres
IS_DATABASE_CREATED=$(sudo -u postgres psql -t -c "SELECT COUNT(1) FROM pg_catalog.pg_database WHERE datname = 'reddit';")
if [ $IS_DATABASE_CREATED -ne 1 ]; then
PGSCRIPT=$(mktemp)
cat > $PGSCRIPT <<PGSCRIPT
CREATE DATABASE reddit WITH ENCODING = 'utf8';
CREATE USER reddit WITH PASSWORD 'password';
PGSCRIPT
sudo -u postgres psql < $PGSCRIPT
rm $PGSCRIPT
fi
sudo -u postgres psql reddit < /home/reddit/reddit/sql/functions.sql
# set up rabbitmq
if ! rabbitmqctl list_vhosts | egrep "^/$"
then
rabbitmqctl add_vhost /
fi
if ! rabbitmqctl list_users | egrep "^reddit$"
then
rabbitmqctl add_user reddit reddit
fi
rabbitmqctl set_permissions -p / reddit ".*" ".*" ".*"
# run the setup script
cd $REDDITHOME/reddit/r2
sudo python setup.py develop
# downgrade some packages
easy_install "webhelpers==0.6.4"
easy_install "Paste==1.7.2-reddit-0.2"
# switch to daemontools for certain things
update-rc.d -f memcached remove
update-rc.d -f cassandra remove
# link
cd $REDDITHOME
if [ ! -L $REDDITHOME/srv ]; then
sudo -u reddit ln -s reddit/srv
fi
cd reddit/r2
if [ ! -L run.ini ]; then
sudo -u reddit ln -s example.ini run.ini
fi
if [ ! -L /service ]; then
ln -s /etc/service /service
fi
ln -s $REDDITHOME/reddit/srv/* /service/ || true
# run make
cd $REDDITHOME/reddit/r2
make
# install the crontab
CRONTAB=$(mktemp)
crontab -u reddit -l > $CRONTAB
cat >>$CRONTAB <<CRON
# m h dom mon dow command
*/5 * * * * ~/reddit/scripts/rising.sh
*/4 * * * * ~/reddit/scripts/send_mail.sh
*/3 * * * * ~/reddit/scripts/broken_things.sh
1 * * * * ~/reddit/scripts/update_promos.sh
*/2 * * * * ~/reddit/scripts/look_for_verdicts.sh
0 23 * * * ~/reddit/scripts/update_reddits.sh
CRON
crontab -u reddit $CRONTAB
rm $CRONTAB
# done!
cd $REDDITHOME
echo "Done installing reddit! Please reboot and populate the database."
@cheapsteak
Copy link

For some reason this script causes the cassandra.yaml to have a
listen_address: 127.0.0.1 127.0.0.1
which has to be manually corrected

Been fiddling around for hours and still haven't gotten it to work yet (Ubuntu 10.4), I'm pretty noob at linux stuff :(

Just noticed in my processes that there are around 130 postgres: reddit (idle) processes each taking up a port. Is this normal? Still haven't gotten it running yet btw. Kind of lost

edit: It works!
Guess I needed to reboot after fixing cassandra

BTW cassandra's cassandra.yaml still has conflicting listening ports of 7000 and 8080, I'd try correcting it on here if I weren't so afraid of messing everything up X(

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