2019-08-07 20:46:13 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-06-20 12:30:46 +00:00
|
|
|
"os"
|
|
|
|
|
2020-05-06 17:36:34 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-09-16 06:52:58 +00:00
|
|
|
"github.com/drakkan/sftpgo/service"
|
2020-03-04 08:27:14 +00:00
|
|
|
"github.com/drakkan/sftpgo/utils"
|
2019-08-07 20:46:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-09-16 06:52:58 +00:00
|
|
|
serveCmd = &cobra.Command{
|
2019-08-07 20:46:13 +00:00
|
|
|
Use: "serve",
|
|
|
|
Short: "Start the SFTP Server",
|
2020-07-09 16:58:22 +00:00
|
|
|
Long: `To start the SFTPGo with the default values for the command line flags simply
|
|
|
|
use:
|
2019-08-07 20:46:13 +00:00
|
|
|
|
2020-07-09 16:58:22 +00:00
|
|
|
$ sftpgo serve
|
2019-09-16 06:52:58 +00:00
|
|
|
|
2019-08-07 20:46:13 +00:00
|
|
|
Please take a look at the usage below to customize the startup options`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2019-09-16 06:52:58 +00:00
|
|
|
service := service.Service{
|
2020-03-04 08:27:14 +00:00
|
|
|
ConfigDir: utils.CleanDirInput(configDir),
|
2019-09-16 06:52:58 +00:00
|
|
|
ConfigFile: configFile,
|
|
|
|
LogFilePath: logFilePath,
|
|
|
|
LogMaxSize: logMaxSize,
|
|
|
|
LogMaxBackups: logMaxBackups,
|
|
|
|
LogMaxAge: logMaxAge,
|
|
|
|
LogCompress: logCompress,
|
|
|
|
LogVerbose: logVerbose,
|
2020-03-15 14:16:35 +00:00
|
|
|
Profiler: profiler,
|
2019-09-16 06:52:58 +00:00
|
|
|
Shutdown: make(chan bool),
|
|
|
|
}
|
|
|
|
if err := service.Start(); err == nil {
|
|
|
|
service.Wait()
|
2020-07-09 17:16:52 +00:00
|
|
|
if service.Error == nil {
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2019-09-16 06:52:58 +00:00
|
|
|
}
|
2020-06-20 12:30:46 +00:00
|
|
|
os.Exit(1)
|
2019-08-07 20:46:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(serveCmd)
|
2019-09-16 06:52:58 +00:00
|
|
|
addServeFlags(serveCmd)
|
2019-08-07 20:46:13 +00:00
|
|
|
}
|