cmd

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: AGPL-3.0 Imports: 70 Imported by: 0

Documentation

Overview

Package cmd implements commands for running pydio services

Index

Constants

This section is empty.

Variables

View Source
var (
	FilterStartTags    []string
	FilterStartExclude []string
)
View Source
var ConfigDatabaseAddCmd = &cobra.Command{
	Use:   "add",
	Short: "Add a database connection to the configuration",
	Long: `
This command lets you add a new database connection to the configuration.

To assign the database connection to a service, you need to use the config database set command.

`,
	Run: func(cmd *cobra.Command, args []string) {

		installConfig := lib.GenerateDefaultConfig()
		if err := promptDB(installConfig); err != nil {
			cmd.Println(err)
			os.Exit(1)
		}

		cmd.Println("\033[1m## Performing Installation\033[0m")
		if err := lib.Install(context.Background(), installConfig, lib.INSTALL_DB, func(event *lib.InstallProgressEvent) {
			cmd.Println(promptui.IconGood + " " + event.Message)
		}); err != nil {
			cmd.Println(err)
			os.Exit(1)
		}

		cmd.Println("*************************************************************")
		cmd.Println(" Config has been updated, please restart now!")
		cmd.Println("**************************************************************")

	},
}

ConfigDatabaseAddCmd permits configuration of a new database connection.

View Source
var ConfigDatabaseCmd = &cobra.Command{
	Use:   "db",
	Short: "Manage Database configuration",
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}

ConfigDatabaseCmd represents the database command

View Source
var ConfigDatabaseListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all database connections",
	Long: `
This command lists all databases connections from all servers registered with cells.
`,
	Run: func(cmd *cobra.Command, args []string) {

		cfg := config.Default().(*config.Config)

		var m map[string]interface{}
		if err := cfg.UnmarshalKey("databases", &m); err != nil {
			cmd.Println(err)
			os.Exit(1)
		}

		table := tablewriter.NewWriter(cmd.OutOrStdout())
		table.SetHeader([]string{"DSN", "Driver", "Services"})

		defaultDatabaseID := cfg.Get("defaults", "database").String("")
		defaultDatabase, ok := m[defaultDatabaseID].(map[string]interface{})

		if !ok {
			cmd.Println("Default database not found")
			os.Exit(1)
		}

		table.Append([]string{defaultDatabase["dsn"].(string), defaultDatabase["driver"].(string), "default"})

		for id, v := range m {
			if id == defaultDatabaseID {
				continue
			}

			db, ok := v.(map[string]interface{})
			if !ok {
				continue
			}

			driver, ok := db["driver"]
			if !ok {
				continue
			}

			dsn, ok := db["dsn"]
			if !ok {
				continue
			}

			var services []string
			if s, err := registry.GetService(id); err == nil && s != nil {
				services = append(services, id)
			}

			for sid, vs := range m {
				dbid, ok := vs.(string)
				if !ok {
					continue
				}

				if dbid == id {
					services = append(services, sid)
				}
			}

			table.Append([]string{dsn.(string), driver.(string), strings.Join(services, ",")})
		}

		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.Render()

	},
}

ConfigDatabaseListCmd permits configuration of a new database connection.

View Source
var ConfigDatabaseSetCmd = &cobra.Command{
	Use:   "set",
	Short: "Assign a database connection to a service",
	Long: `
This command let you assign a different database connection to a service. Use default to change the default database

` + promptui.IconWarn + `  Note that the database data will not be transferred to the new database.`,
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) < 1 {
			return errors.New("Requires at least an argument, please see 'pydio config database set --help'")
		}

		return nil
	},
	Run: func(cmd *cobra.Command, args []string) {
		id := args[0]

		cfg := config.Default().(*config.Config)

		var m map[string]interface{}
		if err := cfg.UnmarshalKey("databases", &m); err != nil {
			cmd.Println(err)
			os.Exit(1)
		}

		var ids []string
		var items []string
		for id, v := range m {
			db, ok := v.(map[string]interface{})
			if !ok {
				continue
			}

			ids = append(ids, id)
			items = append(items, db["driver"].(string)+" - "+db["dsn"].(string))
		}

		selector := promptui.Select{
			Label: "Choose database connection",
			Items: items,
		}

		i, _, err := selector.Run()
		if err != nil {
			cmd.Println("Wrong database connection")
			os.Exit(1)
		}

		config.Set(ids[i], "databases", id)

		if id == "default" {
			config.Set(ids[i], "defaults", "database")
		}

		if err := config.Save("cli", fmt.Sprintf("Set database for service %s : %s", id, ids[i])); err == nil {
			cmd.Println("Config set")
		} else {
			log.Fatal(err)
		}
	},
}

ConfigDatabaseSetCmd permits configuration of a new database connection.

View Source
var (
	IsFork bool
)
View Source
var RootCmd = &cobra.Command{
	Use:   os.Args[0],
	Short: "Secure File Sharing for business",
	Long: `Thank you for using Pydio Cells.
Comprehensive sync & share solution for your collaborators. Open-source software deployed on-premise or in a private cloud.

### Installation

For the very first run, use '` + os.Args[0] + ` install' to load browser-based or command-line based installation wizard. Services
will start at the end of the installation.

### Run

Run '` + os.Args[0] + ` start' to load all services.

### Logs level

By default, logs are outputted in console format at the Info level. You can set the --log flag or set the PYDIO_LOGS_LEVEL environment
variable to one of the following values:
 - debug, info, error : logs are written in console format with the according level
 - production : logs are written in json format, for usage with a log aggregator tool.

### Services Discovery

Micro services need a registry mechanism to discover each other. You don't need to install any dependency.
Cells currently only supports NATS (nats.io) implementation. If a gnatsd service is already running, it will be detected.

`,
	PreRun: func(cmd *cobra.Command, args []string) {},
	PersistentPreRun: func(cmd *cobra.Command, args []string) {

		if cmd.Long == StartCmd.Long {
			common.LogCaptureStdOut = true
		}

		handleRegistry()

		handleBroker()

		handleTransport()

		handleSignals()

		plugins.Init()

		registry.Default.Filter(func(s registry.Service) bool {
			for _, exclude := range FilterStartExclude {
				re := regexp.MustCompile(exclude)

				if strings.HasPrefix(s.Name(), exclude) || re.MatchString(s.Name()) {
					return true
				}
			}

			return false
		})

		initServices()

		if s, err := registry.Default.ListServices(); err != nil {
			cmd.Print("Could not retrieve list of services")
			os.Exit(0)
		} else {
			allServices = s
		}
	},
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}

RootCmd represents the base command when called without any subcommands

View Source
var SslCmd = &cobra.Command{
	Use:   "ssl",
	Short: "Manage SSL configuration",
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}

SslCmd represents the ssl command

View Source
var SslModeCmd = &cobra.Command{
	Use:   "mode",
	Short: "Manage HTTPS support on proxy",
	Long: `
This command lets you enable/disabled SSL on application main access point.

Four modes are currently supported :
- TLS mode : provide the paths to certificate and key (as you would on an apache server)
- Let's Encrypt: certificate is automagically generated during installation process, and later managed (e.g. renewed) by the embedded Caddy server
- Self-Signed : a self-signed certificate will be generated at each application start
- Disabled : application will be served on HTTP

`,
	Run: func(cmd *cobra.Command, args []string) {

		extURL, _ := url.Parse(config.Get("defaults", "url").String(""))
		intURL, _ := url.Parse(config.Get("defaults", "urlInternal").String(""))

		enabled, certData, e := promptSslMode()
		if e != nil {
			log.Fatal(e)
		}

		if enabled {
			extURL.Scheme = "https"
			intURL.Scheme = "https"
		} else {
			extURL.Scheme = "http"
			intURL.Scheme = "http"
		}
		config.Set(extURL.String(), "defaults", "url")
		config.Set(intURL.String(), "defaults", "urlInternal")
		config.Set(certData, "cert")
		if e := config.Save("cli", "Update SSL mode"); e != nil {
			cmd.Println("Error while saving config: " + e.Error())
		}

		cmd.Println("*************************************************************")
		cmd.Println(" Config has been updated, please restart now!")
		cmd.Println("**************************************************************")

	},
}

SslModeCmd permits configuration of used SSL mode.

View Source
var StartCmd = &cobra.Command{
	Use:   "start",
	Short: "Start Cells services",
	Long: `Start one or more services on this machine

### Syntax

$ ` + os.Args[0] + ` start [flags] args...

Additional arguments are regexp that can match any of the service names available (see 'list' command).
The -t/--tags flag may limit to only a certain category of services, use lowercase like broker, idm, data, etc...
The -x/--exclude flag may exclude one or more services
Both flags may be used in conjunction with the regexp arguments.

### Examples

Start only services starting with grpc
$ ` + os.Args[0] + ` start pydio.grpc

Start only services for scheduler
$ ` + os.Args[0] + ` start --tag=scheduler

Start whole plateform except the roles service
$ ` + os.Args[0] + ` start --exclude=pydio.grpc.idm.roles

`,
	PreRunE: func(cmd *cobra.Command, args []string) error {

		if !IsFork {
			if err := checkFdlimit(); err != nil {
				return err
			}
		}

		registry.Default.Filter(func(s registry.Service) bool {
			re := regexp.MustCompile(common.SERVICE_INSTALL)

			if re.MatchString(s.Name()) {
				return true
			}

			return false
		})

		registry.Default.Filter(func(s registry.Service) bool {
			for _, t := range FilterStartTags {
				for _, st := range s.Tags() {
					if t == st {
						registry.ProcessStartTags = append(registry.ProcessStartTags, "t:"+t)
						return false
					}
				}
			}

			return len(FilterStartTags) > 0
		})

		registry.Default.Filter(func(s registry.Service) bool {
			for _, arg := range args {
				reArg := regexp.MustCompile(arg)
				if reArg.MatchString(s.Name()) {
					registry.ProcessStartTags = append(registry.ProcessStartTags, "s:"+s.Name())
					return false
				}
				if s.MatchesRegexp(arg) {
					registry.ProcessStartTags = append(registry.ProcessStartTags, "s:"+s.Name())
					return false
				}
			}
			return len(args) > 0
		})

		registry.Default.Filter(func(s registry.Service) bool {
			if len(args) == 0 && s.Regexp() != nil {
				return true
			}
			return false
		})

		for _, x := range FilterStartExclude {
			registry.ProcessStartTags = append(registry.ProcessStartTags, "x:"+x)
		}

		if s, err := registry.Default.ListServices(); err != nil {
			return fmt.Errorf("Could not retrieve list of services")
		} else {
			allServices = s
		}

		return nil
	},

	Run: func(cmd *cobra.Command, args []string) {

		for _, service := range allServices {
			if !IsFork && service.RequiresFork() {
				if !service.AutoStart() {
					continue
				}
				go service.ForkStart()
			} else {
				go service.Start()
			}
		}

		wg.Add(1)
		wg.Wait()
	},
}

StartCmd represents the start command

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

type Service added in v1.5.3

type Service interface {
	Name() string
	IsRunning() bool
}

type Tags

type Tags struct {
	Name     string
	Services map[string]Service
	Tags     map[string]*Tags
}

Directories

Path Synopsis
Package benchmark is the main package for performing benchmarking requests
Package benchmark is the main package for performing benchmarking requests
cmd
Package cmd implements commands for the benchmark command line tool
Package cmd implements commands for the benchmark command line tool
cmd/testsgo
Package tests is a first draft for benchmarking.
Package tests is a first draft for benchmarking.
cmd/testsgo/dummysetup
Package dummysetup provides utilitary methods to set up a dummy environment for benchmarks.
Package dummysetup provides utilitary methods to set up a dummy environment for benchmarks.
cmd/testsgo/idmtest
Package idmtest performs benchmarks on Roles
Package idmtest performs benchmarks on Roles
ctl
Package cli is the pydio control client for performing grpc requests on running services
Package cli is the pydio control client for performing grpc requests on running services
cmd
Package cmd implements all commands for pydio control client
Package cmd implements all commands for pydio control client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL