Welcome to mirror list, hosted at ThFree Co, Russian Federation.

server « script - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3fcbcc895202425e7f449487c97b5012936b6758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/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)/..

# 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.toml exists
if [ -e "config/diaspora.toml" ]
then
  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!"
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;
  then
    # 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
  fi
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

# Setup environment
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" )
  on_failure "Couldn't parse $CONFIG_FILE!"
  export RAILS_ENV
fi


os=$(uname -s)
vars=$(bin/bundle exec ruby ./script/get_config.rb \
  single_process_mode=environment.single_process_mode? \
  embed_sidekiq_worker=server.embed_sidekiq_worker \
  workers=server.sidekiq_workers \
  redis_url=environment.redis \
  | grep -vE "is not writable|as your home directory temporarily"
)
on_failure "Couldn't parse $CONFIG_FILE!"
eval "$vars"

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

if [ -n "$PORT" ]
then
  export PORT

  services=$(chk_service $PORT)
  if [ -n "$services" ]
  then
    fatal "Port $PORT is already in use.\n\t$services"
  fi
fi

# Force AGPL
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}')
  else
    fatal "Can't generate public/source.tar.gz for you.
Please tar up a copy of your Diaspora installation and place it there."
  fi
fi

if [ ! -e "public/source.tar.gz" ]
then
  fatal "Can't find public/source.tar.gz"
fi

# Check if assets are precompiled
if [ "$RAILS_ENV" = "production" -a -z "$(find public/assets/ -maxdepth 1 -name 'main-*.js' -print -quit 2>/dev/null)" ]
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"
fi

# Check if redis is running
if [ "$single_process_mode" = "false" ]
then
  if [ -n "$redis_url" ]
  then
    redis_param="url: '$redis_url'"
  fi
  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" ]
  then
    fatal "Can't connect to redis. Please check if it's running and if environment.redis is configured correctly in $CONFIG_FILE."
  fi
fi

# 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

# 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

# Start Diaspora
printf "Starting Diaspora in $RAILS_ENV mode "
if [ -n "$PORT" ]
then
  printf "on port $PORT "
fi
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."
  workers=0
else
  echo "with $workers Sidekiq worker(s)."
fi
echo ""

exec bin/bundle exec loader_eye --stop_all -c config/eye.rb