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,
impl<Path, Name, TriggerSet> Spec<Path, Name, TriggerSet, SystemInstall>where
Path: ToAssign,
Name: ToAssign,
TriggerSet: ToAssign,
Source§impl<Path, Name, TriggerSet, InstallType> Spec<Path, Name, TriggerSet, InstallType>where
Path: ToAssign,
Name: ToAssign,
TriggerSet: ToAssign,
InstallType: ToAssign,
impl<Path, Name, TriggerSet, InstallType> Spec<Path, Name, TriggerSet, InstallType>where
Path: ToAssign,
Name: ToAssign,
TriggerSet: ToAssign,
InstallType: ToAssign,
Sourcepub fn path(
self,
path: impl Into<PathBuf>,
) -> Spec<PathIsSet, Name, TriggerSet, InstallType>
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()?;Sourcepub fn current_exe(
self,
) -> Result<Spec<PathIsSet, Name, TriggerSet, InstallType>, Error>
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()?;Sourcepub fn service_name(
self,
service_name: impl Display,
) -> Spec<Path, NameIsSet, TriggerSet, InstallType>
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()?;Sourcepub fn on_schedule(
self,
schedule: Schedule,
) -> Spec<Path, Name, TriggerIsSet, InstallType>
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()?;Sourcepub fn on_boot(self) -> Spec<Path, Name, TriggerIsSet, InstallType>
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()?;Sourcepub fn description(self, description: impl Display) -> Self
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()?;Sourcepub fn overwrite_existing(self, overwrite: bool) -> Self
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()?;Sourcepub fn args(self, args: impl IntoIterator<Item = impl Into<String>>) -> Self
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()?;Sourcepub fn arg(self, arg: impl Into<String>) -> Self
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()?;Sourcepub fn env_vars<S: Into<String>>(
self,
args: impl IntoIterator<Item = (S, S)>,
) -> Self
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()?;Sourcepub fn env_var(
self,
variable: impl Into<String>,
value: impl Into<String>,
) -> Self
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()?;Sourcepub fn working_dir(self, dir: impl Into<PathBuf>) -> Self
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()?;Sourcepub fn allowed_inits(self, allowed: impl AsRef<[System]>) -> Self
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>
impl<T: ToAssign> Spec<PathIsSet, NameIsSet, TriggerIsSet, T>
Sourcepub fn prepare_install(self) -> Result<InstallSteps, PrepareInstallError>
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>
impl<M: ToAssign, P: ToAssign, T: ToAssign, I: ToAssign> Spec<M, P, T, I>
Sourcepub fn prepare_remove(self) -> Result<RemoveSteps, PrepareRemoveError>
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§
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>
impl<Path, Name, TriggerSet, InstallType> Sync for Spec<Path, Name, TriggerSet, InstallType>
impl<Path, Name, TriggerSet, InstallType> Unpin for Spec<Path, Name, TriggerSet, InstallType>
impl<Path, Name, TriggerSet, InstallType> UnwindSafe for Spec<Path, Name, TriggerSet, InstallType>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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