serve.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2019-2023 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package cmd
  15. import (
  16. "os"
  17. "github.com/spf13/cobra"
  18. "github.com/drakkan/sftpgo/v2/internal/service"
  19. "github.com/drakkan/sftpgo/v2/internal/util"
  20. )
  21. var (
  22. serveCmd = &cobra.Command{
  23. Use: "serve",
  24. Short: "Start the SFTPGo service",
  25. Long: `To start the SFTPGo with the default values for the command line flags simply
  26. use:
  27. $ sftpgo serve
  28. Please take a look at the usage below to customize the startup options`,
  29. Run: func(_ *cobra.Command, _ []string) {
  30. service.SetGraceTime(graceTime)
  31. service := service.Service{
  32. ConfigDir: util.CleanDirInput(configDir),
  33. ConfigFile: configFile,
  34. LogFilePath: logFilePath,
  35. LogMaxSize: logMaxSize,
  36. LogMaxBackups: logMaxBackups,
  37. LogMaxAge: logMaxAge,
  38. LogCompress: logCompress,
  39. LogLevel: logLevel,
  40. LogUTCTime: logUTCTime,
  41. LoadDataFrom: loadDataFrom,
  42. LoadDataMode: loadDataMode,
  43. LoadDataQuotaScan: loadDataQuotaScan,
  44. LoadDataClean: loadDataClean,
  45. Shutdown: make(chan bool),
  46. }
  47. if err := service.Start(disableAWSInstallationCode); err == nil {
  48. service.Wait()
  49. if service.Error == nil {
  50. os.Exit(0)
  51. }
  52. }
  53. os.Exit(1)
  54. },
  55. }
  56. )
  57. func init() {
  58. rootCmd.AddCommand(serveCmd)
  59. addServeFlags(serveCmd)
  60. addAWSContainerFlags(serveCmd)
  61. }