Rust library to ease the task of creating daemons

Overview

daemonize-me Rust Crates.io Crates.io Crates.io

Rust library to ease the task of creating daemons, I have drawn heavy inspiration from Daemonize by knsd.

Basic usage

Add it to your cargo.toml this will add the whole 1.0.x series as compatible as per semver

daemonize-me = "1.0"

Example:

println!("Daemonized with success"), Err(e) => eprintln!("Error, {}", e), } } ">
extern crate daemonize_me;
use daemonize_me::{Daemon, Group, User};
use std::convert::TryFrom;
use std::fs::File;

fn main() {
    let stdout = File::create("info.log").unwrap();
    let stderr = File::create("err.log").unwrap();
    let daemon = Daemon::new()
        .pid_file("example.pid", Some(false))
        .user(User::try_from("daemon").unwrap())
        .group(Group::try_from("daemon").unwrap())
        .umask(0o000)
        .work_dir(".")
        .stdout(stdout)
        .stderr(stderr)
        .start();

    match daemon {
        Ok(_) => println!("Daemonized with success"),
        Err(e) => eprintln!("Error, {}", e),
    }
}

OS support

I will try to keep support for linux, freebsd and macos

os tier
linux tier 1
freebsd, netbsd tier 2
macos, unix, *nix tier 3
Anything non unix not supported

For tier 1 any code that breaks the tests and or ci/cd is blocking for a release, tier 2 compilation errors are release blocking, tier 3 are supported on a best effort basis, and build failure as well as test failures are not blocking.

note on custom/hobby OS support, if your os implements the syscalls used in lib.rs with behavior that is equivalent then this library is likely to work but it's even less of a guarantee.

Supported Versions

Odd numbered minor versions receive patches and fixes only until the next odd numbered release, even numbered releases are considered LTS and will get fixes until the next even release happens - about 6 months.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Comments
  • Cannot build - getting an unresolved imports error

    Cannot build - getting an unresolved imports error

    Im trying to use the crate in a simple project just to start a daemon to do some =thing simple. I have added daemonize-me = "1.0" to my Cargo.toml. When I run cargo build I get the following:

    Compiling daemonize-me v1.0.0
    error[E0432]: unresolved imports `libc::prctl`, `libc::PR_SET_NAME`
    --> /Users/conordowney/.cargo/registry/src/github.com-1ecc6299db9ec823/daemonize-me-1.0.0/src/ffi.rs:6:12
     |
    6 | use libc::{prctl, PR_SET_NAME};
     |            ^^^^^  ^^^^^^^^^^^ no `PR_SET_NAME` in the root
     |            |
     |            no `prctl` in the root
    
    For more information about this error, try `rustc --explain E0432`.
    error: could not compile `daemonize-me` due to previous error
    

    My program is just a hello world. I just wanted to see if it would build with the package included. Any idea what might be wrong?

    bug platform-bsd platform-mac 
    opened by conormdowney 17
  • Support `privileged_action`

    Support `privileged_action`

    Currently I use the privileged_action in daemonize to open some files in /proc/self before the process changes user/group so I can sample some stats about the running process. I have not found another approach that may work for this - if I open the files before demonize.start they will be referring not to the process I want to be monitored.

    Is there possibility to add optional privileged_action method that takes a FnOnce? For reference: https://docs.rs/daemonize/latest/daemonize/struct.Daemonize.html#method.privileged_action

    enhancement 
    opened by luben 7
  • Communicating with the running daemon

    Communicating with the running daemon

    Hi there!

    I've been using this library to create a daemon for a program I use. It works perfectly, but I don't know how to interact with it later.

    Is there any function (or could there any that could be implemented) to check if the daemon is already running, and if so communicate with it? Even just getting its PID would already be useful, even better if it's possible to communicate natively with it.

    Thanks in advance for your help :)

    enhancement 
    opened by ClementNerma 5
  • Tokio Support

    Tokio Support

    Is your feature request related to a problem? Please describe.

    This doesn't seem to work with tokio. When I try, I get this message:

    thread 'main' panicked at 'failed to wake I/O driver: Os { code: 9, kind: Uncategorized, message: "Bad file descriptor" }'
    

    Additional context

    This specifically happens when I run Daemon::start from a main with #[tokio::main].

    enhancement 
    opened by wagenet 5
  • Restart/Status/kill methods and handle shutdown

    Restart/Status/kill methods and handle shutdown

    **Is your feature request related to a problem?

    Hey @DarthUdp, amazing work, I've been using daemonize-me for sometime now, and I'd like to have the ability to to start/restart, get status and stop. So that I can create a daemon object and have a set of methods.

    Describe the solution you'd like

    • Start method to accept a function that block the daemon from being killed and be killed if sigterm was received.
    • Stop/kill method to kill daemon and execute a user provide cleanup function.
    • Restart method to kill the daemon and run start method.
    • Status method to pretty print stdout and stdin.

    Additionally, it would be awesome if user can provide app name as in clap and description.

    Describe alternatives you've considered

    I've implemented a semi-independent wrapper for my use case. Here's a gist.

    https://gist.github.com/tami5/af81b31307d7cb9e51f31b55e16180ea

    enhancement 
    opened by kkharji 4
  • Release 1.0.1

    Release 1.0.1

    This is a maintenance release to the 1.0-LTS series, it fixes issues preventing the code from building on BSD and MacOS and a segfault that arose when that was fixed.

    bug platform-bsd platform-mac 
    opened by neonimp 1
  • async_std::task::sleep() hangs

    async_std::task::sleep() hangs

    To Reproduce Steps to reproduce the behavior: In async_std-based app having async_std::task::sleep().await hangs forever when started under daemonize-me.

    Expected behavior Shouldn't hang

    Desktop:

    • OS: Ubuntu
    • Version 20.10

    Additional context I've tried daemonize crate first and got the same issue. I guess it is somehow related to this crate's internals?

    bug 
    opened by nazar-pc 1
  • Passing an invalid uname or gname causes panic

    Passing an invalid uname or gname causes panic

    Describe the bug Passing an invlid uname or gname causes panic.

    To Reproduce Steps to reproduce the behavior: On the construction of the struct give it an invalid uname/gname, it will cause a panic

    Expected behavior A recoverable error should happen not a panic

    Desktop (please complete the following information): Any platform regardless of tier

    bug 
    opened by neonimp 0
Releases(v2.0.1)
  • v2.0.1(Apr 11, 2022)

  • v2.0.0(Apr 11, 2022)

    What's Changed

    • Changed the public API to be more ergonomic;
    • Added hooks that are called in different stages of the daemonization process;
    • Many bug fixes for tier 2 and 3 targets;

    Full Changelog: https://github.com/DarthUdp/daemonize-me/compare/v1.0.2...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Apr 11, 2022)

    Compatibility and advisories

    This release is fully backwards compatible to 1.0.0 as per semver rules. On linux this release does not change anything and continued use of v1.0.0 is safe.

    What's

    • Separated MacOS and FreeBSD from openBSD and netBSD in ffi

    Full Changelog: https://github.com/DarthUdp/daemonize-me/compare/v1.0.1...v1.0.2

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Mar 22, 2022)

    Compatibility and advisories

    This release is fully backwards compatible to 1.0.0 as per semver rules. On linux this release does not change anything and continued use of v1.0.0 is safe.

    What's Changed

    • MacOS no longer fails to build
    • BSD family OSes now wont segfault when handling groups or passwd entries

    Full Changelog: https://github.com/DarthUdp/daemonize-me/compare/v1.0.0...v1.0.1

    Thanks to @conormdowney for reporting the issue that originated this release and @tqwewe for helping in the debugging process.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(Jun 28, 2020)

  • v0.2.1-pre(Jun 27, 2020)

  • 0.2.0-pre(Jun 27, 2020)

Owner
Matheus Xavier
twiddling bits for a living
Matheus Xavier
delicate A lightweight and distributed task scheduling platform written in rust

A lightweight and distributed task scheduling platform written in rust.

BinCheng 529 Jan 9, 2023
Task scheduler for the Internet Computer

IC Cron Makes your IC canister proactive Abstract Canisters are reactive by their nature - they only do something when they're asked by a client or an

Alexander Vtyurin 33 Dec 14, 2022
Cronos - a decentralized task scheduler for Solana

Cronos Cronos is a decentralized task scheduler for Solana. Packages Package Description Version Docs cronos-bot Cronos bot to execute tasks GitBook c

null 174 Dec 26, 2022
Fang - Background job processing library for Rust.

Fang Background job processing library for Rust. Currently, it uses Postgres to store state. But in the future, more backends will be supported.

Ayrat Badykov 421 Dec 28, 2022
Ergo is a low-code IFTTT/Zapier style application, built with Rust and Svelte

Ergo is a low-code IFTTT/Zapier style application, built with Rust and Svelte. Tasks are customizable with Javascript and can contain state machines for more advanced task handling.

Daniel Imfeld 100 Dec 26, 2022
Rust single-process scheduling. Ported from schedule for Python

Rust single-process scheduling. Ported from schedule for Python, in turn inspired by clockwork (Ruby), and "Rethinking Cron" by Adam Wiggins.

Ben Lovy 13 May 30, 2022
Vagga is a containerization tool without daemons

Vagga Vagga is a fully-userspace container engine inspired by Vagrant and Docker, specialized for development environments. Note version 0.2 changed f

Paul Colomiets 1.8k Dec 23, 2022
Ember is a minimalistic Rust library for creating 2D graphics, games, and interactive visualizations with ease and simplicity.

Ember Ember is a simple and fun 2D rendering library for Rust, allowing you to quickly create graphics and interactive applications with ease. It uses

null 8 May 4, 2023
Safe Rust crate for creating socket servers and clients with ease.

bitsock Safe Rust crate for creating socket servers and clients with ease. Description This crate can be used for Client <--> Server applications of e

Lorenzo Torres 3 Nov 25, 2021
A simple, efficient Rust library for handling asynchronous job processing and task queuing.

job_queue Setup cargo add job_queue Usage Create a job use job_queue::{Error, Job, typetag, async_trait, serde}; #[derive(Debug, serde::Deserialize,

Georges KABBOUCHI 3 Nov 30, 2023
A light wheight Neural Network library with a focus on ease of use and speed.

Smarty Pants This goal of this library is to: Produce NeuralNetworks that will always give the same result when given the same input. Provide methods

Coding Wizard 3 Mar 7, 2022
Task runner and process manager for Rust

Steward Task runner and process manager for Rust. If you're not happy managing your infrastructure with a pile of bash scripts, this crate might be he

Alex Fedoseev 24 Dec 26, 2022
delicate A lightweight and distributed task scheduling platform written in rust

A lightweight and distributed task scheduling platform written in rust.

BinCheng 529 Jan 9, 2023
Rust task runner and build tool.

cargo-make Rust task runner and build tool. Overview Installation Binary Release Usage Simple Example Tasks, Dependencies and Aliases Commands, Script

Sagie Gur-Ari 1.8k Jan 7, 2023
Task-based logging for rust

task_log task_log is a task-based logger. Installing Just add task_log = 0.1.4 to your Cargo.toml's dependency section. Example Let's get right to the

Matt Gleich 2 Feb 28, 2022
Background task processing for Rust applications with Tokio, Diesel, and PostgreSQL.

Async persistent background task processing for Rust applications with Tokio. Queue asynchronous tasks to be processed by workers. It's designed to be

Rafael Carício 22 Mar 27, 2023
CrustAGI is an Task-driven Autonomous Agent experiment written in Rust

CrustAGI ?? CrustAGI is an experimental Rust-based implementation of an AI-powered task management system that uses OpenAI and Pinecone APIs to create

Lukas Schmyrczyk 20 Apr 19, 2023
🎭 A CLI task runner defined by a simple markdown file

mask is a CLI task runner which is defined by a simple markdown file. It searches for a maskfile.md in the current directory which it then parses for

Jake Deichert 756 Dec 30, 2022
Task scheduler for the Internet Computer

IC Cron Makes your IC canister proactive Abstract Canisters are reactive by their nature - they only do something when they're asked by a client or an

Alexander Vtyurin 33 Dec 14, 2022
TimeKnight is a neat little TUI-based timer app I use in conjunction with a task tracker

TimeKnight is a neat little TUI-based timer app I use in conjunction with a task tracker. It's kind of a secret sauce for productivity (particularly if you have ADHD or have a ridiculously overactive brain).

Monomadic 1 Feb 8, 2022