Skip to content

Commit d0cfbe1

Browse files
authored
Merge pull request #17 from aniongithub/fix/wiki-dir-permissions
Fix wiki dir permissions: run service as invoking user
2 parents fbc4d0a + f0d0fb5 commit d0cfbe1

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

cmd/mind-map/service.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,19 @@ func newServiceConfig(addr, dir, webui string, idleTimeout time.Duration) *servi
8686
Executable: execPath,
8787
}
8888

89-
// On macOS, install as a user agent (no root required)
89+
// Run as the invoking user, not root. This ensures the service and
90+
// stdio agents share the same file ownership on the wiki directory.
9091
if runtime.GOOS == "darwin" {
9192
cfg.Option = service.KeyValue{
9293
"UserService": true,
9394
}
95+
} else if runtime.GOOS == "linux" {
96+
cfg.UserName = os.Getenv("SUDO_USER")
97+
if cfg.UserName == "" {
98+
if u := os.Getenv("USER"); u != "root" {
99+
cfg.UserName = u
100+
}
101+
}
94102
}
95103

96104
return cfg

install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,16 @@ if [[ "$INSTALL_SERVICE" =~ ^[Yy]$ ]]; then
151151
# System services require elevated privileges on Linux
152152
if [[ "$(uname -s)" == "Linux" ]]; then
153153
echo "==> Installing service (requires sudo)..."
154+
# Ensure wiki dir exists and is owned by the current user
155+
mkdir -p "${SERVICE_WIKI_DIR}"
154156
# Uninstall existing service if present (handles reinstall)
155157
sudo "${INSTALL_DIR}/mind-map" service stop 2>/dev/null || true
156158
sudo "${INSTALL_DIR}/mind-map" service uninstall 2>/dev/null || true
157159
sudo "${INSTALL_DIR}/mind-map" service install --addr ":${SERVICE_PORT}" --dir "${SERVICE_WIKI_DIR}" && \
158160
sudo "${INSTALL_DIR}/mind-map" service start --addr ":${SERVICE_PORT}" --dir "${SERVICE_WIKI_DIR}"
161+
# Fix ownership: the service runs as root but agents run as the user.
162+
# Both need write access to the wiki dir and SQLite database.
163+
sudo chown -R "$(id -u):$(id -g)" "${SERVICE_WIKI_DIR}"
159164
else
160165
"${INSTALL_DIR}/mind-map" service stop 2>/dev/null || true
161166
"${INSTALL_DIR}/mind-map" service uninstall 2>/dev/null || true

0 commit comments

Comments
 (0)