[PR #11] [MERGED] feat: Make CLIProxyAPI run as detached background process #29

Closed
opened 2026-02-27 16:46:49 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/router-for-me/EasyCLI/pull/11
Author: @benzntech
Created: 10/24/2025
Status: Merged
Merged: 10/25/2025
Merged by: @luispater

Base: mainHead: feature/background-process-detachment


📝 Commits (1)

  • b6e742d feat: Make CLIProxyAPI run as detached background process

📊 Changes

3 files changed (+105 additions, -46 deletions)

View changed files

📝 src-tauri/Cargo.lock (+1 -0)
📝 src-tauri/Cargo.toml (+3 -0)
📝 src-tauri/src/main.rs (+101 -46)

📄 Description

Overview

This PR implements independent background process execution for CLIProxyAPI, allowing the CLI service to continue running after the EasyCLI GUI application is closed.

Changes

Process Detachment

  • Windows: Uses DETACHED_PROCESS flag (0x00000008) to create independent process
  • Unix/Linux/macOS: Uses setsid() to create new session and process group
  • No stdout/stderr piping (prevents parent dependency)
  • Process handle is immediately dropped after spawn

PID Tracking

  • Added PROCESS_PID static for storing process ID
  • Used for:
    • Checking if process is already running
    • Killing old process on restart
    • Status verification

Updated Behaviors

  • Window close no longer kills CLIProxyAPI process
  • Tray quit no longer kills CLIProxyAPI process
  • Restart functionality kills old PID before starting new process

Dependencies

  • Added libc = "0.2" for Unix platforms (setsid/kill functions)
  • Added platform-specific CommandExt imports

Benefits

CLI service continues serving API requests after GUI exit
Better separation of concerns (GUI vs service)
Matches typical daemon/service behavior expectations
Allows GUI to be used for configuration without disrupting service

Breaking Changes

⚠️ Important: Users must manually stop CLIProxyAPI using:

  • macOS/Linux: kill <PID> or ps aux | grep cli-proxy-api
  • Windows: taskkill /F /PID <PID> or Task Manager
  • App: Use the Restart button in settings

Process no longer automatically stops when app closes.

Testing

  • Compiled successfully on macOS
  • Process detaches and continues running after GUI close
  • PID tracking works correctly
  • Needs testing on Windows
  • Needs testing on Linux

Technical Details

See implementation in src-tauri/src/main.rs:

  • Lines 1069-1096: Process start with detachment
  • Lines 1110-1128: Restart with old process kill
  • Lines 984-1004: PID-based status checking

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/router-for-me/EasyCLI/pull/11 **Author:** [@benzntech](https://github.com/benzntech) **Created:** 10/24/2025 **Status:** ✅ Merged **Merged:** 10/25/2025 **Merged by:** [@luispater](https://github.com/luispater) **Base:** `main` ← **Head:** `feature/background-process-detachment` --- ### 📝 Commits (1) - [`b6e742d`](https://github.com/router-for-me/EasyCLI/commit/b6e742db194a24bf75dc1134031bcf45fed7cb34) feat: Make CLIProxyAPI run as detached background process ### 📊 Changes **3 files changed** (+105 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/Cargo.lock` (+1 -0) 📝 `src-tauri/Cargo.toml` (+3 -0) 📝 `src-tauri/src/main.rs` (+101 -46) </details> ### 📄 Description ## Overview This PR implements independent background process execution for CLIProxyAPI, allowing the CLI service to continue running after the EasyCLI GUI application is closed. ## Changes ### Process Detachment - **Windows**: Uses `DETACHED_PROCESS` flag (0x00000008) to create independent process - **Unix/Linux/macOS**: Uses `setsid()` to create new session and process group - No stdout/stderr piping (prevents parent dependency) - Process handle is immediately dropped after spawn ### PID Tracking - Added `PROCESS_PID` static for storing process ID - Used for: - Checking if process is already running - Killing old process on restart - Status verification ### Updated Behaviors - Window close no longer kills CLIProxyAPI process - Tray quit no longer kills CLIProxyAPI process - Restart functionality kills old PID before starting new process ### Dependencies - Added `libc = "0.2"` for Unix platforms (setsid/kill functions) - Added platform-specific `CommandExt` imports ## Benefits ✅ CLI service continues serving API requests after GUI exit ✅ Better separation of concerns (GUI vs service) ✅ Matches typical daemon/service behavior expectations ✅ Allows GUI to be used for configuration without disrupting service ## Breaking Changes ⚠️ **Important**: Users must manually stop CLIProxyAPI using: - **macOS/Linux**: `kill <PID>` or `ps aux | grep cli-proxy-api` - **Windows**: `taskkill /F /PID <PID>` or Task Manager - **App**: Use the Restart button in settings Process no longer automatically stops when app closes. ## Testing - [x] Compiled successfully on macOS - [x] Process detaches and continues running after GUI close - [x] PID tracking works correctly - [x] Needs testing on Windows - [x] Needs testing on Linux ## Technical Details See implementation in `src-tauri/src/main.rs`: - Lines 1069-1096: Process start with detachment - Lines 1110-1128: Restart with old process kill - Lines 984-1004: PID-based status checking --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 16:46:49 +03:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/EasyCLI#29
No description provided.