Skip to main content

Startup

Struct Startup 

Source
pub struct Startup { /* private fields */ }
Expand description

开机自启入口;按当前操作系统选择实现,并记录注册级别。

Implementations§

Source§

impl Startup

Source

pub fn root(config: StartupConfig) -> Result<Self>

创建系统级自启:随系统启动,不依赖用户登录;注册与启停通常需要管理员或 root 权限。

Source

pub fn user(config: StartupConfig) -> Result<Self>

创建当前用户级自启:随当前用户登录启动,无需管理员或 root 权限。

同一名称在系统级与用户级下互不冲突(systemd 与 launchd 存放于不同目录), 但 Windows 计划任务名在整个任务树的根目录下唯一,因此系统级与用户级不能使用同名任务。

Source

pub fn exists(&self) -> Result<bool>

查询自启是否已注册。

Source

pub fn is_run(&self) -> Result<bool>

查询自启的进程是否正在运行。

未注册时的行为由 StartupConfig::ignore_not_installed 决定:忽略时返回假,否则报错。

Source

pub fn install(&self) -> Result<()>

注册自启;已注册时不重复执行,直接返回成功。

Source

pub fn install_force(&self) -> Result<()>

注册自启并覆盖已存在的同名自启,用于让配置变更生效。

Source

pub fn uninstall(&self) -> Result<()>

注销自启;不停止正在运行的进程,需要先停止时由调用方先调 Startup::stop。

未注册时的行为由 StartupConfig::ignore_not_installed 决定。

Source

pub fn start(&self) -> Result<()>

立即启动;未注册时与已在运行时都不重复执行,直接返回成功。

Source

pub fn stop(&self) -> Result<()>

立即停止;未注册时与未运行时都不重复执行,直接返回成功。

Source

pub fn restart(&self) -> Result<()>

重启:先停止再启动。

只探测一次运行状态:未运行时直接启动,正在运行时停止后再启动。 停止阶段的错误只说明进程本来就已退出,不阻断后续启动。

Auto Trait Implementations§

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.