JFLib

plat/service.rs#

Source: lib/plat/service.rs

service -- programs that run as a system service

  run_service(name, run) -> exit code
      Windows: started by the service control manager, run() runs while the service reports
      RUNNING; a stop or shutdown request sets stop_requested(), reports STOP_PENDING and gives
      run() 20 s before the process ends.  Started any other way (a console): run() directly.
      Linux: run() directly (systemd starts the program like any other; SIGTERM ends it, the
      programs keep their data crash-safe).
  stop_requested() -> bool
  install(&ServiceSpec) / uninstall(name) / start(name) / stop(name) / state(name)
      Windows: the service control manager (automatic start as LocalSystem, restart after a
      failure); Linux: a systemd unit in /etc/systemd/system and systemctl.  Both need
      administrator / root rights; the errors say so.
      A failure is a crash or a run() that returned another code than 0 without a stop having
      been asked for: the service manager then starts the program again (Windows: 5 s after
      the first failure, 15 s after the second, 60 s after every further one, counted anew
      after a day without one; systemd: after 5 s; launchd: at the earliest 5 s after the
      last start).
  program_path(&ServiceSpec) -> the program install registers: Windows: a program outside
      Program Files is copied to %ProgramFiles%\<name>\ first (only administrators may change
      it there; uninstall leaves the copy, a new install replaces it); Linux, macOS: the program
  unit_text(&ServiceSpec) -> the systemd unit install writes (Linux)
  plist_text(&ServiceSpec) -> the launchd property list install writes (macOS: a daemon in
      /Library/LaunchDaemons, launchctl bootstrap / bootout / kickstart; iOS has no services)
  Android has no system services for an app (docs/ANDROID.md, decision 8): run_service runs
      run() directly, program_path is None, install / start / stop / uninstall answer an error
      text, state NotInstalled -- the module is there so apps build without a cfg of their own
  • fn stop_requested() -> bool whether the service manager asked the program to stop

  • struct ServiceSpec<'a> what a service is

    • name: &'a str -- Windows: the service name ("BackupCraftServer"); Linux: the unit name ("backupcraft-server")
    • display: &'a str
    • description: &'a str
    • exe: &'a str -- the program (absolute) and its arguments
    • args: &'a [String]
  • enum ServiceState

    • NotInstalled
    • Stopped
    • Starting
    • Running
    • Stopping
    • Other

impl ServiceState

  • fn text(self) -> &'static str

  • fn unit_text(s: &ServiceSpec) -> String the systemd unit of a service

  • fn plist_text(s: &ServiceSpec) -> String the launchd property list of a service (macOS): started at boot, again after a failure, umask 077

Source: docs/API.md in the JFLib repository.