From 106119fb42ce9e9cb8176b2b10043f81f2567689 Mon Sep 17 00:00:00 2001 From: Ethan Holz Date: Sun, 5 Nov 2023 20:11:13 -0600 Subject: [PATCH] refactor(service): updated to generic services + service providers - renamed systemd to service - created systemd provider to replace --- .../docs/ingredients/service-providers.md | 39 +++++++++++++ src/content/docs/ingredients/service.md | 56 +++++++++---------- 2 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 src/content/docs/ingredients/service-providers.md diff --git a/src/content/docs/ingredients/service-providers.md b/src/content/docs/ingredients/service-providers.md new file mode 100644 index 0000000..108d2aa --- /dev/null +++ b/src/content/docs/ingredients/service-providers.md @@ -0,0 +1,39 @@ +--- +title: grlx.ingredients.service.providers +description: grlx built-in service providers +--- +grlx has a concept of service providers for different ways to interact with a sprout's various services. This uses a provider interface to keep this extensible and provide a standard way to interact with different service managers. The `go` interface for Service Providers looks like the following: +```go +type ServiceProvider interface { + Properties() (map[string]interface{}, error) + Parse(id, method string, properties map[string]interface{}) (ServiceProvider, error) + + Start(context.Context) error + Stop(context.Context) error + Status(context.Context) (string, error) + + Enable(context.Context) error + Disable(context.Context) error + IsEnabled(context.Context) (bool, error) + + IsRunning(context.Context) (bool, error) + Restart(context.Context) error + + Mask(context.Context) error + Unmask(context.Context) error + IsMasked(context.Context) (bool, error) + + InitName() string + IsInit() bool +} +``` +By default, grlx only has a `systemd` provider. + +## systemd +The local provider would be how you would use a file from your host system. +#### Example +```yaml +service.disabled: + - name: cronie.service + - userMode: false +``` diff --git a/src/content/docs/ingredients/service.md b/src/content/docs/ingredients/service.md index 33e702c..2384693 100644 --- a/src/content/docs/ingredients/service.md +++ b/src/content/docs/ingredients/service.md @@ -11,10 +11,10 @@ Checks if a service is masked and masks it if it is not #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.masked: @@ -28,10 +28,10 @@ Checks if a service is unmasked and unmasks it if it is not #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.unmasked: @@ -45,10 +45,10 @@ Checks if a service is running and starts it if it is not #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.running: @@ -62,10 +62,10 @@ Checks if a service is stopped and stops it if it is not #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.stopped: @@ -79,10 +79,10 @@ Checks if a service is enabled and enables it if it is not #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.enabled: @@ -96,10 +96,10 @@ Checks if a service is disabled and disables it if it is not #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.disabled: @@ -113,10 +113,10 @@ Restarts a service #### Parameters -| parameter | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------ | -| _name_ | string | yes | the name of the `systemd` unit | -| _userMode_ | bool | no | to use `systemd` in user mode, defaults to false | +| parameter | type | required | description | +| ---------- | ------ | -------- | --------------------------------------------- | +| _name_ | string | yes | the name of the service unit | +| _userMode_ | bool | no | to use service in user mode, false by default | ```yaml service.restarted: