summaryrefslogtreecommitdiff
path: root/mason.configure
blob: 9ad6f2c7d125f2699fb6a11b4aaf8e55aff9309d (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
#!/bin/sh
#
# Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# This is a "morph deploy" configuration extension to fully configure
# a Mason instance at deployment time. It uses the following variables
# from the environment:
#
#   * ARTIFACT_CACHE_SERVER
#   * MASON_CLUSTER_MORPHOLOGY
#   * MASON_DEFINITIONS_REF
#   * MASON_DISTBUILD_ARCH
#   * MASON_TEST_HOST
#   * TROVE_HOST
#   * TROVE_ID
#   * CONTROLLERHOST

set -e

ROOT="$1"


##########################################################################
# Copy Mason files into root filesystem
##########################################################################

cp mason/mason.sh "$ROOT"/root/mason.sh
cp mason/mason-report.sh "$ROOT"/root/mason-report.sh

cp mason/mason.timer "$ROOT"/etc/systemd/system/mason.timer

cp mason/mason.service "$ROOT"/etc/systemd/system/mason.service

##########################################################################
# Set up httpd web server
##########################################################################

cp mason/httpd.service "$ROOT"/etc/systemd/system/httpd.service

mkdir -p "$ROOT"/srv/mason

cat >>"$ROOT"/etc/httpd.conf <<EOF
.log:text/plain
EOF


##########################################################################
# Check variables
##########################################################################

if [ -n "$MASON_GENERIC" ]; then
    echo Not configuring Mason, it will be generic
    exit 0
fi

if [ "$ARTIFACT_CACHE_SERVER" = "" \
     -o "$MASON_CLUSTER_MORPHOLOGY" = "" \
     -o "$MASON_DEFINITIONS_REF" = "" \
     -o "$MASON_DISTBUILD_ARCH" = "" \
     -o "$MASON_TEST_HOST" = "" ]; then
    echo Not configuring as Mason, some options not defined
    exit 1
fi


##########################################################################
# Functions
##########################################################################

shellescape() {
    echo "'$(echo "$1" | sed -e "s/'/'\\''/g")'"
}


##########################################################################
# Generate config variable shell snippet
##########################################################################

MASON_CONFIG="$ROOT"/root/mason.conf

echo "Creating $MASON_CONFIG"
cat >>"$MASON_CONFIG" <<EOF
#################### START OF DEPLOY TIME CONFIGURATION #######################

ARTIFACT_CACHE_SERVER=$(shellescape "$ARTIFACT_CACHE_SERVER")
UPSTREAM_TROVE_ADDRESS=$(shellescape "$TROVE_HOST")
DEFINITIONS_REF=$(shellescape "$MASON_DEFINITIONS_REF")
DISTBUILD_ARCH=$(shellescape "$MASON_DISTBUILD_ARCH")
DISTBUILD_CONTROLLER_ADDRESS=$(shellescape "$CONTROLLERHOST")
TROVE_ID=$(shellescape "$TROVE_ID")
BUILD_CLUSTER_MORPHOLOGY=$(shellescape "$MASON_CLUSTER_MORPHOLOGY")
TEST_VM_HOST_SSH_URL=$(shellescape "$MASON_TEST_HOST")

##################### END OF DEPLOY TIME CONFIGURATION ########################
EOF


##########################################################################
# Enable services
##########################################################################

ln -s ../mason.timer "$ROOT"/etc/systemd/system/multi-user.target.wants/mason.timer
ln -s ../mason.service "$ROOT"/etc/systemd/system/multi-user.target.wants/mason.service
ln -s ../httpd.service "$ROOT"/etc/systemd/system/multi-user.target.wants/httpd.service