2017-07-06 13:03:44 +02:00
|
|
|
// See cmd package.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-08-27 19:10:55 +02:00
|
|
|
"github.com/spf13/cobra"
|
2018-08-29 22:06:24 +02:00
|
|
|
"github.com/zrepl/zrepl/client"
|
2018-08-27 22:21:45 +02:00
|
|
|
"github.com/zrepl/zrepl/config"
|
2018-08-27 19:10:55 +02:00
|
|
|
"github.com/zrepl/zrepl/daemon"
|
2018-08-27 22:21:45 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
2017-07-06 13:03:44 +02:00
|
|
|
)
|
|
|
|
|
2018-08-27 19:10:55 +02:00
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "zrepl",
|
|
|
|
Short: "ZFS dataset replication",
|
|
|
|
Long: `Replicate ZFS filesystems & volumes between pools:
|
|
|
|
|
|
|
|
- push & pull mode
|
|
|
|
- automatic snapshot creation & pruning
|
|
|
|
- local / over the network
|
|
|
|
- ACLs instead of blank SSH access`,
|
|
|
|
}
|
|
|
|
|
|
|
|
var daemonCmd = &cobra.Command{
|
2018-08-27 22:21:45 +02:00
|
|
|
Use: "daemon",
|
2018-08-27 19:10:55 +02:00
|
|
|
Short: "daemon",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
conf, err := config.ParseConfig(rootArgs.configFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return daemon.Run(conf)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-08-27 22:21:45 +02:00
|
|
|
var wakeupCmd = &cobra.Command{
|
|
|
|
Use: "wakeup",
|
|
|
|
Short: "wake up jobs",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
conf, err := config.ParseConfig(rootArgs.configFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-29 19:18:54 +02:00
|
|
|
return client.RunWakeup(conf, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var statusCmd = &cobra.Command{
|
|
|
|
Use: "status",
|
|
|
|
Short: "status",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
conf, err := config.ParseConfig(rootArgs.configFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return client.RunStatus(conf, args)
|
2018-08-27 22:21:45 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-05 01:41:54 +02:00
|
|
|
var stdinserverCmd = &cobra.Command{
|
|
|
|
Use: "stdinserver CLIENT_IDENTITY",
|
|
|
|
Short: "start in stdinserver mode (from authorized_keys file)",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
conf, err := config.ParseConfig(rootArgs.configFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return client.RunStdinserver(conf, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-08-27 19:10:55 +02:00
|
|
|
var rootArgs struct {
|
|
|
|
configFile string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
//cobra.OnInitialize(initConfig)
|
|
|
|
rootCmd.PersistentFlags().StringVar(&rootArgs.configFile, "config", "", "config file path")
|
|
|
|
rootCmd.AddCommand(daemonCmd)
|
2018-08-27 22:21:45 +02:00
|
|
|
rootCmd.AddCommand(wakeupCmd)
|
2018-08-29 19:18:54 +02:00
|
|
|
rootCmd.AddCommand(statusCmd)
|
2018-09-05 01:41:54 +02:00
|
|
|
rootCmd.AddCommand(stdinserverCmd)
|
2018-08-27 19:10:55 +02:00
|
|
|
}
|
|
|
|
|
2017-07-06 13:03:44 +02:00
|
|
|
func main() {
|
2018-08-27 19:10:55 +02:00
|
|
|
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
2017-07-06 13:03:44 +02:00
|
|
|
log.Printf("error executing root command: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|