2015-11-16 03:57:07 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Create a bunch of folders under the clean /var that php and nginx expect to exist
|
|
|
|
mkdir -p /var/lib/nginx
|
2020-06-13 21:49:54 +00:00
|
|
|
mkdir -p /var/lib/php/sessions
|
2015-11-16 03:57:07 +00:00
|
|
|
mkdir -p /var/log
|
|
|
|
mkdir -p /var/log/nginx
|
|
|
|
mkdir -p /var/www
|
|
|
|
# Wipe /var/run, since pidfiles and socket files from previous launches should go away
|
|
|
|
# TODO someday: I'd prefer a tmpfs for these.
|
|
|
|
rm -rf /var/run
|
|
|
|
mkdir -p /var/run
|
|
|
|
|
|
|
|
# Spawn php
|
2020-06-03 14:32:15 +00:00
|
|
|
/usr/sbin/php-fpm7.0 -R --nodaemonize --fpm-config /etc/php/7.0/fpm/php-fpm.conf &
|
2015-11-16 03:57:07 +00:00
|
|
|
# Wait until php have bound its socket, indicating readiness
|
2020-06-03 14:32:15 +00:00
|
|
|
while [ ! -e /var/run/php-fpm7.0.sock ] ; do
|
|
|
|
echo "waiting for php-fpm7.0 to be available at /var/run/php-fpm7.0.sock"
|
2016-04-19 01:50:30 +00:00
|
|
|
sleep .2
|
2015-11-16 03:57:07 +00:00
|
|
|
done
|
|
|
|
|
2016-04-19 01:50:30 +00:00
|
|
|
mkdir -p /var/lib/dokuwiki/lib/plugins/sandstorm
|
2015-11-16 03:57:07 +00:00
|
|
|
|
2016-04-19 01:50:30 +00:00
|
|
|
if [ ! -e /var/lib/dokuwiki/conf/local.php ]; then
|
|
|
|
echo Adding new configuration.
|
|
|
|
rsync -a /opt/app/dokuwiki/conf.orig/ /var/lib/dokuwiki/conf
|
|
|
|
cp /opt/app/local.php /var/lib/dokuwiki/conf
|
2015-11-16 03:57:07 +00:00
|
|
|
fi
|
2017-03-14 19:03:27 +00:00
|
|
|
rm -f /var/lib/dokuwiki/conf/conf
|
2020-06-23 21:38:48 +00:00
|
|
|
# sandstorm-specific things go here
|
|
|
|
cp /opt/app/local.protected.php /var/lib/dokuwiki/conf
|
2015-11-16 03:57:07 +00:00
|
|
|
|
2016-04-19 01:50:30 +00:00
|
|
|
if [ ! -e /var/lib/dokuwiki/data ]; then
|
|
|
|
echo Adding data.
|
|
|
|
rsync -a /opt/app/dokuwiki/data.orig/ /var/lib/dokuwiki/data
|
|
|
|
fi
|
2017-03-14 19:03:27 +00:00
|
|
|
rm -f /var/lib/dokuwiki/data/data
|
2016-04-19 01:50:30 +00:00
|
|
|
|
|
|
|
rsync -a /opt/app/dokuwiki/lib/plugins.orig/ /var/lib/dokuwiki/lib/plugins
|
2017-03-14 19:03:27 +00:00
|
|
|
rm -f /var/lib/dokuwiki/lib/plugins/plugins
|
2016-04-19 01:50:30 +00:00
|
|
|
rsync -a /opt/app/plugin/ /var/lib/dokuwiki/lib/plugins/sandstorm
|
|
|
|
|
|
|
|
if [ ! -e /var/lib/dokuwiki/lib/tpl ]; then
|
|
|
|
echo Adding templates.
|
|
|
|
rsync -a /opt/app/dokuwiki/lib/tpl.orig/ /var/lib/dokuwiki/lib/tpl
|
|
|
|
fi
|
2017-03-14 19:03:27 +00:00
|
|
|
rm -f /var/lib/dokuwiki/lib/tpl/tpl
|
2016-04-19 01:50:30 +00:00
|
|
|
|
|
|
|
cd /var/lib/dokuwiki
|
|
|
|
grep -Ev '^($|#)' /opt/app/dokuwiki/data.orig/deleted.files | xargs -n 1 rm -vrf
|
|
|
|
|
2016-11-17 12:50:00 +00:00
|
|
|
cp /opt/app/acl.auth.php /var/lib/dokuwiki/conf
|
|
|
|
|
2017-03-14 19:26:26 +00:00
|
|
|
function cleanup()
|
|
|
|
{
|
|
|
|
local data_path="$1" # full path to data directory of wiki
|
|
|
|
local retention_days="$2" # number of days after which old files are to be removed
|
2017-03-14 19:58:51 +00:00
|
|
|
|
2017-03-14 19:26:26 +00:00
|
|
|
# purge files older than ${retention_days} days from attic and media_attic (old revisions)
|
|
|
|
find "${data_path}"/{media_,}attic/ -type f -mtime +${retention_days} -delete
|
2017-03-14 19:58:51 +00:00
|
|
|
|
2017-03-14 19:26:26 +00:00
|
|
|
# remove stale lock files (files which are 1-2 days old)
|
|
|
|
find "${data_path}"/locks/ -name '*.lock' -type f -mtime +1 -delete
|
2017-03-14 19:58:51 +00:00
|
|
|
|
2017-03-14 19:26:26 +00:00
|
|
|
# remove empty directories
|
|
|
|
find "${data_path}"/{attic,cache,index,locks,media,media_attic,media_meta,meta,pages,tmp}/ \
|
|
|
|
-mindepth 1 -type d -empty -delete
|
2017-03-14 19:58:51 +00:00
|
|
|
|
2017-03-14 19:26:26 +00:00
|
|
|
# remove files older than ${retention_days} days from the cache
|
2017-03-14 19:58:51 +00:00
|
|
|
if [ ! -z "$(ls -A $data_path/cache)" ]; then
|
2017-03-14 19:26:26 +00:00
|
|
|
find "${data_path}"/cache/?/ -type f -mtime +${retention_days} -delete
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup /var/lib/dokuwiki/data 30
|
|
|
|
|
2015-11-16 03:57:07 +00:00
|
|
|
# Start nginx.
|
2016-10-13 23:04:44 +00:00
|
|
|
/usr/sbin/nginx -c /opt/app/.sandstorm/service-config/nginx.conf -g "daemon off;"
|