#!/bin/bash # The contents of this file are subject to the Common Public Attribution # License Version 1.0. (the "License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://code.reddit.com/LICENSE. The License is based on the Mozilla Public # License Version 1.1, but Sections 14 and 15 have been added to cover use of # software over a computer network and provide for limited attribution for the # Original Developer. In addition, Exhibit A has been modified to be consistent # with Exhibit B. # # Software distributed under the License is distributed on an "AS IS" basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for # the specific language governing rights and limitations under the License. # # The Original Code is reddit. # # The Original Developer is the Initial Developer. The Initial Developer of # the Original Code is reddit Inc. # # All portions of the code written by reddit are Copyright (c) 2006-2014 reddit # Inc. All Rights Reserved. ############################################################################### ############################################################################### # reddit dev environment installer # -------------------------------- # This script installs a reddit stack suitable for development. DO NOT run this # on a system that you use for other purposes as it might delete important # files, truncate your databases, and otherwise do mean things to you. # # By default, this script will install the reddit code in the current user's # home directory and all of its dependencies (including libraries and database # servers) at the system level. The installed reddit will expect to be visited # on the domain "reddit.local" unless specified otherwise. Configuring name # resolution for the domain is expected to be done outside the installed # environment (e.g. in your host machine's /etc/hosts file) and is not # something this script handles. # # Several configuration options (listed in the "Configuration" section below) # are overridable with environment variables. e.g. # # sudo REDDIT_DOMAIN=example.com ./install-reddit.sh # ############################################################################### set -e ############################################################################### # Configuration ############################################################################### # which user to install the code for; defaults to the user invoking this script REDDIT_USER=${REDDIT_USER:-$SUDO_USER} # the group to run reddit code as; must exist already REDDIT_GROUP=${REDDIT_GROUP:-nogroup} # the root directory to base the install in. must exist already REDDIT_HOME=${REDDIT_HOME:-/home/$REDDIT_USER} # the domain that you will connect to your reddit install with. # MUST contain a . in it somewhere as browsers won't do cookies for dotless # domains. an IP address will suffice if nothing else is available. REDDIT_DOMAIN=${REDDIT_DOMAIN:-reddit.local} #The plugins to clone and register in the ini file REDDIT_PLUGINS=${REDDIT_PLUGINS:-meatspace about liveupdate} ############################################################################### # Sanity Checks ############################################################################### if [[ $EUID -ne 0 ]]; then echo "ERROR: Must be run with root privileges." exit 1 fi # seriously! these checks are here for a reason. the packages from the # reddit ppa aren't built for anything but precise (12.04) right now, so # if you try and use this install script on another release you're gonna # have a bad time. source /etc/lsb-release if [ "$DISTRIB_ID" != "Ubuntu" -o "$DISTRIB_RELEASE" != "12.04" ]; then echo "ERROR: Only Ubuntu 12.04 is supported." exit 1 fi if [[ "2000000" -gt $(awk '/MemTotal/{print $2}' /proc/meminfo) ]]; then LOW_MEM_PROMPT="reddit requires at least 2GB of memory to work properly, continue anyway? [y/n] " read -er -n1 -p "$LOW_MEM_PROMPT" response if [[ "$response" != "y" ]]; then echo "Quitting." exit 1 fi fi ############################################################################### # Install prerequisites ############################################################################### set -x # aptitude configuration APTITUDE_OPTIONS="-y" export DEBIAN_FRONTEND=noninteractive # run an aptitude update to make sure python-software-properties # dependencies are found apt-get update # add the reddit ppa for some custom packages apt-get install $APTITUDE_OPTIONS python-software-properties apt-add-repository -y ppa:reddit/ppa # pin the ppa -- packages present in the ppa will take precedence over # ones in other repositories (unless further pinning is done) cat < /etc/apt/preferences.d/reddit Package: * Pin: release o=LP-PPA-reddit Pin-Priority: 600 HERE # grab the new ppas' package listings apt-get update # install prerequisites cat < /dev/null; then echo "create keyspace reddit;" | cassandra-cli -h localhost -B fi cat < development.update < $1 chmod 755 $1 } helper-script /usr/local/bin/reddit-run < /etc/gunicorn.d/click.conf < /etc/nginx/sites-available/reddit-media < /etc/nginx/sites-available/reddit-pixel < $BACKUP_HAPROXY fi # make sure haproxy is enabled cat > /etc/default/haproxy < /etc/haproxy/haproxy.cfg < /etc/stunnel/stunnel.conf < /etc/sutro.ini < /etc/init/sutro.conf << UPSTART_SUTRO description "sutro websocket server" stop on runlevel [!2345] start on runlevel [2345] respawn respawn limit 10 5 kill timeout 15 limit nofile 65535 65535 exec gunicorn_paster /etc/sutro.ini UPSTART_SUTRO fi service sutro restart ############################################################################### # geoip service ############################################################################### if [ ! -f /etc/gunicorn.d/geoip.conf ]; then cat > /etc/gunicorn.d/geoip.conf < /etc/default/reddit < $CONSUMER_CONFIG_ROOT/$1 fi } set_consumer_count log_q 0 set_consumer_count cloudsearch_q 0 set_consumer_count scraper_q 1 set_consumer_count markread_q 1 set_consumer_count commentstree_q 1 set_consumer_count newcomments_q 1 set_consumer_count vote_link_q 1 set_consumer_count vote_comment_q 1 chown -R $REDDIT_USER:$REDDIT_GROUP $CONSUMER_CONFIG_ROOT/ initctl emit reddit-stop initctl emit reddit-start ############################################################################### # Cron Jobs ############################################################################### if [ ! -f /etc/cron.d/reddit ]; then cat > /etc/cron.d/reddit <