syncthing: Use systemd-sysusers for creating a system user account

- Drop dependency on 'adduser' package.

Tests:

- Functional tests for syncthing work.

- Installing syncthing app works. The system user and group are created with
proper UID/GID, shell, gecos, and home directory.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2026-05-13 13:38:59 -07:00
parent 0f98ed67e7
commit f4be9039d2
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 8 additions and 17 deletions

View File

@ -0,0 +1,6 @@
# Create system user and group to run syncthing as system daemon (as opposed to
# running in particular user's account). The user is created at boot or when
# 'systemd-sysusers freedombox-syncthing.conf' is run. To override this file as
# system administrator, create a file /etc/sysusers.d/freedombox-syncthing.conf
# or link it to /dev/null.
u! syncthing - "Syncthing file synchronization server" /var/lib/syncthing

View File

@ -1,9 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Configure Syncthing."""
import grp
import os
import pwd
import shutil
import time
@ -32,21 +30,8 @@ def augeas_load(conf_file):
@privileged
def setup():
"""Perform post-install actions for Syncthing."""
# Create syncthing group if needed.
try:
grp.getgrnam('syncthing')
except KeyError:
action_utils.run(['addgroup', '--system', 'syncthing'], check=True)
# Create syncthing user if needed.
try:
pwd.getpwnam('syncthing')
except KeyError:
action_utils.run([
'adduser', '--system', '--ingroup', 'syncthing', '--home',
DATA_DIR, '--gecos', 'Syncthing file synchronization server',
'syncthing'
], check=True)
# Create a 'syncthing' system user and group, if needed.
action_utils.run(['systemd-sysusers', 'freedombox-syncthing.conf'])
if not os.path.exists(DATA_DIR):
os.makedirs(DATA_DIR, mode=0o750)