refactor(service): updated to generic services + service providers

- renamed systemd to service
- created systemd provider to replace
This commit is contained in:
Ethan Holz
2023-11-05 20:11:13 -06:00
parent ec1c60e79e
commit 106119fb42
2 changed files with 67 additions and 28 deletions

View File

@@ -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
```

View File

@@ -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: