This repository has been archived by the owner on Oct 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint
executable file
·93 lines (76 loc) · 2.75 KB
/
entrypoint
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
set -e
HOME_DIR=/var/www/html/nextcloud
OCC="sudo -u www-data php $HOME_DIR/occ "
########### begin apache
#### cleanup
source /etc/apache2/envvars
# Cleanup locks
for i in "$APACHE_PID_FILE" ; do
rm -fr "$i"
done
# Ensure directories exist
for i in "$(dirname $APACHE_PID_FILE)" "$APACHE_LOCK_DIR" ; do
mkdir -p "$i"
done
########### end apache
########### begin nextcloud
# Restore original apps because of volume mount when directory is empty
rsync -a /opt/apps_original/ /var/www/html/nextcloud/apps/
chown -R www-data:www-data /var/www/html/nextcloud/apps
# Wait for database to come up
wait_for_db=$(mktemp)
cat << EOF > $wait_for_db
<?php
\$connected = false;
while(!\$connected) {
try{
\$dbh = new pdo(
'mysql:host=$DB_HOST;dbname=$DB_NAME', '$DB_USER', '$DB_PASSWORD',
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
\$connected = true;
}
catch(PDOException \$ex){
error_log("Could not connect to MySQL");
error_log(\$ex->getMessage());
error_log("Waiting for MySQL Connection.");
sleep(5);
}
}
EOF
php $wait_for_db
# Ensure permissions are correct
chown -R www-data:www-data $HOME_DIR/config $HOME_DIR/data $HOME_DIR/apps $HOME_DIR/.htaccess
echo "Check if already installed..."
set +e
$OCC status | grep installed | grep false
installed=$?
set -e
if [ $installed -eq 0 ] ; then
echo "Nextcloud not installed, proceeding with initial setup"
$OCC maintenance:install \
--database "mysql" \
--database-host="$DB_HOST" \
--database-port=3306 \
--database-name "$DB_NAME" \
--database-user "$DB_USER" \
--database-pass "$DB_PASSWORD" \
--admin-user "$ADMIN_USER" \
--admin-pass "$ADMIN_PASSWORD" \
--no-interaction
fi
# Maybe use import? see https://docs.nextcloud.com/server/10/admin_manual/configuration_server/occ_command.html#config-commands-label
$OCC config:system:set trusted_domains 1 --value "$TRUSTED_DOMAIN"
$OCC config:system:set overwrite.cli.url --value "https://$TRUSTED_DOMAIN"
$OCC config:system:set overwriteprotocol --value "https"
$OCC config:system:set forcessl --value "true" --type boolean
$OCC config:system:set memcache.local --value '\OC\Memcache\APCu'
$OCC config:system:set memcache.locking --value '\OC\Memcache\Redis'
$OCC config:system:set redis host --value "redis"
$OCC config:system:set redis port --value "6379"
$OCC maintenance:update:htaccess
# Cleanup unused files from home
rm -f $HOME_DIR/.rnd
############ begin apache
tail -F /var/log/apache2/* & exec apache2 -D FOREGROUND