start_windows.go 1.1 KB

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