This commit is contained in:
Thomas Miceli 2024-09-18 15:50:56 +02:00
parent 6d76e9c2fb
commit b0b30cc4e9
3 changed files with 43 additions and 29 deletions

View file

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

View file

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

View file

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