Crate systemd_wake

source ·
Expand description

systemd-wake

This is a utility library that uses systemd-run under the hood to schedule any Command to run at some future time. Allows for tasks to be scheduled and cancelled using custom systemd unit names as handles. Note that there are no guarantees about naming collisions from other programs. Be smart about choosing names.

Requires the systemd-wake binary to be installed in order to work. Remember to install with cargo install systemd-wake

Use register() to schedule a command with systemd-run to wake at specificed time

Use deregister() to cancel timer

Example

use systemd_wake::*;

// one minute in the future
let waketime = chrono::Local::now() + chrono::Duration::minutes(1);

// schedule a short beep
let mut command = std::process::Command::new("play");
command.args(vec!["-q","-n","synth","0.1","sin","880"]);

// create unit handle
let timer_name = TimerName::new("my-special-unit-name-123").unwrap();

// register future beep
systemd_wake::register(waketime,timer_name,command).unwrap();

// cancel future beep
systemd_wake::deregister(timer_name).unwrap();

Structs

  • Non-runnable version of Command used for serialization.
  • Error struct for running a command. Wraps running with a non-success exit status as an error variant.
  • Wrapper struct for the name given to the systemd timer unit.
  • Error struct for creating TimerName.

Enums

Functions

  • Calls systemctl to deregister specified timer.
  • Calls systemd-run to register command to wake at specified time using provided name.
  • Helper function for running commands.