Exemplo n.º 1
0
// Syncronizes the shared resources and starts the deamon to sync them.
func StartSharedSync() (*Module, error) {
	name := "internal:shared"
	if ModuleRunning(name) {
		return GetModule(name)
	}

	log.Printf("Syncing shared resources...")
	var err error
	_, err = osutil.WaitRun("shared-init", nil)
	if err != nil {
		return nil, err
	}
	log.Println("Done syncing shared resources.")

	mod := new(Module)
	mod.Name = name

	cmd, err := osutil.Run("shared-daemon", nil)
	if err != nil {
		return nil, err
	}

	mod.SyncProcess = cmd.Process
	modules[name] = mod
	return mod, nil
}
Exemplo n.º 2
0
func JailInit(moddir, jaildir, modname string) error {
	osutil.WaitRun("wfdr-reload-shared", nil)
	setup, err := osutil.RunWithEnv("jail-init", nil, []string{"WFDR_MODDIR=" + moddir, "WFDR_JAILDIR=" + jaildir, "WFDR_MODNAME=" + modname})
	if err != nil {
		return errors.New(fmt.Sprint("Could not run script to initialize jail:", err, " PATH:", os.Getenv("PATH")))
	}
	setup.Wait()
	return nil
}
Exemplo n.º 3
0
func StartModule(name string) (*Module, error) {
	if ModuleRunning(name) {
		return nil, errors.New(fmt.Sprint("The module seems to be already started..."))
	}

	// Handle special/internal modules
	switch name {
	case "internal:shared":
		return StartSharedSync()
	}

	cwd, _ := os.Getwd()
	jaildir := path.Join(cwd, "jails/"+name)
	moddir := path.Join(cwd, "modules/"+name)

	err := JailInit(moddir, jaildir, name)
	if err != nil {
		return nil, err
	}

	path := jaildir + "/sh:" + jaildir + "/bin:" + os.Getenv("PATH")

	if !osutil.FileExists(jaildir + "/sh/run") {
		cp, err := osutil.WaitRun("cp", []string{"framework/sh/jail-run", jaildir + "/sh/run"})
		if err != nil {
			return nil, errors.New(fmt.Sprint("Error copying default run file, cannot continue:", err))
		}
		cp.Wait()
	}

	modulep, err := osutil.RunWithEnvAndWd("run", []string{name}, []string{"PATH=" + path}, jaildir)
	if err != nil {
		return nil, errors.New(fmt.Sprint("Could not start module "+name+"!:", err))
	}
	pid := modulep.Process.Pid

	module := new(Module)
	module.Name = name
	module.MainProcess = modulep.Process
	// wtf? [sic]
	defer func() {
		modules[name] = module
	}()

	log.Println("Started Module "+name+"! PID:", pid)

	// Start the sync deamon, syncronizes css, js, and templates in the background
	syncproc, err := StartSync(moddir, jaildir, name)
	if err != nil {
		return module, err
	}

	module.SyncProcess = syncproc

	return module, nil
}