Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nc21 #111

Merged
merged 18 commits into from
Jun 4, 2021
Merged

nc21 #111

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions createlinks
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ event_templates("nethserver-nextcloud-update", qw(
/etc/httpd/conf.d/default-virtualhost.inc
/etc/httpd/conf.d/nextcloud.conf
/etc/httpd/conf.d/zz_nextcloud.conf
/etc/opt/rh/rh-mariadb105/my.cnf.d/mariadb-server.cnf
));

event_services("nethserver-nextcloud-update", qw(
httpd restart
rh-php73-php-fpm restart
rh-mariadb105-mariadb@nextcloud restart
));

event_templates("nethserver-nextcloud-save", qw(
Expand All @@ -60,3 +62,12 @@ event_actions("nethserver-nextcloud-save", qw(
event_actions("interface-update", qw(
nethserver-nextcloud-occ-conf 91
));

# link to backup and restore event
event_actions("pre-backup-data", qw(
nethserver-nextcloud-rh-mariadb105-dump-database 60
));

event_actions("post-restore-data", qw(
nethserver-nextcloud-restore-rh-mariadb105-database 03
));
9 changes: 6 additions & 3 deletions nethserver-nextcloud.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ License: GPL
Source0: %{name}-%{version}.tar.gz
Source1: %{name}.tar.gz

%define nc_version 20.0.10
%define nc_version 21.0.2
Source2: https://download.nextcloud.com/server/releases/nextcloud-%{nc_version}.tar.bz2

BuildArch: noarch
Expand All @@ -17,7 +17,7 @@ BuildRequires: nethserver-devtools
Provides: nextcloud
Obsoletes: nextcloud
Requires: nethserver-httpd
Requires: nethserver-mysql
Requires: nethserver-rh-mariadb105 rh-mariadb105-mariadb-server-utils
Requires: nethserver-rh-php73-php-fpm >= 1.0.0
Requires: samba-client

Expand Down Expand Up @@ -68,9 +68,11 @@ tar xvf %{SOURCE1} -C %{buildroot}/usr/share/cockpit/%{name}/
cp -a %{name}.json %{buildroot}/usr/share/cockpit/nethserver/applications/
cp -a api/* %{buildroot}/usr/libexec/nethserver/api/%{name}/

mkdir -p %{buildroot}/var/opt/rh/rh-mariadb105/lib/mysql-nextcloud

%{genfilelist} %{buildroot} \
--file /etc/sudoers.d/50_nsapi_nethserver_nextcloud 'attr(0440,root,root)' \
--dir /var/lib/nethserver/nextcloud 'attr(0755,apache,apache)' | grep -v '/usr/share/nextcloud' > %{name}-%{version}-filelist
--dir /var/lib/nethserver/nextcloud 'attr(0755,apache,apache)' | grep -v -e '/usr/share/nextcloud' -e '/var/opt/rh/rh-mariadb105/lib/mysql-nextcloud' > %{name}-%{version}-filelist


%files -f %{name}-%{version}-filelist
Expand All @@ -81,6 +83,7 @@ cp -a api/* %{buildroot}/usr/libexec/nethserver/api/%{name}/
%config(noreplace) %{_sysconfdir}/opt/rh/rh-php73/php-fpm.d/000-nextcloud.conf
%config(noreplace) %attr(0644,apache,apache) /usr/share/nextcloud/.user.ini
%dir %attr(0755,root,apache) /usr/share/nextcloud
%dir %attr(0755,mysql,mysql) /var/opt/rh/rh-mariadb105/lib/mysql-nextcloud
%attr(-,apache,apache) /usr/share/nextcloud
%attr(0755,apache,apache) /usr/share/nextcloud/occ
%attr(0775,apache,apache) /usr/share/nextcloud/data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enabled
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service
88 changes: 81 additions & 7 deletions root/etc/e-smith/events/actions/nethserver-nextcloud-conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
source /opt/rh/rh-mariadb105/enable

function OCC
{
Expand All @@ -8,23 +9,95 @@ function OCC
TERM=dumb runuser -s /bin/bash apache -c "php -dmemory_limit=512M ./occ $params"
}

exitOnError () {
stephdl marked this conversation as resolved.
Show resolved Hide resolved
echo $1
OCC "maintenance:mode --off"
exit 1
}

password=`perl -e "use NethServer::Password; print NethServer::Password::store('nextcloud');"`

# initialize grants mysql nextcloud database
/usr/bin/mysql --defaults-file=/root/.my.cnf -e "CREATE DATABASE IF NOT EXISTS nextcloud;"
/usr/bin/mysql --defaults-file=/root/.my.cnf -e "grant all on nextcloud.* to 'nextcloud'@'localhost' identified by '$password';"
/usr/bin/mysql --defaults-file=/root/.my.cnf -e "FLUSH PRIVILEGES"
systemctl is-active --quiet rh-mariadb105-mariadb@nextcloud
if [[ $? -ne 0 ]]; then
systemctl start rh-mariadb105-mariadb@nextcloud
max_wait=20
wait=0
while ! mysql --socket /run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "SHOW DATABASES" 2>/dev/null; do
sleep 1
wait=$((wait+1))
if [[ $wait -ge $max_wait ]]; then
echo "[ERROR] Can't start rh-mariadb105-mariadb@nextcloud"
exit 1
fi
done
fi
# verify if the db exists and if mysql is installed
database=""
if [[ -x '/usr/bin/mysql' ]]; then
database=$(/usr/bin/mysql -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'nextcloud'")
fi

if [[ -n $database ]]; then
# we still use mariadb55, this is wrong we need rh-mariadb105
OCC "maintenance:mode --on"
tmp_sql=`mktemp`
trap "rm -f $tmp_sql" EXIT

# Dump the mariadb55 nextcloud database or exit on error
/usr/bin/mysqldump --databases nextcloud > $tmp_sql
if [[ $? -ne 0 ]]; then
exitOnError "[ERROR] Error while dumping nextcloud database from mariadb55"
fi

# We got the dump or exit on error
if [[ ! -f $tmp_sql ]]; then
exitOnError "[ERROR] There is no dumped nextcloud database"
fi

# Create the database in rh-mariadb105 and import the dump from mariadb55 or exit on error
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "CREATE DATABASE IF NOT EXISTS nextcloud;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock --database nextcloud < $tmp_sql
if [[ $? -ne 0 ]]; then
exitOnError "[ERROR] Error while restoring nextcloud database to SCL mariadb105"
fi

# we need to upgrade mariadb55 to mariadb105 or exit on error
# https://access.redhat.com/documentation/en-us/red_hat_software_collections/3/html/3.3_release_notes/chap-migration
mysql_upgrade --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock --force
if [[ $? -ne 0 ]]; then
exitOnError "[ERROR] Error while upgrading nextcloud database"
fi

# rh-mariadb105 is created,migrated,updated we can remove mariadb55 and use the socket in nextcloud for the new database
if [[ -d '/var/opt/rh/rh-mariadb105/lib/mysql-nextcloud/' ]]; then
OCC config:system:set dbhost --value="localhost:/run/rh-mariadb105-mariadb/nextcloud-mysql.sock" --type="string"
/usr/bin/mysql -e "drop database nextcloud;"

# Alter database for migration
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "grant all on nextcloud.* to 'nextcloud'@'localhost' identified by '$password';"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "FLUSH PRIVILEGES"
#Enabling MySQL 4-byte support
OCC "config:system:set mysql.utf8mb4 --type boolean --value='true'"
OCC "maintenance:repair"
fi
else
# initialize grants mysql nextcloud database
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "CREATE DATABASE IF NOT EXISTS nextcloud;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "grant all on nextcloud.* to 'nextcloud'@'localhost' identified by '$password';"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "FLUSH PRIVILEGES"
fi

# check if we are migrating from release 10 to 11
if [ -f /var/www/html/nextcloud/config/config.php ]; then
mv /var/www/html/nextcloud/config/config.php /usr/share/nextcloud/config/config.php
rm -rf /var/www/html/nextcloud/
fi

res=`/usr/bin/mysql --defaults-file=/root/.my.cnf -e "select count(*) from information_schema.tables where table_type = 'BASE TABLE' and table_schema = 'nextcloud'" | tail -n1`;

res=`mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "select count(*) from information_schema.tables where table_type = 'BASE TABLE' and table_schema = 'nextcloud'" | tail -n1`;
if [[ $res == '0' ]]; then
OCC "maintenance:install --database mysql --database-name nextcloud --database-user nextcloud --database-pass $password --admin-user admin --admin-pass Nethesis,1234 --data-dir /var/lib/nethserver/nextcloud/"
OCC "maintenance:install --database mysql --database-name nextcloud --database-user nextcloud --database-pass $password --database-host=localhost:/run/rh-mariadb105-mariadb/nextcloud-mysql.sock --admin-user admin --admin-pass Nethesis,1234 --data-dir /var/lib/nethserver/nextcloud/"

OCC "app:enable user_ldap"
OCC "ldap:create-empty-config" # create config with empty id
Expand All @@ -44,6 +117,7 @@ else
fi

OCC "maintenance:mode --on"

OCC "upgrade"
OCC "maintenance:mode --off"
OCC "integrity:check-core"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
#
# Copyright (C) 2021 Nethesis S.r.l.
# http://www.nethesis.it - [email protected]
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see <http://www.gnu.org/licenses/>.
#
# exit when any command fails
set -e

# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "Error while restoring nextcloud database to SCL mariadb105: \"${last_command}\" command filed with exit code $?."' EXIT

source /opt/rh/rh-mariadb105/enable

if [[ ! -f '/var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql' ]]; then
echo "[ERROR] Error the nextcloud SCL mariadb105 dump does not exist"
exit 1
fi

password=`perl -e "use NethServer::Password; print NethServer::Password::store('nextcloud');"`
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "CREATE DATABASE IF NOT EXISTS nextcloud;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock --database nextcloud < /var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "grant all on nextcloud.* to 'nextcloud'@'localhost' identified by '$password';"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "FLUSH PRIVILEGES"

rm -f /var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
#
# Copyright (C) 2021 Nethesis S.r.l.
# http://www.nethesis.it - [email protected]
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see <http://www.gnu.org/licenses/>.
#

source /opt/rh/rh-mariadb105/enable

umask 0027
backup_dir=/var/lib/nethserver/backup/rh-mariadb105/

if [ ! -d $backup_dir ]; then
mkdir -p $backup_dir
fi

mysqldump --socket /run/rh-mariadb105-mariadb/nextcloud-mysql.sock \
--databases nextcloud --default-character-set=utf8mb4 \
--skip-dump-date --ignore-table=mysql.event --single-transaction \
--quick --add-drop-table \
-r $backup_dir/nextcloud.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[mysqld.nextcloud]
datadir=/var/opt/rh/rh-mariadb105/lib/mysql-nextcloud
socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock
log-error=/var/log/rh-mariadb105/nextcloud.log
pid-file=/run/rh-mariadb105-mariadb/mariadb-nextcloud.pid
skip-networking
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1

[server.nextcloud]
skip_name_resolve = 1
innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
long_query_time = 1
19 changes: 19 additions & 0 deletions root/etc/logrotate.d/rh-mariadb105-nextcloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This logname can be set in /etc/my.cnf
# by setting the variable "log-error"
# in the [mysqld] section as follows:
#
# [mysqld]
# log-error=/var/log/rh-mariadb105/nextcloud.log

/var/log/rh-mariadb105/nextcloud.log {
create 600 mysql mysql
notifempty
missingok
postrotate
# just if mariadbd is really running
if [ -e /run/rh-mariadb105-mariadb/mariadb-nextcloud.pid ]
then
kill -1 $(</run/rh-mariadb105-mariadb/mariadb-nextcloud.pid)
fi
endscript
}