goldwarden-vaultwarden-bitw.../cmd/daemonize.go

56 lines
1.3 KiB
Go
Raw Normal View History

2023-07-17 03:23:26 +02:00
package cmd
import (
2024-02-04 01:58:04 +01:00
"fmt"
"syscall"
2023-07-17 03:23:26 +02:00
"github.com/awnumar/memguard"
"github.com/quexten/goldwarden/agent"
"github.com/spf13/cobra"
)
var daemonizeCmd = &cobra.Command{
Use: "daemonize",
Short: "Starts the agent as a daemon",
Long: `Starts the agent as a daemon. The agent will run in the background and will
run in the background until it is stopped.`,
Run: func(cmd *cobra.Command, args []string) {
2023-08-21 18:37:34 +02:00
websocketDisabled := runtimeConfig.WebsocketDisabled
sshDisabled := runtimeConfig.DisableSSHAgent
2023-08-21 13:52:06 +02:00
if websocketDisabled {
println("Websocket disabled")
}
if sshDisabled {
println("SSH agent disabled")
}
2024-02-04 01:58:04 +01:00
cleanup := func() {
fmt.Println("removing sockets and exiting")
fmt.Println("unlinking", runtimeConfig.GoldwardenSocketPath)
err := syscall.Unlink(runtimeConfig.GoldwardenSocketPath)
if err != nil {
fmt.Println(err)
}
fmt.Println("unlinking", runtimeConfig.SSHAgentSocketPath)
err = syscall.Unlink(runtimeConfig.SSHAgentSocketPath)
if err != nil {
fmt.Println(err)
}
fmt.Println("memguard wiping memory and exiting")
2023-07-17 03:23:26 +02:00
memguard.SafeExit(0)
2024-02-04 01:58:04 +01:00
}
2023-12-30 18:53:01 +01:00
err := agent.StartUnixAgent(runtimeConfig.GoldwardenSocketPath, runtimeConfig)
2023-07-17 03:23:26 +02:00
if err != nil {
panic(err)
}
2024-02-04 01:58:04 +01:00
cleanup()
2023-07-17 03:23:26 +02:00
},
}
func init() {
rootCmd.AddCommand(daemonizeCmd)
}