Skip to content

Privilege-free & cross-platform daemon #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2023
Merged

Conversation

PaperCube
Copy link
Collaborator

This PR contains implementation to create a daemon process that requires no special privileges to maintain running in the background after parent process exits, both on Windows and POSIX operating systems, primarily with subprocess module.

This implementation of daemon process manager supports two modes:

  • Detached mode: The child process does not exit when parent exits. (This mode is currently used for NEETBOX daemon)
  • Attached mode: The child process exits along with the exit of the parent.

This implementation has the following requirements and limitations:

On Daemon Process Manager:

  • The executable that launched the parent process must be reentrantly callable, with an accessible executable path and executable permissions.
  • On POSIX, child processes created in "attached" mode may not exit as expected if parent is terminated forcibly (probably, for example, SIGKILL) because this behavior is achieved with atexit registerer.
  • The behavior of to where stdout and stderr are redirected in detached mode differs on Windows and POSIX (but you can always mute stdout and stderr).
  • Redirecting output of child process to files hasn't been intentionally checked and tested.

On the interoperation with neetbox:

  • The operating system must support the passing of, change to and access to environment variables.
  • Length of daemon config is limited on that it, when encoded as json, combined with other CLI args, should not exceed the maximum length supported by the operating system. Should this length be exceeded in the future, we can move to temporary files or other techniques instead.

If this implementation of daemon process manager is to be used in creation of other daemon processes apart from that included in this PR, the following additional requirements have to be met:

  • The code to run as a daemon process must have a package name that is callable in the form {path_to_python_executable} -m package.name (though this can be changed when necessary).

Tested on Windows 11 and WSL2 Ubuntu 20.04

This PR also introduces some other changes and improvements. See commit history for details.

- When daemon process exits unexpectedly, upload_thread is no longer
  created more than once
- Changed retry strategy when creating daemon process:
  1) Unexpected exit of daemon is checked (before the first successful
  connection only).
  2) Retrying lasts for 10 seconds.
@vercel
Copy link

vercel bot commented Apr 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
neetbox ✅ Ready (Inspect) Visit Preview Apr 22, 2023 9:51am

@visualDust visualDust merged commit bd567c7 into master Apr 22, 2023
@visualDust visualDust deleted the feature-win-daemon branch December 4, 2023 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants