From b0b30cc4e9c7874e510cb5c09adad85259e54f42 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Wed, 18 Sep 2024 15:50:56 +0200 Subject: [PATCH] helm tmp --- deploy/helm/templates/configmap.yaml | 2 ++ deploy/helm/templates/deployment.yaml | 30 ++------------------ internal/cli/main.go | 40 ++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/deploy/helm/templates/configmap.yaml b/deploy/helm/templates/configmap.yaml index 9079766..2dff80e 100644 --- a/deploy/helm/templates/configmap.yaml +++ b/deploy/helm/templates/configmap.yaml @@ -10,6 +10,8 @@ data: {{ tpl (.Values.config | toYaml) . | indent 4 }} replace_secrets.sh: | #!/bin/sh + ls + exit 0 set -e config_file="/tmp/config/config.yml" output_file="/config/config.yml" diff --git a/deploy/helm/templates/deployment.yaml b/deploy/helm/templates/deployment.yaml index 619d817..10c1d7e 100644 --- a/deploy/helm/templates/deployment.yaml +++ b/deploy/helm/templates/deployment.yaml @@ -32,20 +32,6 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} spec: - initContainers: - - name: init-config - image: busybox - command: [ "/bin/sh", "/scripts/replace_secrets.sh" ] - volumeMounts: - - name: config-template - mountPath: /tmp/config - - name: secret-config - mountPath: /tmp/secrets - readOnly: true - - name: scripts - mountPath: /scripts - - name: config - mountPath: /config {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} @@ -89,7 +75,7 @@ spec: volumeMounts: - name: opengist-data mountPath: /opengist - - name: config + - name: config-cm mountPath: /config.yml subPath: config.yml {{- if .Values.extraVolumeMounts }} @@ -103,21 +89,9 @@ spec: {{- else }} emptyDir: {} {{- end }} - - name: config - emptyDir: {} - - name: config-template + - name: config-cm configMap: name: {{ include "opengist.fullname" . }} - - name: secret-config - secret: - secretName: {{ include "opengist.fullname" . }}-secret - - name: scripts - configMap: - name: {{ include "opengist.fullname" . }} - items: - - key: replace_secrets.sh - path: replace_secrets.sh - mode: 0755 {{- if .Values.volumes }} {{- toYaml .Values.volumes | nindent 8 }} {{- end }} diff --git a/internal/cli/main.go b/internal/cli/main.go index e313c23..b067a31 100644 --- a/internal/cli/main.go +++ b/internal/cli/main.go @@ -12,8 +12,10 @@ import ( "github.com/thomiceli/opengist/internal/web" "github.com/urfave/cli/v2" "os" + "os/signal" "path" "path/filepath" + "syscall" ) var CmdVersion = cli.Command{ @@ -29,10 +31,30 @@ var CmdStart = cli.Command{ Name: "start", Usage: "Start Opengist server", Action: func(ctx *cli.Context) error { + stopCtx, stop := signal.NotifyContext(ctx.Context, syscall.SIGINT, syscall.SIGTERM) + defer stop() + Initialize(ctx) + + fmt.Println("OG_DEV:", os.Getenv("OG_DEV")) + homeDir := config.GetHomeDir() + fmt.Println("Home Directory:", homeDir) + sessionPath := path.Join(config.GetHomeDir(), "sessions") + fmt.Println("Session Path:", sessionPath) + fmt.Println("About to start server") + go web.NewServer(os.Getenv("OG_DEV") == "1", path.Join(config.GetHomeDir(), "sessions")).Start() + fmt.Println("http server started") go ssh.Start() - select {} + fmt.Println("ssh server started") + + fmt.Println("stop") + <-stopCtx.Done() + fmt.Println("sig") + shutdown() + fmt.Println("done") + + return nil }, } @@ -116,6 +138,22 @@ func Initialize(ctx *cli.Context) { } } +func shutdown() { + log.Info().Msg("Shutting down database...") + if err := db.Close(); err != nil { + log.Error().Err(err).Msg("Failed to close database") + } + + log.Info().Msg("Shutting down index...") + if config.C.IndexEnabled { + if err := index.Close(); err != nil { + log.Error().Err(err).Msg("Failed to close index") + } + } + + log.Info().Msg("Shutdown complete") +} + func createSymlink(homePath string, configPath string) error { if err := os.MkdirAll(filepath.Join(homePath, "symlinks"), 0755); err != nil { return err