From 547db1608b963e5b5f05172da83a7b41dd081eb3 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 5 Apr 2024 16:19:42 -0700 Subject: [PATCH] nextcloud: Use a separate DB for redis - While nextcloud has a good prefix for all the keys it stores, flushing the database (for nextcloud or other apps) is easier if it stores it's keys in a separate database. Assign DB index at 8 (database number 9). Index 7 is taken by rspamd on FreedomBox. - Flush only Nextcloud's DB after restore instead of the entire server. - Ignore errors during flush if redis server is not running. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/nextcloud/privileged.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plinth/modules/nextcloud/privileged.py b/plinth/modules/nextcloud/privileged.py index 6ae894a4e..4a9468a57 100644 --- a/plinth/modules/nextcloud/privileged.py +++ b/plinth/modules/nextcloud/privileged.py @@ -25,6 +25,7 @@ DB_HOST = 'localhost' DB_NAME = 'nextcloud_fbx' DB_USER = 'nextcloud_fbx' GUI_ADMIN = 'nextcloud-admin' +REDIS_DB = 8 # Don't clash with other redis apps _volume_path = pathlib.Path( '/var/lib/containers/storage/volumes/') / VOLUME_NAME @@ -338,7 +339,8 @@ def restore_database(): _set_database_privileges(_get_dbpassword()) - action_utils.service_restart('redis-server') + subprocess.run(['redis-cli', '-n', REDIS_DB, 'FLUSHDB', 'SYNC'], + check=False) _set_maintenance_mode(False) # Attempts to update UUIDs of user and group entries. By default, @@ -364,11 +366,11 @@ def _get_dbpassword(): def _create_redis_config(): """Create a php file for Redis configuration.""" config_file = _volume_path / '_data/config/freedombox.config.php' - file_content = r''' '\OC\Memcache\Redis', 'memcache.locking' => '\OC\Memcache\Redis', -'redis' => ['host' => '/run/redis/redis-server.sock'], +'redis' => ['host' => '/run/redis/redis-server.sock', 'dbindex' => {REDIS_DB}], ]; ''' config_file.write_text(file_content)