Skip to content
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

Add workflow, systemd feature, fix metadata #30

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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