Skip to content
Extraits de code Groupes Projets
server 3,38 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    Jonne Hass's avatar
    Jonne Hass a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    # This script is meant for running a small server in production. It starts the Diaspora
    # server, redis, and resque. To run a server locally for development, use foreman instead:
    #    foreman start
    
    Jonne Hass's avatar
    Jonne Hass a validé
    # ensure right directory
    
    realpath=$( ruby -e "puts File.expand_path(\"$0\")")
    cd $(dirname $realpath)/..
    
    Jonne Hass's avatar
    Jonne Hass a validé
    
    # Check if script_server.yml exists
    if [ ! -e 'config/script_server.yml' ]; then
        echo 'FATAL: config/script_server.yml is missing! Copy over config/script_server.yml.example to config/script_server.yml and edit it properly!' >&2
        exit 69
    fi
    
    Jonne Hass's avatar
    Jonne Hass a validé
    # Check if database.yml exists
    if [ ! -e 'config/database.yml' ]; then
        echo 'FATAL: config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!' >&2
        exit 68
    fi
    
    
    # Check if application.yml exists
    
    Jonne Haß's avatar
    Jonne Haß a validé
    if [ ! -e 'config/diaspora.yml' ]; then
        echo 'FATAL: config/diaspora.yml is missing! Copy over config/diaspora.yml.example to config/diaspora.yml and edit it properly!' >&2
    
    Jonne Hass's avatar
    Jonne Hass a validé
        exit 70
    fi
    
    
    
    
    # Setup environment
    OS=`uname -s`
    
    export RAILS_ENV=$(bundle exec ruby ./script/get_config.rb rails_env script_server)
    export DB=$(bundle exec ruby ./script/get_config.rb db script_server)
    THIN_PORT=$(bundle exec ruby ./script/get_config.rb thin_port script_server)
    eval "DEFAULT_THIN_ARGS=\"$(bundle exec ruby ./script/get_config.rb default_thin_args script_server)\""
    
    # Backward compatibillity, overide default settings
    [ -e config/server.sh ] && source config/server.sh
    
    Philip Champon's avatar
    Philip Champon a validé
    function 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
    }
    
    
    Alec Leamas's avatar
    Alec Leamas a validé
    # Scan for -p, find out what port thin is about to use.
    args="$DEFAULT_THIN_ARGS $@"
    prev_arg=''
    for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
    do
        [ "$prev_arg" = '-p' ] && THIN_PORT="$arg"
        prev_arg="$arg"
    
    # Is someone listening on the ports already? (ipv4 only test ?)
    
    Philip Champon's avatar
    Philip Champon a validé
    services=$( chk_service $THIN_PORT )
    
    if [ -n "$services" ]; then
    
        echo "FATAL: Error: thin port $THIN_PORT is already in use. Exiting" >&2
    
    # 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
    
        echo "FATAL: Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
    
    MrZYX's avatar
    MrZYX a validé
    if [ ! -e 'public/assets/default.css' ]; then
        if [ "$RAILS_ENV" == 'production' ]; then
    
    Jonne Haß's avatar
    Jonne Haß a validé
            echo "FATAL: You're running in production mode without having assets precompiled." >&2
            echo "Now and after each git pull before you restart the application, run:" >&2
    
    David Morley's avatar
    David Morley a validé
            echo "bundle exec rake assets:precompile" >&2
    
    Jonne Haß's avatar
    Jonne Haß a validé
            exit 71
    
    Jonne Hass's avatar
    Jonne Hass a validé
    
    # Start Diaspora
    
    
    Jonne Haß's avatar
    Jonne Haß a validé
    if [ "$(bundle exec ruby ./script/get_config.rb 'environment.single_process_mode?')" != "true" ]; then
    
        QUEUE=* bundle exec rake resque:work&
    fi
    
    MrZYX's avatar
    MrZYX a validé
    if [ "$(./script/get_config.rb enable_thin script_server)" = "true" ]; then