2022-07-17 18:16:00 +00:00
|
|
|
// Copyright (C) 2019-2022 Nicola Murino
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
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"
|
|
|
|
|
2022-07-24 14:18:54 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/internal/service"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/util"
|
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",
|
2021-09-18 08:50:17 +00:00
|
|
|
Short: "Start the SFTPGo service",
|
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`,
|
2022-07-19 21:28:33 +00:00
|
|
|
Run: func(_ *cobra.Command, _ []string) {
|
2022-10-22 09:56:41 +00:00
|
|
|
service.SetGraceTime(graceTime)
|
2019-09-16 06:52:58 +00:00
|
|
|
service := service.Service{
|
2021-07-11 13:26:51 +00:00
|
|
|
ConfigDir: util.CleanDirInput(configDir),
|
2020-10-20 16:42:37 +00:00
|
|
|
ConfigFile: configFile,
|
|
|
|
LogFilePath: logFilePath,
|
|
|
|
LogMaxSize: logMaxSize,
|
|
|
|
LogMaxBackups: logMaxBackups,
|
|
|
|
LogMaxAge: logMaxAge,
|
|
|
|
LogCompress: logCompress,
|
2022-07-13 08:40:24 +00:00
|
|
|
LogLevel: logLevel,
|
2021-11-06 14:18:16 +00:00
|
|
|
LogUTCTime: logUTCTime,
|
2020-10-20 16:42:37 +00:00
|
|
|
LoadDataFrom: loadDataFrom,
|
|
|
|
LoadDataMode: loadDataMode,
|
|
|
|
LoadDataQuotaScan: loadDataQuotaScan,
|
|
|
|
LoadDataClean: loadDataClean,
|
|
|
|
Shutdown: make(chan bool),
|
2019-09-16 06:52:58 +00:00
|
|
|
}
|
2022-05-07 10:50:49 +00:00
|
|
|
if err := service.Start(disableAWSInstallationCode); err == nil {
|
2019-09-16 06:52:58 +00:00
|
|
|
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)
|
2022-05-07 10:50:49 +00:00
|
|
|
addAWSContainerFlags(serveCmd)
|
2019-08-07 20:46:13 +00:00
|
|
|
}
|