Skip to content

Commit

Permalink
added local type (service name)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-przybyl-wttech committed Jun 17, 2024
1 parent d0c7483 commit 68d38a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/provider/instance_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ func (ic *InstanceClient) create() error {
return nil
}

func (ic *InstanceClient) serviceName() string {
if ic.data.System.ServiceName.ValueString() != "" {
return ic.data.System.ServiceName.ValueString()
}
return ServiceName
}

func (ic *InstanceClient) saveProfileScript() error {
envFile := fmt.Sprintf("/etc/profile.d/%s.sh", ServiceName)
envFile := fmt.Sprintf("/etc/profile.d/%s.sh", ic.serviceName())

var systemEnvMap map[string]string
ic.data.System.Env.ElementsAs(ic.ctx, &systemEnvMap, true)
Expand All @@ -106,7 +113,7 @@ func (ic *InstanceClient) saveProfileScript() error {
}

func (ic *InstanceClient) configureService() error {
if !ic.data.System.ServiceEnabled.ValueBool() || ic.data.Client.Type.ValueString() == "local" {
if !ic.data.System.ServiceEnabled.ValueBool() {
return nil
}

Expand All @@ -126,7 +133,7 @@ func (ic *InstanceClient) configureService() error {
if err != nil {
return fmt.Errorf("unable to template AEM system service definition: %w", err)
}
serviceFile := fmt.Sprintf("/etc/systemd/system/%s.service", ServiceName)
serviceFile := fmt.Sprintf("/etc/systemd/system/%s.service", ic.serviceName())
if err := ic.cl.FileWrite(serviceFile, serviceTemplated); err != nil {
return fmt.Errorf("unable to write AEM system service definition '%s': %w", serviceFile, err)
}
Expand All @@ -138,14 +145,14 @@ func (ic *InstanceClient) configureService() error {
}

func (ic *InstanceClient) runServiceAction(action string) error {
if !ic.data.System.ServiceEnabled.ValueBool() || ic.data.Client.Type.ValueString() == "local" {
if !ic.data.System.ServiceEnabled.ValueBool() {
return nil
}

ic.cl.Sudo = true
defer func() { ic.cl.Sudo = false }()

outBytes, err := ic.cl.RunShellCommand(fmt.Sprintf("systemctl %s %s.service", action, ServiceName), ".")
outBytes, err := ic.cl.RunShellCommand(fmt.Sprintf("systemctl %s %s.service", action, ic.serviceName()), ".")
if err != nil {
return fmt.Errorf("unable to perform AEM system service action '%s': %w", action, err)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/instance_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type InstanceResourceModel struct {
WorkDir types.String `tfsdk:"work_dir"`
Env types.Map `tfsdk:"env"`
ServiceEnabled types.Bool `tfsdk:"service_enabled"`
ServiceName types.String `tfsdk:"service_name"`
ServiceConfig types.String `tfsdk:"service_config"`
User types.String `tfsdk:"user"`
Bootstrap InstanceScript `tfsdk:"bootstrap"`
Expand Down Expand Up @@ -176,6 +177,12 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques
Computed: true,
Default: booldefault.StaticBool(true),
},
"service_name": schema.StringAttribute{
MarkdownDescription: "Name of the AEM system service (systemd).",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
},
"service_config": schema.StringAttribute{
MarkdownDescription: "Contents of the AEM system service definition file (systemd).",
Optional: true,
Expand Down

0 comments on commit 68d38a1

Please sign in to comment.