-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost_setup
executable file
·115 lines (91 loc) · 3.26 KB
/
host_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
#!/bin/bash
#
# Part of Simple paas
#
# Setup a new host ready to run Simple paas
#
set -euo pipefail
usage() {
echo "This script will setup Simple paas on a single host."
echo "example usage:"
echo "[email protected] REGISTRY=registry.mydomain.com/internal BUCKET=myhosting STAGING_DOMAIN=wildcarded.domain.com ./simple-paas/host_setup"
exit 1
}
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
set +u
if [ -z "${EMAIL}" ]; then
echo "Please set the default email address before running this script."
echo "Something like this using your own email should work a treat."
echo "[email protected]"
usage
fi
if [ -z "${REGISTRY}" ]; then
echo "Please set the registry address before running this script."
echo "REGISTRY=registry.mydomain.com/internal"
usage
fi
if [ -z "${BUCKET}" ]; then
echo "Please set the bucket name before running this script."
echo "BUCKET=myhosting"
usage
fi
if [ -z "${STAGING_DOMAIN}" ]; then
echo "Please set the staging domain before running this script."
echo "This is a domain/subdomain setup with a wildcard DNS record."
echo "STAGING_DOMAIN=wildcarded.domain.com"
usage
fi
set -u
CHECKOUT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "Installing software and verifying functionality."
apt update
apt -y install docker.io ssh mariadb-server mariadb-server-10.3 python3-pip memcached jq
pip3 install b2
docker run hello-world
echo "Creating directories."
mkdir -p /etc/simple-paas /sites
echo "Tweaking docker."
cp ${CHECKOUT_DIR}/setup/daemon.json /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
echo "Installing simple-paas."
for i in ${CHECKOUT_DIR}/bin/*; do
ln -sf $i /usr/local/bin/;
done
echo "Setting mysql to bind to all addresses."
cp ${CHECKOUT_DIR}/setup/90-simple-paas.cnf /etc/mysql/mariadb.conf.d/90-simple-paas.cnf
systemctl daemon-reload
systemctl restart mariadb
echo "Adding simple-paas logging channel local6."
cp ${CHECKOUT_DIR}/setup/60-simple-paas.conf /etc/rsyslog.d/
systemctl daemon-reload
systemctl restart rsyslog
echo "Creating simple paas directory."
mkdir -p /etc/simple-paas/sites
echo "Copying proxy config to simple paas directory."
cp ${CHECKOUT_DIR}/setup/proxy.conf /etc/simple-paas/
echo "Creating basic host config."
cp ${CHECKOUT_DIR}/setup/sp_config.example /etc/simple-paas/sp_config
sed -i -e 's%SYSTEM_EMAIL=.*%SYSTEM_EMAIL='"${EMAIL}"'%' /etc/simple-paas/sp_config
sed -i -e 's@CONTAINER_REGISTRY=.*@CONTAINER_REGISTRY='"${REGISTRY}"'@' /etc/simple-paas/sp_config
sed -i -e 's@B2_BUCKET=.*@B2_BUCKET='"${BUCKET}"'@' /etc/simple-paas/sp_config
set -i -e 's@STAGING_DOMAIN=.*@STAGING_DOMAIN='"${STAGING_DOMAIN}"'@' /etc/simple-paas/sp_config
echo "Logging into the specified container registry ${REGISTRY}"
docker login ${REGISTRY}
echo "Logging into B2"
# Check if the host is authorized for B2, if not, set that up now.
if ! b2 get-account-info > /dev/null; then
echo "Enter B2 authorization details for backup setup."
b2 authorize-account
fi
if ! b2 list-buckets | grep ${BUCKET}; then
b2 create-bucket ${BUCKET} allPrivate
fi
echo "Starting nginx proxy containers."
${CHECKOUT_DIR}/host_start_nginx
echo "Adding automated backups"
ln -sf /usr/local/bin/sp_backup_all /etc/cron.hourly/
echo "Setup complete."