Spec

Struct Spec 

Source
pub struct Spec<Path, Name, TriggerSet, InstallType>
where Path: ToAssign, Name: ToAssign, TriggerSet: ToAssign, InstallType: ToAssign,
{ /* private fields */ }
Expand description

The configuration for the current install, needed to perform the installation or remove an existing one. Create this by using the install_system or install_user macros.

Implementations§

Source§

impl<Path, Name, TriggerSet> Spec<Path, Name, TriggerSet, SystemInstall>
where Path: ToAssign, Name: ToAssign, TriggerSet: ToAssign,

Source

pub fn run_as(self, user: impl Into<String>) -> Self

Only available for install_system

§Example
install_system!()
    .current_exe()?
    .service_name("weather_checker")
    .run_as("David")
    .on_boot()
    .prepare_install()?
    .install()?;
Source§

impl<Path, Name, TriggerSet, InstallType> Spec<Path, Name, TriggerSet, InstallType>
where Path: ToAssign, Name: ToAssign, TriggerSet: ToAssign, InstallType: ToAssign,

Source

pub fn path( self, path: impl Into<PathBuf>, ) -> Spec<PathIsSet, Name, TriggerSet, InstallType>

Install a copy of the currently running executable.

§Example
install_user!()
    .path("path/to/binary/weather_checker")
    .service_name("weather_checker")
    .on_boot()
    .prepare_install()?
    .install()?;
Source

pub fn current_exe( self, ) -> Result<Spec<PathIsSet, Name, TriggerSet, InstallType>, Error>

Install a copy of the currently running executable.

§Errors

Will return an error if the path to the current executable could not be gotten. This can fail for a number of reasons such as filesystem operations and system call failures.

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .prepare_install()?
    .install()?;
Source

pub fn service_name( self, service_name: impl Display, ) -> Spec<Path, NameIsSet, TriggerSet, InstallType>

Name to give the systemd service or cron job

Only needed for install. During uninstall we recognize the service or con job by the special comment service-install leaves at the top of each

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .prepare_install()?
    .install()?;
Source

pub fn on_schedule( self, schedule: Schedule, ) -> Spec<Path, Name, TriggerIsSet, InstallType>

Start the job on at a certain time every day. See the Schedule docs for how to configure the time.

§Example
use time::Time;
use service_install::Schedule;

let schedule = Schedule::Daily(Time::from_hms(10, 42, 0).unwrap());
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_schedule(schedule)
    .prepare_install()?
    .install()?;
Source

pub fn on_boot(self) -> Spec<Path, Name, TriggerIsSet, InstallType>

Start the job on boot. When cron is used as init the system needs to be rebooted before the service is started. On systemd its started immediately.

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .prepare_install()?
    .install()?;
Source

pub fn description(self, description: impl Display) -> Self

The description for the installed service

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .description("Sends a notification if a storm is coming")
    .on_boot()
    .prepare_install()?
    .install()?;
Source

pub fn overwrite_existing(self, overwrite: bool) -> Self

Should the installer overwrite existing files? Default is false

Note: we do not even try replace a value if the installed and to be installed files are identical. This setting only applies to scenarios where there are files taking up the install location that are different to what would be installed.

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .overwrite_existing(true)
    .on_boot()
    .prepare_install()?
    .install()?;
Source

pub fn args(self, args: impl IntoIterator<Item = impl Into<String>>) -> Self

The args will be shell escaped. If any arguments where already set this adds to them

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .args(["check", "--location", "North Holland"])
    .prepare_install()?
    .install()?;
Source

pub fn arg(self, arg: impl Into<String>) -> Self

The argument will be shell escaped. This does not clear previous set arguments but adds to it

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .arg("check")
    .arg("--location")
    .arg("North Holland")
    .prepare_install()?
    .install()?;
Source

pub fn env_vars<S: Into<String>>( self, args: impl IntoIterator<Item = (S, S)>, ) -> Self

Environmental variables passed to the program when it runs. If you set the same variable multiple times only the last value will be set for the program.

§Panics

If any part of any of the environmental variables pairs contains an equal sign.

§Example
install_user!()
    .current_exe()?
    .service_name("cli")
    .on_boot()
    .env_vars([("WAYLAND_display","wayland-1"), ("SHELL", "/bin/bash")])
    .prepare_install()?
    .install()?;
Source

pub fn env_var( self, variable: impl Into<String>, value: impl Into<String>, ) -> Self

Environmental variable passed to the program when it runs. If you set the same variable multiple times only the last value will be set for the program.

§Panics

If any part of any of the environmental variables pairs contains an equal sign.

§Example
install_user!()
    .current_exe()?
    .service_name("cli")
    .on_boot()
    .env_var("SHELL", "/bin/bash")
    .prepare_install()?
    .install()?;
Source

pub fn working_dir(self, dir: impl Into<PathBuf>) -> Self

The working directory of the program when it is started on a schedule. Can be a relative path. Shell variables like ~ and $Home are not expanded.

§Example
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .working_dir("/home/david/.local/share/weather_checker")
    .prepare_install()?
    .install()?;
Source

pub fn allowed_inits(self, allowed: impl AsRef<[System]>) -> Self

By default all supported init systems will be tried Can be set multiple times to try multiple init systems in the order in which this was set.

Note: setting this for an uninstall might cause it to fail

§Example
use service_install::install::init;
install_user!()
    .current_exe()?
    .service_name("weather_checker")
    .on_boot()
    .allowed_inits([init::System::Systemd])
    .prepare_install()?
    .install()?;
Source§

impl<T: ToAssign> Spec<PathIsSet, NameIsSet, TriggerIsSet, T>

Source

pub fn prepare_install(self) -> Result<InstallSteps, PrepareInstallError>

Prepare for installing. This makes a number of checks and if they are passed it returns the InstallSteps. These implement IntoIterator and can be inspected and executed one by one or executed in one step using InstallSteps::install.

§Errors

Returns an error if:

  • the install is set to be system wide install while not running as admin/superuser.
  • the service should run as another user then the current one while not running as admin/superuser.
  • the service should run for a non-existing user.
  • no suitable install directory could be found.
  • the path for the executable does not point to a file.
Source§

impl<M: ToAssign, P: ToAssign, T: ToAssign, I: ToAssign> Spec<M, P, T, I>

Source

pub fn prepare_remove(self) -> Result<RemoveSteps, PrepareRemoveError>

Prepare for removing an install. This makes a number of checks and if they are passed it returns the RemoveSteps. These implement IntoIterator and can be inspected and executed one by one or executed in one step using RemoveSteps::remove.

§Errors

Returns an error if:

  • trying to remove a system install while not running as admin/superuser.
  • no install is found.
  • anything goes wrong setting up the removal.

Trait Implementations§

Source§

impl<Path, Name, TriggerSet, InstallType> Debug for Spec<Path, Name, TriggerSet, InstallType>
where Path: ToAssign + Debug, Name: ToAssign + Debug, TriggerSet: ToAssign + Debug, InstallType: ToAssign + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Path, Name, TriggerSet, InstallType> Freeze for Spec<Path, Name, TriggerSet, InstallType>

§

impl<Path, Name, TriggerSet, InstallType> RefUnwindSafe for Spec<Path, Name, TriggerSet, InstallType>
where Path: RefUnwindSafe, Name: RefUnwindSafe, TriggerSet: RefUnwindSafe, InstallType: RefUnwindSafe,

§

impl<Path, Name, TriggerSet, InstallType> Send for Spec<Path, Name, TriggerSet, InstallType>
where Path: Send, Name: Send, TriggerSet: Send, InstallType: Send,

§

impl<Path, Name, TriggerSet, InstallType> Sync for Spec<Path, Name, TriggerSet, InstallType>
where Path: Sync, Name: Sync, TriggerSet: Sync, InstallType: Sync,

§

impl<Path, Name, TriggerSet, InstallType> Unpin for Spec<Path, Name, TriggerSet, InstallType>
where Path: Unpin, Name: Unpin, TriggerSet: Unpin, InstallType: Unpin,

§

impl<Path, Name, TriggerSet, InstallType> UnwindSafe for Spec<Path, Name, TriggerSet, InstallType>
where Path: UnwindSafe, Name: UnwindSafe, TriggerSet: UnwindSafe, InstallType: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more