Browse Source

commiting what I have so far

nextcloud/optimization
Mar Alegre 2 years ago
parent
commit
6e5efef072
  1. 1
      mcbe/assets/systemd/mcbe-backup.service
  2. 21
      nextcloud/Containerfile
  3. 11
      nextcloud/assets/bin/db-load
  4. 8
      nextcloud/assets/bin/db-make
  5. 22
      nextcloud/assets/bin/maint-backup
  6. 22
      nextcloud/assets/bin/maint-mode
  7. 9
      nextcloud/assets/bin/maint-scan
  8. 2
      nextcloud/assets/bugfix/cronfix
  9. 8
      nextcloud/assets/systemd/nextcloud-backup.timer
  10. 9
      nextcloud/assets/systemd/nextcloud-cron.service
  11. 9
      nextcloud/assets/systemd/nextcloud-cron.timer
  12. 8
      nextcloud/assets/systemd/nextcloud-scan.service
  13. 8
      nextcloud/assets/systemd/nextcloud-scan.timer
  14. 4
      nextcloud/assets/systemd/nextcloud-updown.service

1
mcbe/assets/systemd/mcbe-backup.service

@ -7,5 +7,4 @@ Requisite=mcbe.service
ExecStart=/usr/local/bin/maint
StandardOutput=journal
StandardError=journal
KillMode=none
Type=oneshot

21
nextcloud/Containerfile

@ -25,7 +25,7 @@ ENV DBNAME=nextcloud
# install packages we want
RUN apt update -y && apt install -y apache2 php-fpm php-gd php-zip php-pgsql \
php-curl php-mbstring php-intl php-imagick php-xml php-gmp php-json \
redis php-redis postgresql postgresql-doc php-ldap php-bcmath cron
redis php-redis postgresql postgresql-doc php-ldap php-bcmath jq
# put database variables in /etc/environment so anyone can access them
@ -72,8 +72,6 @@ COPY --chown=postgres:postgres assets/postgresql ./
RUN mv postgresql/pg_hba.conf /etc/postgresql/${PSQLV:?}/main/ & \
cat postgresql/postgresql.conf >> /etc/postgresql/${PSQLV:?}/main/postgresql.conf
###
### Apache
###
@ -120,22 +118,15 @@ RUN cd nextcloud/config && \
ln -s /vol/data/secret.config.php
###
### DB Auto Load/Dump
### Systemd
###
# copy service
COPY assets/db-updown.service /etc/systemd/system/
# copy services
COPY assets/systemd/ /etc/systemd/system/
# enable service
RUN systemctl enable db-updown.service
###
### Crontab
###
COPY assets/crontab /root/
# crontab for www-data
RUN crontab -u www-data /root/crontab
###
### Bugfix
###
@ -145,10 +136,6 @@ COPY assets/bugfix/redis-server.service /etc/systemd/system/redis-server.service
COPY assets/bugfix/apache2.override /etc/systemd/system/apache2.service.d/override.conf
# bugfix for cron
COPY assets/bugfix/cronfix /root/
RUN chmod +x /root/cronfix && /root/cronfix
###
### Workdir
###

11
nextcloud/assets/bin/db-load

@ -1,9 +1,20 @@
#!/bin/bash
. /usr/local/bin/maint-mode
mode_get
mode_on
if [[ ! -f $1 ]]; then
>&2 echo "Error: could not find file \"$1\""
exit 2
fi
mode=$(nc-occ maintenance:mode | cut -d' ' -f 5)
if [[ $mode != "enabled" ]]; then
nc-occ maintenance:mode --on
fi
db-make
psql -U $DBUSER -d $DBNAME -f $1
mode_off

8
nextcloud/assets/bin/db-make

@ -4,9 +4,17 @@ cmd() {
sudo -u postgres psql -c "$1"
}
. /usr/local/bin/maint-mode
mode_get
mode_on
cd /var/lib/postgresql
cmd "DROP DATABASE IF EXISTS ${DBNAME:?};"
cmd "DROP USER IF EXISTS ${DBUSER:?};"
cmd "CREATE USER ${DBUSER:?};"
cmd "CREATE DATABASE ${DBNAME:?};"
cmd "GRANT ALL PRIVILEGES ON DATABASE ${DBNAME:?} TO ${DBUSER:?};"
redis-cli -s /var/run/redis/redis-server.sock flushall
mode_off

22
nextcloud/assets/bin/maint → nextcloud/assets/bin/maint-backup

@ -1,5 +1,7 @@
#!/bin/bash
. /usr/local/bin/maint-mode
# load environment variables
. /etc/environment
@ -20,23 +22,25 @@ if [[ $# -lt 2 ]]; then
fi
if [[ $hour == $1 ]]; then
nc-occ maintenance:mode --on
mode_get
mode_on
nc-occ maintenance:mode --on
fi
db-dump $DBNAME-hourly-$hour.sql 2>> $errlog
if [[ $hour == $1 ]]; then
systemctl restart postgresql
nc-occ maintenance:mode --off
mv $DBNAME-hourly-$hour.sql $DBNAME-daily-$day.sql 2>> $errlog
systemctl restart postgresql
mode_off
mv $DBNAME-hourly-$hour.sql $DBNAME-daily-$day.sql 2>> $errlog
if [[ $day == $2 ]]; then
mv $DBNAME-daily-$day.sql $DBNAME-$year-$month-$day.sql 2>> $errlog
fi
if [[ $day == $2 ]]; then
mv $DBNAME-daily-$day.sql $DBNAME-$year-$month-$day.sql 2>> $errlog
fi
fi
# If error log is size 0, erase it because I don't like seeing it
if [[ ! -s $errlog ]]; then
rm $errlog
rmdir --ignore-fail-on-non-empty error
rm $errlog
rmdir --ignore-fail-on-non-empty error
fi

22
nextcloud/assets/bin/maint-mode

@ -0,0 +1,22 @@
#!/bin/bash
mode_get() {
mode=$(nc-occ maintenance:mode | cut -d' ' -f 5)
if [[ $mode == "enabled" || $mode == "disabled" ]]; then
echo $mode
return 0
else
echo "Error: failed to get maintenance mode" 1>&2
return 1
fi
}
mode_on() {
nc-occ maintenance:mode --on
}
mode_off() {
if [[ $mode == "disabled" ]]; then
nc-occ maintenance:mode --off
fi
}

9
nextcloud/assets/bin/maint-scan

@ -0,0 +1,9 @@
#!/bin/bash
if [[ -n $1 ]]; then
nc-occ files:scan --path="/$1/files/"
else
for user in $(nc-occ user:list --output=json | jq -r 'keys[]'); do
nc-occ files:scan --path="/$user/files/"
done
fi

2
nextcloud/assets/bugfix/cronfix

@ -1,2 +0,0 @@
#!/bin/sh
sed -i '/session required pam_loginuid.so/c\#session required pam_loginuid.so' /etc/pam.d/cron

8
nextcloud/assets/systemd/nextcloud-backup.timer

@ -0,0 +1,8 @@
[Unit]
Description=Scan files every 15 minutes
[Timer]
OnCalendar=0/15:00
[Install]
WantedBy=timers.target

9
nextcloud/assets/systemd/nextcloud-cron.service

@ -0,0 +1,9 @@
[Unit]
Description=Nextcloud cron.php job
[Service]
User=www-data
ExecStart=/usr/bin/php -f /var/www/nextcloud/cron.php
StandardOutput=journal
StandardError=journal
KillMode=process

9
nextcloud/assets/systemd/nextcloud-cron.timer

@ -0,0 +1,9 @@
[Unit]
Description=Run Nextcloud cron.php every 5 minutes
[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target

8
nextcloud/assets/systemd/nextcloud-scan.service

@ -0,0 +1,8 @@
[Unit]
Description=Scan Nextcloud files for changes
[Service]
ExecStart=/usr/local/bin/maint-scan
StandardOutput=journal
StandardError=journal
Type=oneshot

8
nextcloud/assets/systemd/nextcloud-scan.timer

@ -0,0 +1,8 @@
[Unit]
Description=Scan files every 15 minutes
[Timer]
OnCalendar=0/15:00
[Install]
WantedBy=timers.target

4
nextcloud/assets/db-updown.service → nextcloud/assets/systemd/nextcloud-updown.service

@ -1,6 +1,6 @@
[Unit]
Description=Load/Dump database on start/stop
After=postgresql.service
After=postgresql.service php*
Requires=postgresql.service
[Service]
@ -8,7 +8,7 @@ Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c "if [[ $(ls -t /vol/data/sql/ | head -1) == $DBNAME-updown.sql ]]; then db-load /vol/data/sql/$DBNAME-updown.sql; else echo 'updown.sql is not most recent file in database dir, skipping db-load'; fi"
ExecStop=/bin/bash -c "db-dump /vol/data/sql/$DBNAME-updown.sql"
ExecStop=/bin/bash -c "nc-occ maintenance:mode --on; db-dump /vol/data/sql/$DBNAME-updown.sql"
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save