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().naive_local() + 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 unit_name = UnitName::new("my-special-unit-name-123").unwrap();

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

// check future beep
systemd_wake::query_registration(unit_name).unwrap();

// cancel future beep and retrieve command and deadline
let (command, waketime) = systemd_wake::deregister(unit_name).unwrap();

Modules§

command
Command serialization.

Structs§

UnitName
Wrapper struct for the name given to the systemd timer unit.

Enums§

CommandError
Error struct for running a command. Wraps running with a non-success exit status as an error variant.
QueryError
Error struct for querying task registration.
RegistrationError
Error struct for registration.
UnitNameError
Error struct for creating UnitName.

Functions§

deregister
Calls systemctl to deregister specified timer.
query_registration
Returns registered command and wake up time for unit if it exists.
register
Calls systemd-run to register command to wake at specified time using provided name.
reschedule
Convenience function for changing scheduled waketime
run_command
Helper function for running commands.