Skip to content

Commit

Permalink
Merge branch 'dev/2.0.0' into trunk
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/rust.yml
#	Cargo.toml
#	README.md
#	src/ffi.rs
  • Loading branch information
xadaemon committed Apr 11, 2022
2 parents bd6195a + 1c26ba6 commit 8fc98dd
Show file tree
Hide file tree
Showing 13 changed files with 668 additions and 585 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: Rust

on:
push:
branches: [ trunk ]
branches: [ trunk, 'dev/**', 'lts/**' ]
pull_request:
branches: [ trunk, 'lts/**' ]
branches: [ trunk, 'dev/**', 'lts/**' ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build and test

runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
.idea/
Cargo.lock
*.log
*.pid
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "daemonize-me"
version = "1.0.2"
authors = ["Matheus Xavier <m.xavier@ieee.org>"]
edition = "2018"
version = "2.0.0"
authors = ["Matheus Xavier <xavier+cargo@2dc.io>"]
edition = "2021"
license = "BSD-3-Clause/Apache-2.0"
repository = "https://github.com/CardinalBytes/daemonize-me"
description = "Rust library to ease the task of creating daemons on unix-like systems"
Expand All @@ -13,6 +13,6 @@ categories = ["os::unix-apis"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "0.2"
nix = "0.17"
snafu = "0.6.8"
libc = "0.2.113"
nix = "0.23.1"
thiserror = "1.0"
66 changes: 20 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,39 @@
# daemonize-me [![Rust](https://github.com/CardinalBytes/daemonize-me/workflows/Rust/badge.svg)](https://github.com/CardinalBytes/daemonize-me/actions) [![Crates.io](https://img.shields.io/crates/v/daemonize-me)](https://crates.io/crates/daemonize-me) [![Crates.io](https://img.shields.io/crates/d/daemonize-me)](https://crates.io/crates/daemonize-me) [![Crates.io](https://img.shields.io/crates/l/daemonize-me)](https://github.com/CardinalBytes/daemonize-me/blob/master/LICENSE)
Rust library to ease the task of creating daemons, I have drawn heavy inspiration from [Daemonize by knsd](https://github.com/knsd/daemonize).

# Current release
1.0-LTS track: 1.0.2
# Current releases and EOL table
| track | version | EOL |
|----------|---------|---------|
| 2.0 | 2.0.0 | TBA |
| 1.0(LTS) | 1.0.2 | 2022-10 |

# Semver public API
The public API of this crate is considered

# Basic usage
Add it to your cargo.toml this will add the whole 1.0.x (LTS) series as compatible as per semver
```
daemonize-me = "1.0"
Add it to your cargo.toml this will add the whole 2.0.x series as compatible as per semver
```toml
daemonize-me = "2.0"
```
Example:
```rust
extern crate daemonize_me;
use daemonize_me::{Daemon, Group, User};
use std::convert::TryFrom;
use std::fs::File;
Then look at [example.rs](examples/example.rs)

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 |
| os | tier |
|---------------------|---------------|
| linux | tier 1 |
| freebsd, openbsd | tier 2 |
| macos, netbsd, unix | 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,
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
LTS versions are marked as such in the current release, those have a lifetime of 6 months after the release of the next version.

Non LTS versions will only be supported until the next version:

i.e: 1.0.x is an LTS version, when 2.0.0 lands it will be supported for 6 more months.
within releases patches are **NOT LTS**.

# License

Licensed under either of
Expand All @@ -69,4 +43,4 @@ 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.
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.
16 changes: 7 additions & 9 deletions examples/example-lingering.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
extern crate daemonize_me;
use daemonize_me::{Daemon, Group, User};
use nix::unistd::{getgid, getuid};
use std::convert::TryFrom;

use std::fs::File;

pub use daemonize_me::{Daemon, User, Group};

fn main() {
let stdout = File::create("info.log").unwrap();
let stderr = File::create("err.log").unwrap();
let uid = getuid();
let gid = getgid();
println!("sid: {}, pid: {}", uid, gid);
let daemon = Daemon::new()
.pid_file("example.pid", Some(false))
.user(User::try_from("daemon").unwrap())
Expand All @@ -24,7 +21,8 @@ fn main() {
Ok(_) => println!("Daemonized with success"),
Err(e) => eprintln!("Error, {}", e),
}
// use infinite loop to keep process open for inspection
println!("Hello from the daemon");
loop {}

loop {
// You wil have to kill this process yourself
}
}
47 changes: 38 additions & 9 deletions examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
extern crate daemonize_me;
use daemonize_me::{Daemon, Group, User};
use nix::unistd::{getgid, getuid};
use std::convert::TryFrom;

use std::any::Any;
use std::fs::File;
use std::process::exit;

pub use daemonize_me::Daemon;


fn post_fork_parent(ppid: i32, cpid: i32) -> ! {
println!("Parent pid: {}, Child pid {}", ppid, cpid);
println!("Parent will keep running after the child is forked, might even go do other tasks");
println!("Or quit like so, bye :)");
exit(0);
}

fn post_fork_child(ppid: i32, cpid: i32) {
println!("Parent pid: {}, Child pid {}", ppid, cpid);
println!("This hook is called in the child");
// Child hook must return
return
}

fn after_init(_: Option<&dyn Any>) {
println!("Initialized the daemon!");
return
}

fn main() {
let stdout = File::create("info.log").unwrap();
let stderr = File::create("err.log").unwrap();
let uid = getuid();
let gid = getgid();
println!("sid: {}, pid: {}", uid, gid);
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)
// Hooks are optional
.setup_post_fork_parent_hook(post_fork_parent)
.setup_post_fork_child_hook(post_fork_child)
.setup_post_init_hook(after_init, None)
//
.start();

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

for i in 0..=10000 {
println!("{}", i);
}
}
32 changes: 0 additions & 32 deletions examples/name_set.rs

This file was deleted.

Loading

0 comments on commit 8fc98dd

Please sign in to comment.