#!/bin/sh # Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. warning() { echo "WARNING: $1" >&2 } fatal() { echo "FATAL: $1" >&2 exit 1 } on_failure() { if [ $? != 0 ] then fatal $1 fi } # Check if already running/port blocked chk_service() { port=${1:?Missing port} case $os in *[Bb][Ss][Dd]*|Darwin) ## checks ipv[46] netstat -anL | awk '{print $2}' | grep "\.$1$" ;; *) # Is someone listening on the ports already? (ipv4 only test ?) netstat -nl | grep '[^:]:'$port'[ \t]' ;; esac } # ensure right directory realpath=$( ruby -e "puts File.expand_path(\"$0\")") cd $(dirname $realpath)/.. #Warn if legacy config exists if [ -e "config/script_server.yml" ] then warning "config/script_server.yml was merged into config/diaspora.yml. Please read the changelog!" fi # Check if database.yml exists if [ ! -e "config/database.yml" ] then fatal "config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!" fi # Check if diaspora.yml exists if [ ! -e "config/diaspora.yml" ] then fatal "config/diaspora.yml is missing! Copy over config/diaspora.yml.example to config/diaspora.yml and edit it properly!" fi # Setup environment if [ -z "$RAILS_ENV" ] then RAILS_ENV=$(bundle exec ruby ./script/get_config.rb server.rails_environment) on_failure "Couldn't parse config/diaspora.yml!" export RAILS_ENV fi os=$(uname -s) vars=$(bundle exec ruby ./script/get_config.rb \ port=server.port \ db=server.database \ single_process_mode=environment.single_process_mode? \ embed_sidekiq_worker=server.embed_sidekiq_worker \ workers=server.sidekiq_workers ) on_failure "Couldn't parse config/diaspora.yml!" eval "$vars" if [ -z "$DB" ] then DB=$db export DB fi args="$@" for arg in $(echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}') do [ "$prev_arg" = '-p' ] && port="$arg" prev_arg="$arg" done services=$(chk_service $port ) if [ -n "$services" ] then fatal "Port $port is already in use.\n\t$services" fi # Force AGPL if [ -w "public" -a ! -e "public/source.tar.gz" ] then branch=$(git branch | awk '/^[*]/ {print $2}') tar czf public/source.tar.gz $(git ls-tree -r $branch | awk '{print $4}') fi if [ ! -e "public/source.tar.gz" ] then fatal "Can't find, or even create, public/source.tar.gz." fi # Check if assets are precompiled if [ "$RAILS_ENV" = "production" -a ! -e "public/assets/default.css" ] then fatal <