-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.sh
executable file
·92 lines (67 loc) · 2.18 KB
/
serve.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
#!/bin/bash
#Script created to run nginx along with PHP-FPM based on the example by Docker
# Uses external script to make enviroment variables available to PHP
./set_env_variables.sh
echo "Checking if installation is required"
# Starts installation process only if the config.php file is present at the specific location
if [ -f "/var/www/limesurvey/application/config/config.php" ]; then
echo "config.php was provided: installation is required"
# Checks if the host is listening on port 5432
nc -zv $LIME_DBHOST $LIME_DBPORT
status=$?
echo "Checking if DB server is available"
while [ $status -ne 0 ]; do
echo "DB server not available yet"
sleep 2
nc -zv $LIME_DBHOST $LIME_DBPORT
status=$?
done
echo "DB server available"
echo $LIME_DBHOST:$LIME_DBPORT:$LIME_DBNAME:$LIME_DBUSER:$LIME_DBPASSWORD > .pgpass
chmod 600 .pgpass
export PGPASSFILE=.pgpass
# Makes a query to the dabatase to find out if it's available and installed
psql -h $LIME_DBHOST -U $LIME_DBUSER -c 'SELECT count(*) FROM lime_users'
status=$?
if [ $status -ne 0 ]; then
echo "Installing Limesurvey"
# Installs LimesSurvey - creates database and insert basic data
php application/commands/console.php installfromconfig application/config/config.php
status=$?
if [ $status -ne 0 ]; then
echo "Failed to install Limesurvey: $status"
exit $status
fi
echo "Limesurvey installed!"
else
echo "Limesurvey is already installed"
fi
else
echo "config.php was not provided: installation is not required"
fi
# Starts NGINX
/usr/sbin/nginx
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start nginx: $status"
exit $status
fi
# Start PHP-FPM
/usr/sbin/php-fpm7.3
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start php-fpm: $status"
exit $status
fi
while sleep 60; do
ps aux | grep nginx | grep -v grep > /dev/null 2>&1
NGINX_STATUS=$?
ps aux | grep php-fpm | grep -v grep > /dev/null 2>&1
PHPFPM_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $NGINX_STATUS -ne 0 -o $PHPFPM_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done