Skip to content
Extraits de code Groupes Projets
server 2,97 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.
    
    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é
    
    
    #Warn if legacy config exists
    if [ -e 'config/script_server.yml' ]; then
      echo "WARNING: config/script_server.yml was merged into config/diaspora.yml. Please read the changelog!" >&2
    
    Jonne Hass's avatar
    Jonne Hass a validé
    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
    
    Jonne Hass's avatar
    Jonne Hass a validé
    fi
    
    
    # Check if diaspora.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
      exit 70
    
    Jonne Hass's avatar
    Jonne Hass a validé
    fi
    
    
    # Setup environment
    
    if [ -z "$RAILS_ENV" ]; then
    
      RAILS_ENV=$(bundle exec ruby ./script/get_config.rb server.rails_environment)
      export RAILS_ENV
    
    os=`uname -s`
    eval $(bundle exec ruby ./script/get_config.rb \
      port=server.port \
    
      db=server.database \
    
      single_process_mode=environment.single_process_mode?
    
    Jonne Haß's avatar
    Jonne Haß a validé
      embed_sidekiq_worker=server.embed_sidekiq_worker
    
    )
    
    if [ -z "$DB" ]; then
    
    Alec Leamas's avatar
    Alec Leamas a validé
    prev_arg=''
    for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
    do
    
      [ "$prev_arg" = '-p' ] && port="$arg"
      prev_arg="$arg"
    
    # Check if already running/port blocked
    
    {
      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
    }
    
    
    services=$( chk_service $port )
    
    if [ -n "$services" ]; then
    
      echo "FATAL: Error: port $port is already in use. Exiting" >&2
      echo "     $services"
      exit 64
    
    # 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}'`
    
    if [ ! -e public/source.tar.gz ]; then
    
      echo "FATAL: Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
      exit 65
    
    # Check if assets are precompiled
    
    if [ "$RAILS_ENV" = 'production' ]; then
    
      if [ ! -e 'public/assets/default.css' ]; then
        echo "FATAL: You're running in production mode without having assets precompiled." >&2
        echo "Now and after each update before you restart the application, run:" >&2
        echo "bundle exec rake assets:precompile" >&2
        exit 71
      fi
    
    Jonne Hass's avatar
    Jonne Hass a validé
    
    # Start Diaspora
    
    echo -n "Starting Diaspora in $RAILS_ENV mode on port $port "
    
    Jonne Haß's avatar
    Jonne Haß a validé
    if [ "$embed_sidekiq_worker" = "true" ]; then
      echo "with a sidekiq worker embeded into unicorn."
    
    elif [ "$single_process_mode" = "true" ]; then
      echo "with job processing inside the request cycle."
    
    Jonne Haß's avatar
    Jonne Haß a validé
    exec bundle exec foreman start -m "web=1,sidekiq=1" -p $port