start_windows.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package cmd
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "github.com/drakkan/sftpgo/service"
  6. "github.com/drakkan/sftpgo/utils"
  7. "github.com/spf13/cobra"
  8. )
  9. var (
  10. startCmd = &cobra.Command{
  11. Use: "start",
  12. Short: "Start SFTPGo Windows Service",
  13. Run: func(cmd *cobra.Command, args []string) {
  14. configDir = utils.CleanDirInput(configDir)
  15. if !filepath.IsAbs(logFilePath) && utils.IsFileInputValid(logFilePath) {
  16. logFilePath = filepath.Join(configDir, logFilePath)
  17. }
  18. s := service.Service{
  19. ConfigDir: configDir,
  20. ConfigFile: configFile,
  21. LogFilePath: logFilePath,
  22. LogMaxSize: logMaxSize,
  23. LogMaxBackups: logMaxBackups,
  24. LogMaxAge: logMaxAge,
  25. LogCompress: logCompress,
  26. LogVerbose: logVerbose,
  27. Shutdown: make(chan bool),
  28. }
  29. winService := service.WindowsService{
  30. Service: s,
  31. }
  32. err := winService.RunService()
  33. if err != nil {
  34. fmt.Printf("Error starting service: %v\r\n", err)
  35. } else {
  36. fmt.Printf("Service started!\r\n")
  37. }
  38. },
  39. }
  40. )
  41. func init() {
  42. serviceCmd.AddCommand(startCmd)
  43. addServeFlags(startCmd)
  44. }