serve.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (C) 2019-2022 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 := service.Service{
  31. ConfigDir: util.CleanDirInput(configDir),
  32. ConfigFile: configFile,
  33. LogFilePath: logFilePath,
  34. LogMaxSize: logMaxSize,
  35. LogMaxBackups: logMaxBackups,
  36. LogMaxAge: logMaxAge,
  37. LogCompress: logCompress,
  38. LogLevel: logLevel,
  39. LogUTCTime: logUTCTime,
  40. LoadDataFrom: loadDataFrom,
  41. LoadDataMode: loadDataMode,
  42. LoadDataQuotaScan: loadDataQuotaScan,
  43. LoadDataClean: loadDataClean,
  44. Shutdown: make(chan bool),
  45. }
  46. if err := service.Start(disableAWSInstallationCode); err == nil {
  47. service.Wait()
  48. if service.Error == nil {
  49. os.Exit(0)
  50. }
  51. }
  52. os.Exit(1)
  53. },
  54. }
  55. )
  56. func init() {
  57. rootCmd.AddCommand(serveCmd)
  58. addServeFlags(serveCmd)
  59. addAWSContainerFlags(serveCmd)
  60. }