Skip to content

Commit 98ccebb

Browse files
andystimeclaude
andcommitted
fix: improve privilege handling and worker environment configuration
1. Enhanced sudo credential caching in install.sh and uninstall.sh - Added sudo -v refresh calls before each operation requiring privileges - Prevents multiple password prompts during installation/uninstallation 2. Fixed TF_CONNECTION_INFO_PATH environment variable handling - Removed incorrect global directory setting from agent Start() method - Variable now correctly set per-worker as file path (not directory) - Each worker gets its own connection file: {connectionsDir}/{workerID}.txt 3. Added TF_LOG_PATH environment variable for tensor-fusion-worker - Workers now log to: {stateDir}/logs/worker-{workerID}.log - Added TF_LOG_LEVEL environment variable (defaults to "info") - Ensures worker logs are saved to specific files as required Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4abbb09 commit 98ccebb

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

internal/agent/agent.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,9 @@ func (a *Agent) Start() error {
231231
klog.Warningf("Failed to create connections directory: path=%s error=%v", a.connectionsDir, err)
232232
}
233233

234-
// Set TF_CONNECTION_INFO_PATH environment variable for worker processes
234+
// Note: TF_CONNECTION_INFO_PATH is set per-worker in convertToWorkerInfos() as worker-specific file path
235235
// Each worker gets its own file: {connectionsDir}/{workerID}.txt
236236
// Workers write connection info to their file, one line per connection (format: clientIP,clientPort,clientPID)
237-
if err := os.Setenv(EnvConnectionInfoPath, a.connectionsDir); err != nil {
238-
klog.Warningf("Failed to set %s env var: error=%v", EnvConnectionInfoPath, err)
239-
} else {
240-
klog.V(4).Infof("Set %s=%s (base dir, workers get {workerID}.txt)", EnvConnectionInfoPath, a.connectionsDir)
241-
}
242237

243238
// Write PID file
244239
if err := a.writePIDFile(); err != nil {
@@ -448,6 +443,16 @@ func (a *Agent) convertToWorkerInfos(apiWorkers []api.WorkerConfig) ([]*hvApi.Wo
448443
envVars["TF_ENABLE_LOG"] = "1"
449444
envVars[EnvURLAuth] = "1"
450445
envVars[EnvAuthorizedKeyPath] = filepath.Join(a.paths.ConfigDir(), w.WorkerID+"_share_codes")
446+
447+
// Set TF_LOG_PATH for tensor-fusion-worker to save logs to a specific file
448+
logsDir := filepath.Join(a.config.StateDir(), "logs")
449+
if err := os.MkdirAll(logsDir, 0755); err != nil {
450+
klog.Warningf("Failed to create logs directory: path=%s error=%v", logsDir, err)
451+
}
452+
workerLogPath := filepath.Join(logsDir, "worker-"+w.WorkerID+".log")
453+
envVars["TF_LOG_PATH"] = workerLogPath
454+
envVars["TF_LOG_LEVEL"] = getEnvWithDefault("TF_LOG_LEVEL", "info")
455+
451456
// Set TF_CONNECTION_INFO_PATH to the worker's specific connection file (not directory)
452457
// Worker will write connection info to this file, one line per connection
453458
envVars[EnvConnectionInfoPath] = filepath.Join(a.connectionsDir, w.WorkerID+".txt")
@@ -1425,3 +1430,11 @@ func GetLocalStatus(paths *platform.Paths) LocalStatus {
14251430

14261431
return LocalStatus{Running: true, PID: pid}
14271432
}
1433+
1434+
// getEnvWithDefault gets an environment variable or returns a default value
1435+
func getEnvWithDefault(key, defaultValue string) string {
1436+
if value := os.Getenv(key); value != "" {
1437+
return value
1438+
}
1439+
return defaultValue
1440+
}

scripts/install.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,13 @@ setup_systemd_service() {
200200

201201
# Require sudo for systemd operations
202202
require_sudo_for_systemd
203-
203+
204204
SUDO=$(get_sudo)
205+
206+
# Refresh sudo timestamp to prevent password prompts during installation
207+
if [ -n "${SUDO}" ]; then
208+
${SUDO} -v || fatal "Failed to refresh sudo credentials"
209+
fi
205210

206211
# Build environment variables section
207212
ENV_VARS=""
@@ -301,6 +306,11 @@ register_agent() {
301306

302307
# Get sudo command (empty if already root)
303308
SUDO=$(get_sudo)
309+
310+
# Refresh sudo timestamp to prevent password prompts during registration
311+
if [ -n "${SUDO}" ]; then
312+
${SUDO} -v || fatal "Failed to refresh sudo credentials"
313+
fi
304314

305315
# Build register command
306316
# Use sudo to ensure config is saved to root's home directory (~/.gpugo/config)
@@ -393,6 +403,11 @@ main() {
393403

394404
# Check if we need sudo
395405
SUDO=$(get_sudo)
406+
407+
# Refresh sudo timestamp to prevent password prompts during installation
408+
if [ -n "${SUDO}" ]; then
409+
${SUDO} -v || fatal "Failed to refresh sudo credentials"
410+
fi
396411

397412
# Create install directory if needed
398413
if [ ! -d "${INSTALL_DIR}" ]; then

scripts/uninstall.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ remove_systemd_service() {
7171

7272
info "Stopping systemd service..."
7373
SUDO=$(get_sudo)
74+
75+
# Refresh sudo timestamp to prevent password prompts during removal
76+
if [ -n "${SUDO}" ]; then
77+
${SUDO} -v 2>/dev/null || true
78+
fi
79+
80+
# Refresh sudo timestamp to prevent password prompts during removal
81+
if [ -n "${SUDO}" ]; then
82+
${SUDO} -v 2>/dev/null || true
83+
fi
7484

7585
# Stop service
7686
${SUDO} systemctl stop "${SYSTEMD_SERVICE_NAME}" 2>/dev/null || true
@@ -107,6 +117,11 @@ remove_launchd_service() {
107117
if [ -f "${PLIST_FILE_SYSTEM}" ]; then
108118
info "Stopping launchd system daemon..."
109119
SUDO=$(get_sudo)
120+
121+
# Refresh sudo timestamp to prevent password prompts during removal
122+
if [ -n "${SUDO}" ]; then
123+
${SUDO} -v 2>/dev/null || true
124+
fi
110125
${SUDO} launchctl unload "${PLIST_FILE_SYSTEM}" 2>/dev/null || true
111126
${SUDO} rm -f "${PLIST_FILE_SYSTEM}"
112127
info "System launch daemon removed!"
@@ -138,6 +153,11 @@ remove_binary() {
138153
info "Removing binary at ${BINARY_PATH}..."
139154

140155
SUDO=$(get_sudo)
156+
157+
# Refresh sudo timestamp to prevent password prompts during removal
158+
if [ -n "${SUDO}" ]; then
159+
${SUDO} -v 2>/dev/null || true
160+
fi
141161

142162
# Check if we need sudo
143163
if [ -w "$(dirname "${BINARY_PATH}")" ]; then
@@ -165,6 +185,11 @@ remove_config() {
165185

166186
# System config (Linux)
167187
SUDO=$(get_sudo)
188+
189+
# Refresh sudo timestamp to prevent password prompts during removal
190+
if [ -n "${SUDO}" ]; then
191+
${SUDO} -v 2>/dev/null || true
192+
fi
168193
SYSTEM_DIRS="/var/lib/ggo /etc/ggo"
169194

170195
for dir in ${SYSTEM_DIRS}; do
@@ -273,6 +298,11 @@ unregister_from_server() {
273298
local unregister_result=0
274299
if [ "${needs_sudo}" = "true" ]; then
275300
SUDO=$(get_sudo)
301+
302+
# Refresh sudo timestamp to prevent password prompts during removal
303+
if [ -n "${SUDO}" ]; then
304+
${SUDO} -v 2>/dev/null || true
305+
fi
276306
if [ -n "${SUDO}" ]; then
277307
${SUDO} "${binary_path}" agent unregister --force 2>/dev/null || unregister_result=$?
278308
else

0 commit comments

Comments
 (0)