Merge pull request #88 from nupplaphil/task/mysql_wait

Add MySQL DB wait possibility
This commit is contained in:
Hypolite Petovan 2019-11-28 16:08:36 -05:00 committed by GitHub
commit ba7371ad99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 692 additions and 361 deletions

47
.bin/wait-for-connection Executable file
View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -24,7 +24,8 @@ services:
- FRIENDICA_ADMIN_MAIL= - FRIENDICA_ADMIN_MAIL=
- FRIENDICA_TZ= - FRIENDICA_TZ=
- FRIENDICA_LANG= - FRIENDICA_LANG=
- SITENAME= - FRIENDICA_URL=
- FRIENDICA_SITENAME=
- SMTP= - SMTP=
env_file: env_file:
- db.env - db.env
@ -42,6 +43,8 @@ services:
entrypoint: /cron.sh entrypoint: /cron.sh
depends_on: depends_on:
- db - db
env_file:
- db.env
hostname: friendica.local hostname: friendica.local
volumes: volumes:

View File

@ -24,8 +24,9 @@ services:
- FRIENDICA_ADMIN_MAIL= - FRIENDICA_ADMIN_MAIL=
- FRIENDICA_TZ= - FRIENDICA_TZ=
- FRIENDICA_LANG= - FRIENDICA_LANG=
- SITENAME= - FRIENDICA_URL=
- SMTP= - FRIENDICA_SITENAME=
- SMTP=
env_file: env_file:
- db.env - db.env
depends_on: depends_on:

View File

@ -24,7 +24,8 @@ services:
- FRIENDICA_ADMIN_MAIL= - FRIENDICA_ADMIN_MAIL=
- FRIENDICA_TZ= - FRIENDICA_TZ=
- FRIENDICA_LANG= - FRIENDICA_LANG=
- SITENAME= - FRIENDICA_URL=
- FRIENDICA_SITENAME=
- SMTP= - SMTP=
env_file: env_file:
- db.env - db.env

View File

@ -1,78 +1,76 @@
version: '2.1' version: '2.1'
services: services:
db: db:
image: mariadb image: mariadb
restart: always restart: always
volumes: volumes:
- db:/var/lib/mysql/ - db:/var/lib/mysql/
environment: environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes - MYSQL_RANDOM_ROOT_PASSWORD=yes
env_file: env_file:
- db.env - db.env
app: app:
build: ./app build: ./app
restart: always restart: always
volumes: volumes:
- friendica:/var/www/html - friendica:/var/www/html
environment: environment:
- AUTOINSTALL=true - FRIENDICA_ADMIN_MAIL=
- MAILNAME= - FRIENDICA_TZ=
- TZ= - FRIENDICA_LANG=
- LANGUAGE= - FRIENDICA_URL=
env_file: - FRIENDICA_SITENAME=
- db.env - SMTP=
depends_on: env_file:
- db - db.env
hostname: friendica.local depends_on:
labels: - db
- "traefik.backend=friendica" hostname: friendica.local
- "traefik.frontend.entryPoints=https" labels:
- "traefik.frontend.headers.SSLRedirect=true" - "traefik.backend=friendica"
- "traefik.frontend.headers.STSSeconds=15768000" - "traefik.frontend.entryPoints=https"
- "traefik.frontend.headers.STSIncludeSubdomains=false" - "traefik.frontend.headers.SSLRedirect=true"
- "traefik.frontend.headers.forceSTSHeader=true" - "traefik.frontend.headers.STSSeconds=15768000"
- "traefik.friendica.frontend.rule=Host:friendica.local" - "traefik.frontend.headers.STSIncludeSubdomains=false"
- "traefik.friendica.frontend.port=80" - "traefik.frontend.headers.forceSTSHeader=true"
- "traefik.enable=true" - "traefik.friendica.frontend.rule=Host:friendica.local"
- "traefik.docker.network=proxy-tier" - "traefik.friendica.frontend.port=80"
networks: - "traefik.enable=true"
- proxy-tier - "traefik.docker.network=proxy-tier"
- default networks:
- proxy-tier
cron: - default
build: ./app
restart: always cron:
volumes: build: ./app
- friendica:/var/www/html restart: always
entrypoint: /cron.sh volumes:
environment: - friendica:/var/www/html
- MAILNAME= entrypoint: /cron.sh
- TZ= env_file:
- LANGUAGE= - db.env
env_file: depends_on:
- db.env - db
depends_on: hostname: friendica.local
- db
hostname: friendica.local proxy:
build: ./proxy
proxy: restart: always
build: ./proxy ports:
restart: always - "80:80"
ports: - "443:443"
- "80:80" volumes:
- "443:443" - /var/run/docker.sock:/var/run/docker.sock
volumes: container_name: traefik
- /var/run/docker.sock:/var/run/docker.sock networks:
container_name: traefik - default
networks: - proxy-tier
- default
- proxy-tier volumes:
db:
volumes: friendica:
db:
friendica: networks:
networks:
proxy-tier: proxy-tier:

View File

@ -20,6 +20,9 @@ services:
- FRIENDICA_ADMIN_MAIL= - FRIENDICA_ADMIN_MAIL=
- FRIENDICA_TZ= - FRIENDICA_TZ=
- FRIENDICA_LANG= - FRIENDICA_LANG=
- FRIENDICA_URL=
- FRIENDICA_SITENAME=
- SMTP=
env_file: env_file:
- db.env - db.env
depends_on: depends_on:
@ -32,10 +35,6 @@ services:
volumes: volumes:
- friendica:/var/www/html - friendica:/var/www/html
entrypoint: /cron.sh entrypoint: /cron.sh
environment:
- MAILNAME=
- TZ=
- LANGUAGE=
env_file: env_file:
- db.env - db.env
depends_on: depends_on:

View File

@ -1,87 +1,85 @@
version: '2.1' version: '2.1'
services: services:
db: db:
image: mariadb image: mariadb
restart: always restart: always
volumes: volumes:
- db:/var/lib/mysql/ - db:/var/lib/mysql/
environment: environment:
- MYSQL_RANDOM_ROOT_PASSWORD=yes - MYSQL_RANDOM_ROOT_PASSWORD=yes
env_file: env_file:
- db.env - db.env
app: app:
build: ./app build: ./app
restart: always restart: always
volumes: volumes:
- friendica:/var/www/html - friendica:/var/www/html
environment: environment:
- AUTOINSTALL=true - FRIENDICA_ADMIN_MAIL=
- MAILNAME= - FRIENDICA_TZ=
- TZ= - FRIENDICA_LANG=
- LANGUAGE= - FRIENDICA_URL=
env_file: - FRIENDICA_SITENAME=
- db.env - SMTP=
depends_on: env_file:
- db - db.env
hostname: friendica.local depends_on:
- db
cron: hostname: friendica.local
build: ./app
restart: always cron:
volumes: build: ./app
- friendica:/var/www/html restart: always
entrypoint: /cron.sh volumes:
environment: - friendica:/var/www/html
- MAILNAME= entrypoint: /cron.sh
- TZ= env_file:
- LANGUAGE= - db.env
env_file: depends_on:
- db.env - db
depends_on: - app
- db hostname: friendica.local
- app
hostname: friendica.local web:
image: nginx
web: restart: always
image: nginx volumes:
restart: always - friendica:/var/www/html:ro
volumes: - ./web/nginx.conf:/etc/nginx/nginx.conf:ro
- friendica:/var/www/html:ro depends_on:
- ./web/nginx.conf:/etc/nginx/nginx.conf:ro - app
depends_on: networks:
- app - default
networks: - proxy-tier
- default labels:
- proxy-tier - "traefik.backend=friendica"
labels: - "traefik.frontend.entryPoints=https,http"
- "traefik.backend=friendica" - "traefik.frontend.headers.STSSeconds=15768000"
- "traefik.frontend.entryPoints=https,http" - "traefik.frontend.headers.STSIncludeSubdomains=false"
- "traefik.frontend.headers.STSSeconds=15768000" - "traefik.frontend.headers.forceSTSHeader=true"
- "traefik.frontend.headers.STSIncludeSubdomains=false" - "traefik.friendica.frontend.rule=Host:friendica.local"
- "traefik.frontend.headers.forceSTSHeader=true" - "traefik.friendica.frontend.port=80"
- "traefik.friendica.frontend.rule=Host:friendica.local" - "traefik.enable=true"
- "traefik.friendica.frontend.port=80" - "traefik.docker.network=proxy-tier"
- "traefik.enable=true"
- "traefik.docker.network=proxy-tier" proxy:
build: ./proxy
proxy: restart: always
build: ./proxy ports:
restart: always - "80:80"
ports: - "443:443"
- "80:80" volumes:
- "443:443" - /var/run/docker.sock:/var/run/docker.sock
volumes: container_name: traefik
- /var/run/docker.sock:/var/run/docker.sock networks:
container_name: traefik - default
networks: - proxy-tier
- default
- proxy-tier volumes:
db:
volumes: friendica:
db:
friendica: networks:
networks:
proxy-tier: proxy-tier:

View File

@ -140,6 +140,7 @@ RUN set -ex; \
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"] CMD ["apache2-foreground"]

View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -116,6 +116,7 @@ RUN set -ex; \
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"] CMD ["php-fpm"]

View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -131,6 +131,7 @@ RUN set -ex; \
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"] CMD ["php-fpm"]

View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -126,6 +126,7 @@ ENV FRIENDICA_ADDONS 2019.12-dev
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/entrypoint-dev.sh"] ENTRYPOINT ["/entrypoint-dev.sh"]
CMD ["apache2-foreground"] CMD ["apache2-foreground"]

View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -102,6 +102,7 @@ ENV FRIENDICA_ADDONS 2019.12-dev
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/entrypoint-dev.sh"] ENTRYPOINT ["/entrypoint-dev.sh"]
CMD ["php-fpm"] CMD ["php-fpm"]

View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -117,6 +117,7 @@ ENV FRIENDICA_ADDONS 2019.12-dev
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/entrypoint-dev.sh"] ENTRYPOINT ["/entrypoint-dev.sh"]
CMD ["php-fpm"] CMD ["php-fpm"]

View File

@ -0,0 +1,47 @@
#!/usr/local/bin/php
<?php
/**
* This script tries to connect to a database for a given interval
* Useful in case of installation e.g. to wait for the database to not generate unnecessary errors
*
* Usage: php bin/wait-for-connection {HOST} {PORT} [{TIMEOUT}]
*/
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -101,6 +101,7 @@ ENV FRIENDICA_ADDONS %%VERSION%%
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/%%ENTRYPOINT%%"] ENTRYPOINT ["/%%ENTRYPOINT%%"]
CMD ["%%CMD%%"] CMD ["%%CMD%%"]

View File

@ -116,6 +116,7 @@ ENV FRIENDICA_ADDONS %%VERSION%%
COPY *.sh upgrade.exclude / COPY *.sh upgrade.exclude /
COPY config/* /usr/src/friendica/config/ COPY config/* /usr/src/friendica/config/
COPY bin/* /usr/local/bin/
ENTRYPOINT ["/%%ENTRYPOINT%%"] ENTRYPOINT ["/%%ENTRYPOINT%%"]
CMD ["%%CMD%%"] CMD ["%%CMD%%"]

View File

@ -67,7 +67,7 @@ There are three options to enable the cron-job for Friendica:
## Possible Environment Variables ## Possible Environment Variables
**Friendica Settings** **Friendica Settings**
- `FRIENDICA_ADMIN_MAIL` E-Mail address of the administrator. - `FRIENDICA_URL` The Friendica URL path.
- `FRIENDICA_TZ` The default localization of the Friendica server. - `FRIENDICA_TZ` The default localization of the Friendica server.
- `FRIENDICA_LANG` The default language of the Friendica server. - `FRIENDICA_LANG` The default language of the Friendica server.
- `FRIENDICA_PHP_PATH` The path of the PHP binary. - `FRIENDICA_PHP_PATH` The path of the PHP binary.

View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/sh
trap "break;exit" HUP INT TERM trap "break;exit" HUP INT TERM
while [ ! -f /var/www/html/config/local.ini.php ] && [ ! -f /var/www/html/config/local.config.php ]; do while [ ! -f /var/www/html/bin/daemon.php ]; do
sleep 1 sleep 1
done done
# TODO let the database and the autoinstall time to complete - not winning a beauty contest echo "Waiting for MySQL $MYSQL_HOST initialization..."
sleep 15s if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
exec php /var/www/html/bin/daemon.php -f start
exec php /var/www/html/bin/daemon.php -f start echo "[ERROR] Waited 300 seconds, no response" >&2
fi

View File

@ -17,14 +17,14 @@ version_greater() {
} }
setup_ssmtp() { setup_ssmtp() {
if [ -n "${SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then if [ -n "${FRIENDICA_SITENAME+x}" ] && [ -n "${SMTP+x}" ] && [ "${SMTP}" != "localhost" ]; then
echo "Setup SSMTP for '$SITENAME' with '$SMTP' ..." echo "Setup SSMTP for '$FRIENDICA_SITENAME' with '$SMTP' ..."
smtp_from=${SMTP_FROM:-no-reply} smtp_from=${SMTP_FROM:-no-reply}
# Setup SSMTP # Setup SSMTP
sed -i "s/:root:/:${SITENAME}:/g" /etc/passwd sed -i "s/:root:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
sed -i "s/:Linux\ User:/:${SITENAME}:/g" /etc/passwd sed -i "s/:Linux\ User:/:${FRIENDICA_SITENAME}:/g" /etc/passwd
# add possible mail-senders # add possible mail-senders
{ {
@ -100,7 +100,7 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
echo "New Friendica instance" echo "New Friendica instance"
install=false install=false
if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n ${FRIENDICA_ADMIN_MAIL+x} ]; then if [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ] && [ -n "${MYSQL_USER+x}" -o -n "${MYSQL_USERNAME+x}" ] && [ -n "${FRIENDICA_ADMIN_MAIL+x}" ] && [ -n "${FRIENDICA_URL+x}" ]; then
echo "Installation with environment variables" echo "Installation with environment variables"
FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php} FRIENDICA_PHP_PATH=${FRIENDICA_PHP_PATH:-/usr/local/php}
@ -117,30 +117,28 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ]; then
install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"' install_options='-s --dbhost "'$MYSQL_HOST'" --dbport "'$MYSQL_PORT'" --dbdata "'$MYSQL_DATABASE'" --dbuser "'$MYSQL_USERNAMEFULL'" --dbpass "'$MYSQL_PASSWORD'"'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'"' install_options=$install_options' --admin "'$FRIENDICA_ADMIN_MAIL'" --tz "'$FRIENDICA_TZ'" --lang "'$FRIENDICA_LANG'" --url "'$FRIENDICA_URL'"'
install=true
elif [ -f "/usr/src/config/local.config.php" ]; then
echo "Installation with prepared local.config.php"
install_options="-f /usr/src/local.config.php"
install=true install=true
fi fi
if [ "$install" = true ]; then if [ "$install" = true ]; then
echo "Starting Friendica installation ..." echo "Waiting for MySQL $MYSQL_HOST initialization..."
# TODO Let the database time to warm up - not winning a beauty contest if /usr/local/bin/wait-for-connection "$MYSQL_HOST" "$MYSQL_PORT" 300; then
sleep 10s
run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# TODO Workaround because of a strange permission issue echo "Starting Friendica installation ..."
rm -fr /var/www/html/view/smarty3/compiled run_as "php /var/www/html/bin/console.php autoinstall $install_options"
# load other config files (*.config.php) to the config folder rm -fr /var/www/html/view/smarty3/compiled
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/ # load other config files (*.config.php) to the config folder
if [ -d "/usr/src/config" ]; then
rsync $rsync_options --ignore-existing /usr/src/config/ /var/www/html/config/
fi
echo "Installation finished"
else
echo "[ERROR] Waited 300 seconds, no response" >&2
fi fi
echo "Installation finished"
else else
echo "Running web-based installer on first connect!" echo "Running web-based installer on first connect!"
fi fi

View File

@ -135,6 +135,7 @@ function create_variant() {
cp upgrade.exclude "$dir/" cp upgrade.exclude "$dir/"
cp -rT .config "$dir/config" cp -rT .config "$dir/config"
cp -rT .bin "$dir/bin"
travisEnvAmd64='\n - env: VERSION='"$dockerName"' VARIANT='"$variant"' ARCH=amd64'"$travisEnvAmd64" travisEnvAmd64='\n - env: VERSION='"$dockerName"' VARIANT='"$variant"' ARCH=amd64'"$travisEnvAmd64"
for arch in i386 amd64; do for arch in i386 amd64; do