Exemple #1
0
func (app *Application) Create(c *cli.Context) {
	args := c.Args()
	name := args.First()
	exec := c.String("exec")
	force := c.Bool("force")
	restart := c.Bool("restart")
	disabled := c.Bool("disabled")
	log_dir := c.String("log-dir")

	if name == "" {
		log.Errorf("service name is required")
		return
	}
	if exec == "" {
		log.Errorf("execute is required")
		return
	}

	log.Tracef("Create %s", name)
	lcfg := runit.DefaultLoggingConfig()
	if log_dir == "" {
		lcfg.Directory = filepath.Join(app.Conf.Logging.Directory, name)
	} else {
		lcfg.Directory = log_dir
	}

	cfg := &runit.ServiceConfig{
		Name:           name,
		Exec:           exec,
		Logging:        lcfg,
		Disabled:       disabled,
		Activated:      true,
		RedirectStderr: true,
	}

	copts := &runit.CreateOptions{
		Force:   force,
		Restart: restart,
	}

	err := app.Runit.Create2(cfg, copts)
	if err != nil {
		log.Warnf("Create %s: %s", name, err)
	}

}
Exemple #2
0
func (app *Application) Setup(c *cli.Context) {
	log_level := c.String("log-level")
	verbose := c.Bool("verbose")
	service_dir := c.String("service-dir")
	active_dir := c.String("active-service-dir")
	log_dir := c.String("log-dir")
	enable := c.Bool("enable")
	disable := c.Bool("disable")
	run := c.String("run")
	log_run := c.String("log-run")

	script := c.StringSlice("script")
	restart := c.Bool("restart")
	uid := c.Int("uid")
	gid := c.Int("gid")

	args := c.Args()
	name := args.First()

	if verbose {
		gologging.SetLogLevel("trace")
	}
	if log_level != "" {
		gologging.SetLogLevel(log_level)
	}

	// template does nothing

	// make the runit api locally for these flags to function
	rcfg := runit.DefaultRunitConfig()
	if service_dir != "" {
		rcfg.ServiceDir = service_dir
	}
	if active_dir != "" {
		rcfg.ActiveDir = active_dir
	}
	rapi := runit.NewRunit(rcfg)

	if name == "" {
		log.Errorf("service name is required")
		return
	}
	if run == "" {
		log.Errorf("run command is required")
		return
	}

	if log_run != "" {
		log.Warnf("specifying log-run is not supported, argument is ignored")
	}

	log.Tracef("setup %s", name)

	lcfg := runit.DefaultLoggingConfig()
	if log_dir == "" {
		lcfg.Directory = filepath.Join(runit.DefaultLogDir, name)
	} else {
		lcfg.Directory = log_dir
	}

	var exec string
	if uid != 0 || gid != 0 {
		exec = fmt.Sprintf("chpst -u %d:%d %s", uid, gid, run)
	} else {
		exec = run
	}

	if enable {
		disable = false
	}

	// log_run is not supported

	cfg := &runit.ServiceConfig{
		Name:           name,
		Exec:           exec,
		Logging:        lcfg,
		Disabled:       disable,
		Activated:      true,
		RedirectStderr: true,
	}

	copts := &runit.CreateOptions{
		Force:   true,
		Restart: restart,
		Script:  script,
	}

	err := rapi.Create2(cfg, copts)
	if err != nil {
		log.Warnf("Create2 %s: %s", name, err)
	}

}