-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.sh
More file actions
executable file
·86 lines (70 loc) · 1.84 KB
/
exec.sh
File metadata and controls
executable file
·86 lines (70 loc) · 1.84 KB
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
#! /bin/sh
DEBUG=false
NULL="/dev/null"
PRINT_NULL="> $NULL 2> $NULL"
if $DEBUG; then
echo ""
whoami
echo "says hello world!"
echo "from Docker!"
echo ""
lsb_release -a
uname -a
echo ""
cat /etc/os-release
echo ""
fi
os_id=$(grep "^\(ID\|id\)=" /etc/os-release | awk -F= '{print $2}')
if $DEBUG; then
echo "Detected OS ID: $os_id"
echo ""
fi
if $DEBUG; then
echo "Starting PostgreSQL Cluster..."
fi
if [ "$os_id" = 'debian' ] ; then
debian_pg_start="/usr/bin/pg_ctlcluster 9.6 main start"
if $DEBUG; then
eval $debian_pg_start && echo "Started cluster!" || echo "Failed to start cluster!";
else
eval "$debian_pg_start $PRINT_NULL"
fi
else
if [ "$os_id" = 'alpine' ] ; then
md="mkdir -vp"
pg_r_dir="/run/postgresql"
pg_vr_dir="/var/run/postgresql"
pg_data="/var/lib/postgresql/data"
pg_user="postgres"
pg_cmd="postgres &"
ch_own="chown -R $pg_user:$pg_user"
ch_mod_rd="chmod -v 775 $pg_r_dir"
ch_mod_vrd="chmod -v 2777 $pg_vr_dir"
su_pg="su - $pg_user -c"
exprt="export PGDATA=$pg_data"
start_pg="$su_pg \"$exprt && $pg_cmd\""
validation="echo \"Started cluster!\" || echo \"Failed to start cluster!\""
if $DEBUG; then
cmd="$md $pg_r_dir && $ch_own $pg_r_dir && $ch_mod_rd && $md $pg_vr_dir && $ch_own $pg_vr_dir && $ch_mod_vrd && $start_pg && $validation"
else
cmd="$md $pg_r_dir $PRINT_NULL && $ch_own $pg_r_dir $PRINT_NULL && $ch_mod_rd $PRINT_NULL && $md $pg_vr_dir $PRINT_NULL && $ch_own $pg_vr_dir $PRINT_NULL && $ch_mod_vrd $PRINT_NULL && $start_pg $PRINT_NULL"
fi
eval $cmd
sleep 10s
else
if $DEBUG; then
echo "Unknown/Unsupported OS";
fi
exit 1;
fi
fi
if $DEBUG; then
echo ""
fi
init_db="su - user -c \"psql -U user userdb -f /code/init.sql\""
if $DEBUG; then
eval $init_db
else
eval "$init_db $PRINT_NULL"
fi
su - user -c "psql -U user userdb -f /code/main.sql"