Skip to content

Commit fb83b37

Browse files
Tobi-Declaude
andcommitted
fix: handle pre-existing group when creating app user
When a group with the app name already exists (e.g., from a previous partial install), useradd fails silently because it tries to create a user private group with the same name. Now checks for existing group and uses --no-user-group -g flags to reuse it. Also adds check=True to catch useradd failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 030643f commit fb83b37

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/fujin/_installer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,15 @@ def install(
118118
logger.debug("User %s already exists", config.app_user)
119119
except KeyError:
120120
logger.debug("Creating system user: %s", config.app_user)
121-
run(
122-
f"useradd --system --no-create-home --shell /usr/sbin/nologin {config.app_user}",
123-
)
121+
# Check if group already exists (e.g., from a previous partial install)
122+
try:
123+
grp.getgrnam(config.app_user)
124+
# Group exists, use it instead of creating a new one
125+
useradd_cmd = f"useradd --system --no-create-home --shell /usr/sbin/nologin --no-user-group -g {config.app_user} {config.app_user}"
126+
except KeyError:
127+
# No existing group, let useradd create one
128+
useradd_cmd = f"useradd --system --no-create-home --shell /usr/sbin/nologin {config.app_user}"
129+
run(useradd_cmd, check=True)
124130

125131
app_dir = Path(config.app_dir)
126132
app_dir.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)