forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappliance-initialize.sh
executable file
·52 lines (39 loc) · 1.52 KB
/
appliance-initialize.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
#!/bin/bash
# Source EVM environment
[ -f /etc/default/evm ] && . /etc/default/evm
[[ -s ${CONTAINER_SCRIPTS_ROOT}/container-deploy-common.sh ]] && source "${CONTAINER_SCRIPTS_ROOT}/container-deploy-common.sh"
function create_v2_key() {
V2_KEY=$(ruby -ropenssl -rbase64 -e 'puts Base64.strict_encode64(Digest::SHA256.digest(OpenSSL::Random.random_bytes(32))[0, 32])')
write_v2_key
unset V2_KEY
}
# Check postgres server DB init status, if necessary, initdb, start/enable service and inject MIQ role
echo "== Checking MIQ database status =="
[[ -d /var/lib/pgsql/data/base ]]
if [ $? -eq 0 ]; then
echo "** DB already initialized"
exit 0
else
echo "** DB has not been initialized"
echo "** Launching initdb"
su postgres -c "initdb -D ${APPLIANCE_PG_DATA}"
test $? -ne 0 && echo "!! Failed to initdb" && exit 1
echo "** Starting postgresql"
su postgres -c "pg_ctl -D ${APPLIANCE_PG_DATA} start"
test $? -ne 0 && echo "!! Failed to start postgresql service" && exit 1
sleep 5
echo "** Creating MIQ role"
su postgres -c "psql -c \"CREATE ROLE root SUPERUSER LOGIN PASSWORD 'smartvm'\""
test $? -ne 0 && echo "!! Failed to inject MIQ root Role" && exit 1
# Check if memcached is running, if not start it
pidof memcached
test $? -ne 0 && /usr/bin/memcached -u memcached -p 11211 -m 64 -c 1024 -l 127.0.0.1 -d
echo "** Starting DB setup"
pushd ${APP_ROOT}
create_v2_key
bundle exec rake evm:db:reset
popd
echo "** MIQ database has been initialized"
generate_miq_server_cert.sh
exit 0
fi