Beispiel #1
0
func StartModule(name string) (*Module, os.Error) {
	if ModuleRunning(name) {
		return nil, os.NewError(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)
	JailInit(moddir, jaildir, name)

	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, os.NewError(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, os.NewError(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
}
Beispiel #2
0
// Creates the pipe if it does not exist, and then opens it using OpenPipe().
func MakeAndOpen(pipename string) (*os.File, os.Error) {
	if !osutil.FileExists(pipename) {
		Mkfifo(pipename, 0644)
	}
	return Open(pipename)
}