-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathappscale_build.sh
executable file
·156 lines (133 loc) · 5.33 KB
/
appscale_build.sh
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
#!/bin/bash
#
# This script installs AppScale on the local machine. It pulls in all the
# needed dependencies and configures them properly for AppScale.
#
# Some basic check: we need a way to install packages.
PKG_CMD="$(which apt-get)"
if [ -z "${PKG_CMD}" ]; then
echo "Cannot find the package manager command!"
exit 1
fi
set -e
# We need to update the package cache and list first, to ensure we don't
# get errors when installing basic packages.
echo -n "Updating package list and cache ..."
${PKG_CMD} update > /dev/null
echo "done."
# We need to make sure we have lsb-release, before we use it. On
# streamlined images (like docker) it may not be present.
if ! which lsb_release > /dev/null ; then
echo -n "Installing lsb-release..."
${PKG_CMD} install -y lsb-release > /dev/null
echo "done."
fi
# Get the release version and vendor.
export DIST="$(lsb_release -c -s)"
export VENDOR="$(lsb_release -i -s)"
cd `dirname $0`/..
# Let's check that the distribution is supported by the build script.
if [ ! -e ./debian/changelog.${DIST} ]; then
echo "${VENDOR}/${DIST} is not supported."
exit 1
fi
# Let's make sure we have appscale source installed.
if [ ! -e VERSION ]; then
echo "Please checkout whole appscale branch."
exit 1
fi
echo "Installing building environment for ${VENDOR}/${DIST}"
echo "Press Ctrl-C if this is not correct"
# Let's wait few seconds to allow a Ctrl-C if building is not desirable.
sleep 5
# Let's check if we run in a docker container.
export IN_DOCKER="no"
if grep docker /proc/1/cgroup > /dev/null ; then
echo "Detected docker container."
IN_DOCKER="yes"
# Make sure we have default locale.
${PKG_CMD} install --assume-yes locales
locale-gen en_US en_US.UTF-8
fi
export APPSCALE_HOME_RUNTIME=`pwd`
export CONFIG_DIR="/etc/appscale"
# Ensure we have apt-add-repository. On some very small/custom builds it
# may be missing (for example docker).
if ! which apt-add-repository > /dev/null ; then
echo -n "Installing software-properties-common..."
${PKG_CMD} install -y software-properties-common > /dev/null
echo "done."
fi
# Newer versions of ejabberd must be installed before rabbitmq-server because
# if RabbitMQ starts first, it will start an incompatible epmd daemon that will
# prevent ejabberd from being installed.
case ${DIST} in
stretch|bionic)
apt-get install --assume-yes ejabberd
;;
esac
# Ejabberd fails creating a cert on Azure because of domain name length, if
# the file exists already it will skip creating it and not fail. We use the
# certs we generate and change ejabberd's config file to use that instead.
mkdir -p /etc/ejabberd && touch /etc/ejabberd/ejabberd.pem
# This will install dependencies from control.$DIST (ie distro specific
# packages).
PACKAGES="$(find debian -regex ".*\/control\.${DIST}\$" -exec debian/package-list.sh {} +)"
if ! ${PKG_CMD} install --assume-yes ${PACKAGES}; then
echo "Fail to install depending packages for runtime."
exit 1
fi
# This will remove all the conflicts packages.
PACKAGES="$(find debian -regex ".*\/control\.${DIST}\$" -exec debian/remove-list.sh {} +)"
if ! ${PKG_CMD} remove --purge --assume-yes ${PACKAGES}; then
echo "Fail to remove conflicting packages"
exit 1
fi
# Since the last step in appscale_build.sh is to create the certs directory,
# its existence indicates that appscale has already been installed.
if [ -d ${CONFIG_DIR}/certs ]; then
# Version 2.3.1 and prior didn't have /etc/appscale/VERSION.
WHERE_IS_VERSION="${CONFIG_DIR}/VERSION"
if [ ! -e ${WHERE_IS_VERSION} ]; then
WHERE_IS_VERSION="appscale/VERSION"
fi
APPSCALE_MAJOR="$(sed -n 's/.*\([0-9]\)\+\.\([0-9]\)\+\.[0-9]/\1/gp' ${WHERE_IS_VERSION})"
APPSCALE_MINOR="$(sed -n 's/.*\([0-9]\)\+\.\([0-9]\)\+\.[0-9]/\2/gp' ${WHERE_IS_VERSION})"
if [ -z "$APPSCALE_MAJOR" -o -z "$APPSCALE_MINOR" ]; then
echo "Cannot determine version of AppScale!"
exit 1
fi
echo
echo "Found AppScale version $APPSCALE_MAJOR.$APPSCALE_MINOR: upgrading it."
# Make sure AppScale is not running.
if systemctl is-active appscale-controller > /dev/null ; then
echo "AppScale is still running: please stop it"
[ "$FORCE_UPGRADE" = "Y" ] || exit 1
fi
# This sleep is to allow the user to Ctrl-C in case an upgrade is
# not wanted.
echo "Upgrading AppScale version $APPSCALE_MAJOR.$APPSCALE_MINOR ..."
sleep 5
# Let's keep a copy of the old config: we need to move it to avoid
# questions from dpkg.
if [ -e /etc/haproxy/haproxy.cfg ]; then
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.appscale.old
fi
# Remove outdated init scripts.
[ ! -f "/etc/init.d/appscale-controller" ] || rm -fv "/etc/init.d/appscale-controller"
[ ! -f "/etc/init.d/appscale-progenitor" ] || rm -fv "/etc/init.d/appscale-progenitor"
[ ! -f "/etc/init.d/appscale-unmonit" ] || rm -fv "/etc/init.d/appscale-unmonit"
fi
if [ $1 ]; then
echo "Installing AppScale with $1 as the only supported database."
bash debian/appscale_install.sh core || exit 1
bash debian/appscale_install.sh $1 || exit 1
else
echo "Installing full AppScale image"
bash debian/appscale_install.sh all || exit 1
fi
if ! mkdir -p ${CONFIG_DIR}/certs; then
echo "Unable to complete AppScale installation."
exit 1
fi
echo "AppScale installation completed successfully!"