forked from openSUSE/open-build-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-appliance.sh
executable file
·175 lines (124 loc) · 3.43 KB
/
setup-appliance.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
###############################################################################
#
# MAIN
#
###############################################################################
export LC_ALL=C
SH_LIBDIR=`dirname $0`
source $SH_LIBDIR/functions.setup-appliance.sh
prepare_os_settings
ENABLE_OPTIONAL_SERVICES=0
ENABLE_FORCEPROJECTKEYS=1
MYSQL_USER=root
MYSQL_PASS=opensuse
PID_FILE=/run/setup-appliance.pid
# package or appliance defaults
if [ -e /etc/sysconfig/obs-server ]; then
source /etc/sysconfig/obs-server
fi
# Set default directories
apidir=/srv/www/obs/api
backenddir=/srv/obs
# Overwrite directory defaults with settings in
# config file /etc/sysconfig/obs-server
if [ -n "$OBS_BASE_DIR" ]; then
backenddir="$OBS_BASE_DIR"
fi
logline "Starting "`basename $0`" at "`date`
NON_INTERACTIVE=0
if [ -f $PID_FILE ];then
APID=`cat $PID_FILE`
if [ -f /proc/$APID/status ];then
logline `basename $0`" already running. Exiting!"
exit 0
else
logline `basename $0`" died unexpectedly"
fi
fi
echo $$ > $PID_FILE
trap "rm -f $PID_FILE" EXIT
while [[ $1 ]];do
case $1 in
--non-interactive) NON_INTERACTIVE=1;;
--setup-only) SETUP_ONLY=1;;
--enable-optional-services) ENABLE_OPTIONAL_SERVICES=1;;
--force) OBS_API_AUTOSETUP="yes";;
--disable-forceprojectkeys) ENABLE_FORCEPROJECTKEYS=0;;
esac
shift
done
if [ "$OBS_API_AUTOSETUP" != "yes" ]; then
echo "OBS API Autosetup is not enabled in sysconfig, skipping!"
exit 0
fi
[[ $HOME == '' ]] && export HOME=/root
# prepare configuration for obssigner before any other backend service
# is started, because obssigner configuration might affect other services
# too
GPG_KEY_CREATED=0
prepare_obssigner
if [[ $GPG_KEY_CREATED == 1 ]];then
systemctl reload obssrcserver
systemctl reload obsrepserver
fi
check_required_backend_services
check_recommended_backend_services
check_optional_backend_services
check_unit $MYSQL_SERVICE.service 1
get_hostname
### In case of the appliance, we never know where we boot up !
OLDFQHOSTNAME="NOTHING"
if [ -e $backenddir/.oldfqhostname ]; then
OLDFQHOSTNAME=`cat $backenddir/.oldfqhostname`
fi
DETECTED_HOSTNAME_CHANGE=0
if [ "$FQHOSTNAME" != "$OLDFQHOSTNAME" ]; then
echo "Appliance hostname changed from $OLDFQHOSTNAME to $FQHOSTNAME !"
DETECTED_HOSTNAME_CHANGE=1
fi
if [[ $DETECTED_HOSTNAME_CHANGE == 1 ]];then
adapt_worker_jobs
adjust_api_config
fi
echo "$FQHOSTNAME" > $backenddir/.oldfqhostname
OBSVERSION=`rpm -q --qf '%{VERSION}' obs-server`
if [ -e /etc/os-release ];then
# execute in subshell to preserve the values of the variables
# $NAME and $VERSION as these are very generic
OS_NAME=`. /etc/os-release;echo $NAME`
OS_VERSION=`. /etc/os-release;echo $VERSION`
OS="$OS_NAME $OS_VERSION"
else
OS="UNKNOWN"
fi
RUN_INITIAL_SETUP=""
prepare_database_setup
enable_forceprojectkeys
check_server_key
generate_proposed_dnsnames
DNS_NAMES="$rv"
DETECTED_CERT_CHANGE=0
check_server_cert
import_ca_cert
relink_server_cert
fix_permissions
prepare_apache2
prepare_passenger
check_unit $HTTPD_SERVICE.service
check_unit memcached.service
# make sure that apache gets restarted after cert change
if [[ $DETECTED_CERT_CHANGE && ! $SETUP_ONLY ]];then
systemctl reload $HTTPD_SERVICE.service
fi
check_unit obs-api-support.target
create_issue_file
if [ -n "$FQHOSTNAME" ]; then
create_overview_html
add_login_info_to_issue
else
network_failure_warning
fi
set_gpg_expiry_date
create_sign_cert
exit 0