|
| 1 | +package applications |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "crypto/tls" |
| 6 | + "errors" |
| 7 | + |
| 8 | + "github.com/lxc/incus-os/incus-osd/internal/systemd" |
| 9 | +) |
| 10 | + |
| 11 | +type openfga struct { |
| 12 | + common //nolint:unused |
| 13 | +} |
| 14 | + |
| 15 | +// Start starts the systemd unit. |
| 16 | +func (*openfga) Start(ctx context.Context, _ string) error { |
| 17 | + // Start the unit. |
| 18 | + return systemd.EnableUnit(ctx, true, "openfga.service") |
| 19 | +} |
| 20 | + |
| 21 | +// Stop stops the systemd unit. |
| 22 | +func (*openfga) Stop(ctx context.Context, _ string) error { |
| 23 | + // Stop the unit. |
| 24 | + return systemd.StopUnit(ctx, "openfga.service") |
| 25 | +} |
| 26 | + |
| 27 | +// Update triggers restart after an application update. |
| 28 | +func (*openfga) Update(ctx context.Context, _ string) error { |
| 29 | + // Reload the systemd daemon to pickup any service definition changes. |
| 30 | + err := systemd.ReloadDaemon(ctx) |
| 31 | + if err != nil { |
| 32 | + return err |
| 33 | + } |
| 34 | + |
| 35 | + // Restart the unit. |
| 36 | + return systemd.RestartUnit(ctx, "openfga.service") |
| 37 | +} |
| 38 | + |
| 39 | +// Initialize runs first time initialization. |
| 40 | +func (*openfga) Initialize(_ context.Context) error { |
| 41 | + return nil |
| 42 | +} |
| 43 | + |
| 44 | +// IsRunning reports if the application is currently running. |
| 45 | +func (*openfga) IsRunning(ctx context.Context) bool { |
| 46 | + return systemd.IsActive(ctx, "openfga.service") |
| 47 | +} |
| 48 | + |
| 49 | +// IsPrimary reports if the application is a primary application. |
| 50 | +func (*openfga) IsPrimary() bool { |
| 51 | + return false |
| 52 | +} |
| 53 | + |
| 54 | +// GetCertificate returns the keypair for the server certificate. |
| 55 | +func (*openfga) GetCertificate() (*tls.Certificate, error) { |
| 56 | + return nil, errors.New("not supported") |
| 57 | +} |
| 58 | + |
| 59 | +// AddTrustedCertificate adds a new trusted certificate to the application. |
| 60 | +func (*openfga) AddTrustedCertificate(_ context.Context, _ string, _ string) error { |
| 61 | + return errors.New("not supported") |
| 62 | +} |
0 commit comments