-
-
Save dandv/1030673 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 -e | |
# Neil Williams, reddit | |
# Configuration | |
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 | |
# die if an error occurs | |
set -e | |
# make sure any installations we do aren't gonna need to be updated immediately | |
aptitude update | |
# add some external ppas for packages | |
DEBIAN_FRONTEND=noninteractive aptitude install $APTITUDE_OPTIONS python-software-properties | |
apt-add-repository ppa:cassandra-ubuntu/stable # for lucid | |
apt-add-repository ppa:jason-alioth/reddit | |
# grab the new ppas' package listings | |
aptitude update | |
# install prerequisites | |
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 libpq-dev libpqxx-dev libssl-dev curl daemontools daemontools-run rabbitmq-server haproxy libmemcached5 libmemcached-dev cassandra optipng | |
# disable init scripts for cassandra/memcached so we can control them in | |
# daemontools | |
/etc/init.d/cassandra stop | |
update-rc.d -f cassandra remove | |
/etc/init.d/memcached stop | |
update-rc.d -f memcached remove | |
# link the /service directory to debian's /etc/service | |
if [ ! -L /service ]; then | |
ln -s /etc/service /service | |
fi | |
# add the reddit user if not already present | |
# note: the user will have a password of 'password' | |
if ! egrep "^$REDDITUSER:" /etc/passwd > /dev/null; then | |
useradd -m -p TGya1gjhpZi82 $REDDITUSER | |
fi | |
# 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 | |
ln -s $REDDITHOME/reddit/config/cassandra/cassandra.yaml $CASSANDRAFILE | |
# control cassandra with daemontools | |
ln -s $REDDITHOME/reddit/srv/cassandra /service/ || true | |
# start daemontools | |
/sbin/stop svscan || true | |
/sbin/start svscan | |
sleep 30 # give cassandra time to boot | |
# create the reddit keyspace and permacache CF | |
cat <<COMMANDS | cassandra-cli -B | |
connect localhost/9160; | |
create keyspace reddit with replication_factor = 1; | |
use reddit; | |
create column family permacache with column_type = 'Standard' and comparator = 'BytesType'; | |
COMMANDS | |
# 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 | |
cat <<PGSCRIPT | sudo -u postgres psql | |
CREATE DATABASE reddit WITH ENCODING = 'utf8'; | |
CREATE USER reddit WITH PASSWORD 'password'; | |
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" | |
# install the rest of the runscripts | |
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 | |
ln -s $REDDITHOME/reddit/srv/* /service/ || true | |
# run make | |
cd $REDDITHOME/reddit/r2 | |
make | |
# install the crontab | |
CRONTAB=$(mktemp) | |
crontab -u reddit -l > $CRONTAB || true | |
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 | |
0 23 * * * ~/reddit/scripts/update_reddits.sh | |
CRON | |
crontab -u reddit $CRONTAB | |
rm $CRONTAB | |
# done! | |
cd $REDDITHOME | |
echo "Done installing reddit!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment