cmd

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: AGPL-3.0 Imports: 78 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 (
	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.

### Cells working directories

By default, application data is stored under the standard OS application dir : 

 - Linux: ${USER_HOME}/.config/pydio/cells
 - Darwin: ${USER_HOME}/Library/Application Support/Pydio/cells
 - Windows: ${USER_HOME}/ApplicationData/Roaming/Pydio/cells

You can customize the various storage locations with the following ENV variables : 

 - CELLS_WORKING_DIR : replace the whole standard application dir
 - CELLS_DATA_DIR : replace the location for storing default datasources (default CELLS_WORKING_DIR/data)
 - CELLS_LOG_DIR : replace the location for storing logs (default CELLS_WORKING_DIR/logs)
 - CELLS_SERVICES_DIR : replace location for services-specific data (default CELLS_WORKING_DIR/services) 

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

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

		switch cmd.Name() {
		case "version", "completion", "doc", "help", "bash", "zsh", os.Args[0]:
			return
		default:

			handleRegistry()

			handleBroker()

			handleTransport()

			handleSignals()
		}

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

RootCmd represents the base command when called without any subcommands

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
			}
		}

		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
		})

		registry.Default.Filter(func(s registry.Service) bool {

			for _, exclude := range FilterStartExclude {
				if exclude == startTagUnique && s.MustBeUnique() {
					return true
				}
			}
			for _, t := range FilterStartTags {
				if t == startTagUnique && s.MustBeUnique() {
					registry.ProcessStartTags = append(registry.ProcessStartTags, "t:"+t)
					return false
				} else {
					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
		}

		initServices()

		return nil
	},

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

		if a, _ := config.GetDefaultDatabase(); a == "" {
			var crtUser string
			if u, er := user.Current(); er == nil {
				crtUser = "(currently running as '" + u.Username + "')"
			}
			cmd.Println("****************************************************************************************")
			cmd.Println("# ")
			cmd.Println("# " + promptui.IconBad + " Oops, cannot find a valid configuration for the database!")
			cmd.Println("# ")
			cmd.Println("# A - If it is the first time you start " + os.Args[0] + ", make sure to first run the install step:")
			cmd.Println("#     $> " + os.Args[0] + " install")
			cmd.Println("# ")
			cmd.Println("# B - If you have already installed, maybe the configuration file is not accessible.")
			cmd.Println("#     Working Directory is " + config.ApplicationWorkingDir())
			cmd.Println("#     If you did not set the CELLS_WORKING_DIR environment variable, make sure you are ")
			cmd.Println("#     launching the process as the correct OS user " + crtUser + ".")
			cmd.Println("# ")
			cmd.Println("****************************************************************************************")
			cmd.Println("")
			cmd.Println("Exiting now...")
			return
		}

		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 CellsVersion

type CellsVersion struct {
	//Distribution string
	PackageLabel string
	Version      string
	BuildTime    string
	GitCommit    string
	OS           string
	Arch         string
	GoVersion    string
}

CellsVersion contains version information for the current running binary

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

Jump to

Keyboard shortcuts

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