serve.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package cmd
  2. import (
  3. "os"
  4. "github.com/spf13/cobra"
  5. "github.com/drakkan/sftpgo/service"
  6. "github.com/drakkan/sftpgo/utils"
  7. )
  8. var (
  9. serveCmd = &cobra.Command{
  10. Use: "serve",
  11. Short: "Start the SFTP Server",
  12. Long: `To start the SFTPGo with the default values for the command line flags simply
  13. use:
  14. $ sftpgo serve
  15. Please take a look at the usage below to customize the startup options`,
  16. Run: func(cmd *cobra.Command, args []string) {
  17. service := service.Service{
  18. ConfigDir: utils.CleanDirInput(configDir),
  19. ConfigFile: configFile,
  20. LogFilePath: logFilePath,
  21. LogMaxSize: logMaxSize,
  22. LogMaxBackups: logMaxBackups,
  23. LogMaxAge: logMaxAge,
  24. LogCompress: logCompress,
  25. LogVerbose: logVerbose,
  26. Profiler: profiler,
  27. Shutdown: make(chan bool),
  28. }
  29. if err := service.Start(); err == nil {
  30. service.Wait()
  31. if service.Error == nil {
  32. os.Exit(0)
  33. }
  34. }
  35. os.Exit(1)
  36. },
  37. }
  38. )
  39. func init() {
  40. rootCmd.AddCommand(serveCmd)
  41. addServeFlags(serveCmd)
  42. }