start_windows.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (C) 2019 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. "fmt"
  17. "os"
  18. "github.com/spf13/cobra"
  19. "github.com/drakkan/sftpgo/v2/internal/service"
  20. "github.com/drakkan/sftpgo/v2/internal/util"
  21. )
  22. var (
  23. startCmd = &cobra.Command{
  24. Use: "start",
  25. Short: "Start the SFTPGo Windows Service",
  26. Run: func(_ *cobra.Command, _ []string) {
  27. configDir = util.CleanDirInput(configDir)
  28. checkServeParamsFromEnvFiles(configDir)
  29. service.SetGraceTime(graceTime)
  30. s := service.Service{
  31. ConfigDir: 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. winService := service.WindowsService{
  47. Service: s,
  48. }
  49. err := winService.RunService()
  50. if err != nil {
  51. fmt.Printf("Error starting service: %v\r\n", err)
  52. os.Exit(1)
  53. } else {
  54. fmt.Printf("Service started!\r\n")
  55. }
  56. },
  57. }
  58. )
  59. func init() {
  60. serviceCmd.AddCommand(startCmd)
  61. addServeFlags(startCmd)
  62. }