Using env variables to get the right version of the extension

This commit is contained in:
Filiberto Fuentes 2024-01-08 21:05:42 +00:00
Родитель 61b11f9989
Коммит f7389ac9c0
3 изменённых файлов: 7 добавлений и 10 удалений

Просмотреть файл

@ -2,6 +2,7 @@ package service
import (
"fmt"
"os"
"strings"
"github.com/Azure/run-command-handler-linux/pkg/servicehandler"
@ -28,10 +29,10 @@ ExecStart=%run_command_working_directory%/bin/run-command-handler runService
WantedBy=multi-user.target`
)
func Register(ctx *log.Context, workingDirectory string) error {
func Register(ctx *log.Context) error {
if isSystemdSupported(ctx) {
ctx.Log("message", "Generating service configuration files")
systemdUnitContent := generateServiceConfigurationContent(ctx, workingDirectory)
systemdUnitContent := generateServiceConfigurationContent(ctx)
serviceHandler := getSystemdHandler(ctx)
ctx.Log("message", "Registering service")
@ -182,7 +183,8 @@ func getSystemdHandler(ctx *log.Context) *servicehandler.Handler {
return &handler
}
func generateServiceConfigurationContent(ctx *log.Context, workingDirectory string) string {
func generateServiceConfigurationContent(ctx *log.Context) string {
workingDirectory := os.Getenv("AZURE_GUEST_AGENT_EXTENSION_PATH")
systemdConfigContent := strings.Replace(systemdUnitConfigurationTemplate, runcommand_working_directory_placeholder, workingDirectory, -1)
ctx.Log("message", "Using working directory: "+workingDirectory)
return systemdConfigContent

Просмотреть файл

@ -9,7 +9,6 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strconv"
"time"
@ -120,9 +119,7 @@ func update(ctx *log.Context, h HandlerEnvironment, report *RunCommandInstanceVi
}
if isInstalled {
workingDirectory := path.Dir(h.HandlerEnvironment.ConfigFolder)
ctx.Log("message", fmt.Sprintf("Upgrading service with new working directory: %v", workingDirectory))
err = service.Register(ctx, workingDirectory)
err = service.Register(ctx)
if err != nil {
return "", "", errors.Wrap(err, "failed to upgrade run command service"), ExitCode_UpgradeInstalledServiceFailed
}
@ -239,9 +236,7 @@ func enable(ctx *log.Context, h HandlerEnvironment, report *RunCommandInstanceVi
}
if !isInstalled {
ctx.Log("message", "Getting run command service working directory")
workingDirectory := path.Dir(h.HandlerEnvironment.ConfigFolder)
err3 := service.Register(ctx, workingDirectory)
err3 := service.Register(ctx)
if err3 != nil {
return "", "", errors.Wrap(err3, "failed to install RunCommand as a service"), ExitCode_InstallServiceFailed
}

Двоичные данные
main/run-command-handler

Двоичный файл не отображается.