
#############
#   Redis   #
#############
[nc-directory]
recipe  = slapos.cookbook:mkdirectory
redis     = ${directory:srv}/redis
redis-log = ${directory:log}/redis
data      = ${directory:srv}/data
backup   = ${directory:backup}/nextcloud
tmp       = ${buildout:directory}/tmp

[service-redis]
recipe  = slapos.cookbook:redis.server
wrapper = ${directory:services}/redis
promise-wrapper = ${directory:bin}/redis-promise
server-dir  = ${nc-directory:redis}
config-file = ${directory:etc}/redis.conf
log-file    = ${nc-directory:redis-log}/redis.log
pid-file    = ${directory:run}/redis.pid
use-passwd  = false
unixsocket  = ${:server-dir}/redis.socket
# port = 0 means "don't listen on TCP at all" - listen only on unix socket
ipv6    = ::1
port    = 0
server-bin  = {{ redis_bin }}
cli-bin  = {{ redis_cli }}
depend  =
    ${logrotate-entry-redis:recipe}

[redis-promise]
<= monitor-promise-base
promise = check_command_execute
name = redis.py
config-command = ${service-redis:promise-wrapper}

[logrotate-entry-redis]
<= logrotate-entry-base
name = redis
log     = ${nc-directory:redis-log}/*.log
frequency = daily
rotate-num = 30

[instance-parameter]
nextcloud = ${:document-root}
installed-file = ${directory:etc}/.nextcloud-install-done
admin-user = admin
admin-password = admin
ffmpeg-path = {{ ffmpeg_location }}/bin/ffmpeg
tmp-dir = ${nc-directory:tmp}
trusted-domain-list =
  [${apache-php-configuration:ip}]:${apache-php-configuration:port}
  ${request-frontend:connection-domain}
  ${slap-parameter:instance.trusted-domain-list}

trusted-proxy-list = ${slap-parameter:instance.trusted-proxy-list}
cli-url = ${slap-parameter:instance.cli-url}
data-dir = ${nc-directory:data}
redis-socket = ${service-redis:unixsocket}

#SMTP settings
mail.from = ${slap-parameter:instance.mail-from}
mail.domain = ${slap-parameter:instance.mail-domain}
mail.smtpauthtype = ${slap-parameter:instance.mail-smtpauthtype}
mail.smtpauth = ${slap-parameter:instance.mail-smtpauth}
mail.smtpport = ${slap-parameter:instance.mail-smtpport}
mail.smtphost = ${slap-parameter:instance.mail-smtphost}
mail.smtpname = ${slap-parameter:instance.mail-smtpname}
mail.smtppassword = ${slap-parameter:instance.mail-smtppassword}
# Instance configuration
collabora-url = ${slap-parameter:instance.collabora-url}
stun-server = ${slap-parameter:instance.stun-server}
turn-server = ${slap-parameter:instance.turn-server}
turn-secret = ${slap-parameter:instance.turn-secret}
# php.ini
php.opcache.revalidate-freq = 60
php.opcache.interned-strings-buffer = 24

[nextcloud-install.sh]
recipe = slapos.recipe.template:jinja2
url = {{ nextcloud_install_sh }}
output = ${directory:scripts}/nextcloud-install
context =
  section parameter_dict   instance-parameter
  section nextcloud_apps   nextcloud-apps
depends =
  ${service-redis:recipe}
  ${redis-promise:recipe}
  ${nextcloud-cron:recipe}
  ${nextcloud-optimize:recipe}
  ${nextcloud-backup-cron:recipe}
  ${nextcloud-news-updater:recipe}
  ${nextcloud-config-update:recipe}
  ${nextcloud-install-promise:name}

[nextcloud-apps]
{% for app_name, app_location in nextcloud_apps.items() %}
{{ app_name }} = {{ app_location }}
{%endfor%}

[nextcloud-install-promise]
<= monitor-promise-base
promise = check_command_execute
name = check-nextcloud-install.py
config-command = ${nc-install-wrapper:output}

[nc-install-wrapper]
recipe = collective.recipe.template
input = inline:#!/bin/bash
  if [ -f "${instance-parameter:nextcloud}/config/CAN_INSTALL" ]; then
    echo "Nextcloud is not installed.";
    exit 1;
  fi
  if [ ! -f "${instance-parameter:installed-file}" ]; then
    echo "Nextcloud is not configured.";
    exit 1;
  fi
output = ${directory:bin}/check-nc-install
mode = 744

[nextcloud-cron]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = nextcloud
frequency = */5 * * * *
command = ${php-bin:wrapper-path} -f ${instance-parameter:nextcloud}/cron.php

[nextcloud-optimize-bin]
recipe = collective.recipe.template
input = inline:#!/bin/bash
  {{ redis_cli }} -s ${instance-parameter:redis-socket} <<EOF
  FLUSHALL
  quit
  EOF
  ${php-bin:wrapper-path} ${instance-parameter:nextcloud}/occ files:scan --all
  ${php-bin:wrapper-path} ${instance-parameter:nextcloud}/occ files:scan-app-data
  exit 0
output = ${directory:bin}/nextcloud-optimize
mode = 744

[nextcloud-backup]
recipe = collective.recipe.template
input = inline:#!/bin/bash
  ${php-bin:wrapper-path} ${instance-parameter:nextcloud}/occ app:list --output json > ${nc-directory:backup}/app-list.json
  cp -r ${instance-parameter:nextcloud}/config ${nc-directory:backup}
  exit 0
output = ${directory:bin}/nextcloud-backup
mode = 744

[nextcloud-backup-cron]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = nextcloud-backup
frequency = 0 0 * * *
command = ${nextcloud-backup:output}

[nextcloud-optimize]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = nextcloud-optimize
frequency = 5 1 * * *
command = ${nextcloud-optimize-bin:output}

[nextcloud-news-updater]
recipe = collective.recipe.template
input = inline:#!/bin/sh
  cd {{ news_updater_location }}
  export PATH={{ php_location }}/bin:$PATH
  {{ python3_location}}/bin/python3 -m nextcloud_news_updater --phpini ${php.ini-conf:output} \
    --interval 300 --mode endless --loglevel info ${instance-parameter:nextcloud}
output = ${directory:scripts}/nextcloud-news-updater
mode = 744

[nextcloud-config.json]
recipe = slapos.recipe.template:jinja2
url = {{ nextcloud_parameter_json }}
output = ${directory:etc}/nextcloud-config.json
extensions = jinja2.ext.do
context =
  section parameter_dict   instance-parameter

[nextcloud-config-update]
output = ${directory:scripts}/nextcloud-update
recipe = collective.recipe.template
input = inline:#!/bin/sh
  if [ -f "${instance-parameter:nextcloud}/config/CAN_INSTALL" ]; then
    # do not run this script if nextcloud is not installed yet.
    exit 1;
  fi
  ${php-bin:wrapper-path} ${instance-parameter:nextcloud}/occ config:import ${nextcloud-config.json:output}
mode = 744

[publish-connection-information]
admin-user = ${instance-parameter:admin-user}
admin-password = ${instance-parameter:admin-password}

[slap-parameter]
instance.mail-from = Nextcloud
instance.mail-domain = nextcloud@example.com
instance.mail-smtpauthtype = LOGIN
instance.mail-smtpauth = 1
instance.mail-smtpport = 587
instance.mail-smtphost =
instance.mail-smtpname =
instance.mail-smtppassword =
instance.collabora-url = https://collabora.host.vifib.net/
instance.stun-server = turn.vifib.com:5349
instance.turn-server =
instance.turn-secret =

instance.cli-url = ${apache-php-configuration:url}
instance.trusted-proxy-list =
instance.trusted-domain-list =
