Skip to content

Commit

Permalink
Add workflow, systemd feature, fix metadata (#30)
Browse files Browse the repository at this point in the history
* ceviche-rs: add workflow, add feature for systemd-rs

* ceviche-rs: bump version

* ceviche-rs: fix metadata
  • Loading branch information
thenextman committed Mar 14, 2024
1 parent 6c5c277 commit b12ae42
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:

jobs:
build:
strategy:
fail-fast: false
matrix:
os: ['pc-windows-msvc', 'apple-darwin', 'unknown-linux-gnu']
arch: [x86_64, aarch64]
include:
- runner: ubuntu-latest
os: unknown-linux-gnu
- runner: windows-latest
os: pc-windows-msvc
- runner: macos-latest
os: apple-darwin
runs-on: ${{ matrix.runner }}

steps:
- uses: actions/checkout@v4

- name: Configure runner
run: rustup target add ${{matrix.arch}}-${{matrix.os}}

- name: Configure runner
if: matrix.os == 'unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get -o Acquire:retries=3 install libsystemd-dev
- name: Build
shell: pwsh
run: cargo build --target ${{matrix.arch}}-${{matrix.os}}
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "ceviche"
version = "0.5.2"
version = "0.6.0"
edition = "2021"
license = "MIT/Apache-2.0"
homepage = "https://github.com/wayk/ceviche-rs"
repository = "https://github.com/wayk/ceviche-rs"
homepage = "https://github.com/devolutions/ceviche-rs"
repository = "https://github.com/devolutions/ceviche-rs"
authors = ["Marc-André Moreau <[email protected]>", "Sébastien Duquette <[email protected]>", "Richard Markiewicz <[email protected]>"]
keywords = ["daemon", "service"]
description = "Rust daemon/service wrapper"
Expand All @@ -23,7 +23,7 @@ winapi = { version = "0.3", features = ["winbase", "winerror", "winuser", "winsv
widestring = "0.4.3"

[target.'cfg(target_os = "linux")'.dependencies]
systemd-rs = "^0.1.2"
systemd-rs = { version="^0.1.2", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.9"
Expand Down
4 changes: 2 additions & 2 deletions examples/foobar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "foobar_service"
version = "0.1.0"
edition = "2021"
license = "MIT/Apache-2.0"
homepage = "https://github.com/wayk/ceviche-rs"
repository = "https://github.com/wayk/ceviche-rs"
homepage = "https://github.com/devolutions/ceviche-rs"
repository = "https://github.com/devolutions/ceviche-rs"
authors = ["Marc-André Moreau <[email protected]>"]
keywords = ["daemon", "service"]
description = "Rust daemon/service wrapper"
Expand Down
15 changes: 12 additions & 3 deletions src/controller/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ use std::sync::mpsc;

use ctrlc;
use log::{debug, info};
use systemd_rs::login::monitor::{Category, Monitor};
use systemd_rs::login::session as login_session;

use crate::controller::{ControllerInterface, ServiceMainFn};
use crate::session;
use crate::Error;
use crate::ServiceEvent;

#[cfg(feature = "systemd-rs")]
use {
systemd_rs::login::monitor::{Category, Monitor},
systemd_rs::login::session as login_session,
};

type LinuxServiceMainWrapperFn = extern "system" fn(args: Vec<String>);
pub type Session = session::Session_<String>;

Expand Down Expand Up @@ -179,6 +183,7 @@ impl ControllerInterface for LinuxController {
}
}

#[cfg(feature = "systemd-rs")]
fn run_monitor<T: Send + 'static>(
tx: mpsc::Sender<ServiceEvent<T>>,
) -> Result<Monitor, std::io::Error> {
Expand Down Expand Up @@ -240,7 +245,11 @@ macro_rules! Service {
pub fn dispatch<T: Send + 'static>(service_main: ServiceMainFn<T>, args: Vec<String>) {
let (tx, rx) = mpsc::channel();

let _monitor = run_monitor(tx.clone()).expect("Failed to run session monitor");
#[cfg(feature = "systemd-rs")]
{
let _monitor = run_monitor(tx.clone()).expect("Failed to run session monitor");
}

let _tx = tx.clone();

ctrlc::set_handler(move || {
Expand Down

0 comments on commit b12ae42

Please sign in to comment.