chipsenkbeil / service-manager-rs

Provides adapters to communicate with various operating system service managers like launchd and systemd
Apache License 2.0
174 stars 13 forks source link

[FEATURE request] Command-line interface and language-agnostic configuration language #20

Open SamuelMarks opened 3 months ago

SamuelMarks commented 3 months ago

For use in other languages, it would be great to expose a C FFI and (more easily done first) a CLI interface with a language-agnostic configuration language, something like:

# Global to all service-manager-rs
constants: &global_const
   ${if_win}:
      exe: ".exe"
   ${if_not_win}:
      exe: ""

Then you'd roughly have:

name: service_name
constants: &constants
    prefix:
        ${if_win}:
            "%TMP%\foo"
        ${if_not_win}:
            "/tmp/foo"
lifecycle:
   start:  my_init*global_const.exe --prefix *constants.prefix start
   reload: my_init*global_const.exe --prefix *constants.prefix reload
   stop:   my_init*global_const.exe --prefix *constants.prefix stop

Which could be used like so:

$ server-manager install -c "my_yaml_file.yml"
$ server-manager remove "service_name"

And alternatively be specified all at the CLI:

$ server-manager install "my_init" --start "my_init start" --reload "my_init reload" --stop "my_init stop"
$ server-manager remove  "my_init"
chipsenkbeil commented 2 months ago

@SamuelMarks I use this library in some of my own CLI tools. Do you see there being much demand for a standalone CLI that offers the functionality you described? Is yaml the popular configuration language to use?

This wouldn't take very long to implement, but thinking of the value here.

SamuelMarks commented 2 months ago

@chipsenkbeil YAML is pretty popular, as is TOML, JSON and what-have-you. YAML seemed like the simplest syntax to get this example working for you.

I think a CLI would create a whole of new use-cases. For example, I'm working on a large number of new package-managers; originally written in C; then Go; and now Rust (also ² & ³).

(but for outside contributors I wouldn't want to limit their implementation language)

If you think about what is required to build a package manager, it is:

  1. Download
  2. Extract
  3. Dependency resolution (libsolv I guess works here - is open-source and cross-platform [even to Windows])
  4. "Install"
  5. Verification (for download, extract, dependency-resolution, install)

Now the install step might also involve installing services. I haven't seen any other project like yours which does it in such a cross-platform manner.

Kudos!

So what do you think; have I made a sufficient case for being language agnostic and/or creating C bindings? =)

Thanks for your consideration