/
zotonic_setup
executable file
·115 lines (99 loc) · 4.3 KB
/
zotonic_setup
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
#!/usr/bin/env bash
#
# Copyright 2011 Lloyd R. Prentice
# Copyright 2012 Arjan Scherpenisse
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function require_zotonic_running {
PONG=$($ZOTONIC_CALL -a "zotonic ping" 2>&1)
if [ "$PONG" != "pong" ]; then
echo "$PONG" 1>&2
echo "Zotonic is not running. You need to start Zotonic first to use this command." 1>&2
echo 1>&2
exit 1
fi
}
export -f require_zotonic_running
function require_zotonic_not_running {
PONG=$($ZOTONIC_CALL -a "zotonic ping" 2>&1)
if [ "$PONG" = "pong" ]; then
echo "Zotonic is already running as $NODENAME@$NODEHOST." 1>&2
echo "You cannot start two Zotonic instances with the same node name." 1>&2
echo 1>&2
exit 1
fi
}
export -f require_zotonic_not_running
export ZOTONIC_BIN=${ZOTONIC_BIN:=$ZOTONIC/bin}
export SITES=${SITES:=$ZOTONIC/priv/sites}
# Path to the Erlang VM
export ERL=${ERL:=erl}
if make --version 2>&1 | grep "^GNU Make" >& /dev/null
then
export MAKE=${MAKE:=make}
else
export MAKE=${MAKE:=gmake}
fi
# Increase this if you expect a lot of concurrent connections. For example
# if you use comet on popular pages.
# Please check the documentation of your system on how to increase
# the maximum number of open files your operating system.
export MAX_PORTS=${MAX_PORTS:=$(ulimit -n|sed 's/unlimited/100000/')}
# The maximum number of Erlang processes. Must be in the range
# 16..134217727.
export MAX_PROCESSES=${MAX_PROCESSES:=10000000}
# Whether or not to use kernel polling (+K argument); either 'true' or
# 'false'
export KERNEL_POLL=${KERNEL_POLL:=true}
# The include path for the erlang vm, add when needed for your application.
export PA=${PA:="$ZOTONIC/ebin $ZOTONIC/deps/*/ebin $ZOTONIC/modules/*/deps/*/ebin $ZOTONIC/priv/modules/*/deps/*/ebin $ZOTONIC/priv/sites/*/modules/*/deps/*/ebin"}
# The name of the Erlang node, this must be unique on your host. ($SNAME is for b.c.)
export NODENAME=${NODENAME:=${SNAME:=zotonic001}}
# For zotonic-addsite et. al. we require Zotonic to be already
# running. In that case, check if Zotonic is already running with the
# -name parameter.
DISTRIBUTED_DETECTED=$(ps u |grep beam.smp|grep $NODENAME@$HOSTNAME|grep \\-name>/dev/null&&echo true||echo false)
export ZOTONIC_DISTRIBUTED=${ZOTONIC_DISTRIBUTED:=$DISTRIBUTED_DETECTED}
# The ZOTONIC_DISTRIBUTED flag tells Zotonic to start a (potentially)
# distributed node. In that case, we require the hostname to be a FQDN.
if [ "$ZOTONIC_DISTRIBUTED" = "true" ]; then
HOSTNAME=$(hostname -f)
if [ "`echo $HOSTNAME|grep '\.'`" != "$HOSTNAME" ]; then
echo Zotonic is configured to run as distributed node, but your hostname is 1>&2
echo not configured to be a fully qualified domain name. Please configure 1>&2
echo your system so the output of \"hostname -f\" returns a FQDN. 1>&2
echo 1>&2
exit 1
fi
export NAME_ARG=-name
export NODEHOST="$HOSTNAME"
else
# Only use the part for the dot of the hostname.
export NODEHOST=`echo $HOSTNAME|sed 's/\..*//'`
export NAME_ARG=-sname
fi
# The filename where zotonic writes its unix process Id to, for monitoring applications.
export ZOTONIC_PIDFILE=$ZOTONIC/zotonic.pid
# Locate the path to the erl_call binary
ERL_CALL=$($ERL -noshell -noinput -eval "io:format(\"~s\", [code:priv_dir(erl_interface)])" -s erlang halt|sed 's~priv$~bin/erl_call~')
export ZOTONIC_CALL="$ERL_CALL $NAME_ARG $NODENAME@$NODEHOST"
# Make sure the erlang.config file exists
if [ ! -e "$ZOTONIC/priv/erlang.config" -a -e "$ZOTONIC/priv/erlang.config.in" ]; then
echo "Installing default erlang.config file"
cp "$ZOTONIC/priv/erlang.config.in" "$ZOTONIC/priv/erlang.config"
fi
# Make sure Zotonic is built
if [ ! -e "$ZOTONIC/ebin/zotonic.app" ]; then
echo "Building Zotonic for the first time."
$MAKE
fi