Skip to content
Extraits de code Groupes Projets
server 6,43 ko
Newer Older
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 Haß's avatar
Jonne Haß a validé
warning()
{
  echo "WARNING: $1" >&2
}

fatal()
{
  echo "FATAL: $1" >&2
  exit 1
}

on_failure()
{
  if [ $? != 0 ]
  then
    fatal "$1"
Jonne Haß's avatar
Jonne Haß a validé
  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
}


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
Jonne Haß's avatar
Jonne Haß a validé
if [ -e "config/script_server.yml" ]
then
  warning "config/script_server.yml was merged into config/diaspora.yml. Please read the changelog!"
Jonne Hass's avatar
Jonne Hass a validé
fi
Jonne Hass's avatar
Jonne Hass a validé
# Check if database.yml exists
Jonne Haß's avatar
Jonne Haß a validé
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!"
Jonne Hass's avatar
Jonne Hass a validé
fi

Jonne Haß's avatar
Jonne Haß a validé
# Check if diaspora.toml exists
if [ -e "config/diaspora.toml" ]
Jonne Haß's avatar
Jonne Haß a validé
then
Jonne Haß's avatar
Jonne Haß a validé
  CONFIG_FILE="config/diaspora.toml"
elif [ -e "config/diaspora.yml" ]
then
  CONFIG_FILE="config/diaspora.yml"
else
  fatal "config/diaspora.toml is missing! Copy over config/diaspora.toml.example to config/diaspora.toml and edit it properly!"
Jonne Hass's avatar
Jonne Hass a validé
fi

command -v git > /dev/null 2>&1
if [ $? -eq 0 ]; then
  # Check if we're in a repository, before doing any verification.
  if git status > /dev/null 2>&1;
    # Check if git merge is in progress
    if [ -f .git/MERGE_MODE ]; then
      fatal "A git merge is in progress!"
    fi

    # Check if detached head state
    git_branch_name="$(git symbolic-ref HEAD 2>/dev/null)"
    if [ -z "$git_branch_name" ];
    then
      warning "You are in detached HEAD state!"
    fi
# Do RVM checks if RVM is being used
command -v rvm > /dev/null 2>&1
if [ $? -eq 0 ]; then
  rvm_gemset="$(rvm current | cut -d"@" -f2)"
  project_gemset="$(cat .ruby-gemset | tr -d " \t\n\r")"
  if [ "$rvm_gemset" != "$project_gemset" ]; then
    warning "Project gemset is $project_gemset but you are using $rvm_gemset"
  fi
fi

# Check if bundle is complete
if ! bin/bundle check > /dev/null
then
  fatal "Your bundle is not up to date, run the command \"bundle install\""
fi

Jonne Hass's avatar
Jonne Hass a validé
# Setup environment
Jonne Haß's avatar
Jonne Haß a validé
if [ -z "$RAILS_ENV" ]
then
  RAILS_ENV=$(bin/bundle exec ruby ./script/get_config.rb server.rails_environment | grep -vE "is not writable|as your home directory temporarily" )
Jonne Haß's avatar
Jonne Haß a validé
  on_failure "Couldn't parse $CONFIG_FILE!"
Jonne Haß's avatar
Jonne Haß a validé

os=$(uname -s)
vars=$(bin/bundle exec ruby ./script/get_config.rb \
Jonne Haß's avatar
Jonne Haß a validé
  single_process_mode=environment.single_process_mode? \
  embed_sidekiq_worker=server.embed_sidekiq_worker \
  workers=server.sidekiq_workers \
  chat=chat.enabled \
  chat_server=chat.server.enabled \
  chat_bosh_proxy=chat.server.bosh.proxy \
  redis_url=environment.redis \
  | grep -vE "is not writable|as your home directory temporarily"
Jonne Haß's avatar
Jonne Haß a validé
on_failure "Couldn't parse $CONFIG_FILE!"
Jonne Haß's avatar
Jonne Haß a validé
eval "$vars"
Jonne Haß's avatar
Jonne Haß a validé
for arg in $(echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
Alec Leamas's avatar
Alec Leamas a validé
do
  [ "$prev_arg" = '-p' ] && PORT="$arg"
  prev_arg="$arg"
if [ -n "$PORT" ]
Jonne Haß's avatar
Jonne Haß a validé
then
  export PORT

  services=$(chk_service $PORT)
  if [ -n "$services" ]
  then
Jonne Haß's avatar
Jonne Haß a validé
    fatal "Port $PORT is already in use.\n\t$services"
Jonne Haß's avatar
Jonne Haß a validé
if [ -w "public" -a ! -e  "public/source.tar.gz" ]
then
  if command -v git > /dev/null 2>&1 && git rev-parse --is-inside-work-tree > /dev/null 2>&1
  then
    commit_sha=$(git rev-parse HEAD)
    tar czf public/source.tar.gz  $(git ls-tree -r $commit_sha | awk '{print $4}')
    fatal "Can't generate public/source.tar.gz for you.
Bigard Florian's avatar
Bigard Florian a validé
Please tar up a copy of your Diaspora installation and place it there."
Jonne Haß's avatar
Jonne Haß a validé
if [ ! -e "public/source.tar.gz" ]
then
  fatal "Can't find public/source.tar.gz"
# Check if assets are precompiled
if [ "$RAILS_ENV" = "production" -a -z "$(find public/assets/ -maxdepth 1 -name 'main-*.js' -print -quit 2>/dev/null)" ]
Jonne Haß's avatar
Jonne Haß a validé
then
  fatal "You're running in production mode without having assets
precompiled. Now and after each update before you restart the
application, run:
    bin/rake assets:precompile"
# Check if redis is running
if [ "$single_process_mode" = "false" ]
then
  if [ -n "$redis_url" ]
  then
    redis_param="url: '$redis_url'"
  if [ "$(bin/bundle exec ruby -e "require 'redis'; puts Redis.new($redis_param).ping" 2> /dev/null | grep -vE "is not writable|as your home directory temporarily" )" != "PONG" ]
Jonne Haß's avatar
Jonne Haß a validé
    fatal "Can't connect to redis. Please check if it's running and if environment.redis is configured correctly in $CONFIG_FILE."
# Check for old curl versions (see https://github.com/diaspora/diaspora/issues/4202)
if [ `curl -V | grep AsynchDNS | wc -l` -ne 1 ]
then
  warning "
*****************************************************************
curl does not support async DNS, this can cause Sidekiq to crash!
Please update curl to version 7.32, see issue
https://github.com/diaspora/diaspora/issues/4202 for details
*****************************************************************
"
fi

Jonne Haß's avatar
Jonne Haß a validé
if [ "$chat" = "true" -a "$chat_server" = "true" -a  "$chat_bosh_proxy" = "false" ]
Jonne Haß's avatar
Jonne Haß a validé
  warning "
*****************************************************************
You enabled the chat feature but haven't configured BOSH! That
could lead to mixed-content problems with the http clients. Please
think about editing your proxy configuration as described in:

diaspora.yml.example
*****************************************************************
"
# Use libjemalloc if it's available for better memory usage
command -v ldconfig > /dev/null 2>&1
if [ $? -eq 0 ]; then
  ldconfig=ldconfig
elif [ -x /sbin/ldconfig ]; then
  ldconfig=/sbin/ldconfig
fi
if [ -n "${ldconfig}" ]; then
  jemalloc_path=$(${ldconfig} -p | grep jemalloc | tr ' ' '\n' | grep '^/' | head -1)

  if [ -n "${jemalloc_path}" ]; then
    export LD_PRELOAD="${jemalloc_path}"
  fi
fi

Jonne Hass's avatar
Jonne Hass a validé
# Start Diaspora
printf "Starting Diaspora in $RAILS_ENV mode "
if [ -n "$PORT" ]
then
  printf "on port $PORT "
fi
Jonne Haß's avatar
Jonne Haß a validé
if [ "$embed_sidekiq_worker" = "true" ]
then
  echo "with a Sidekiq worker embedded into Unicorn."
  workers=0
elif [ "$single_process_mode" = "true" ]
then
  echo "with job processing inside the request cycle."
Jonne Haß's avatar
Jonne Haß a validé
  workers=0
else
  echo "with $workers Sidekiq worker(s)."
exec bin/bundle exec loader_eye --stop_all -c config/eye.rb