func JailInit(moddir, jaildir, modname string) os.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 os.NewError(fmt.Sprint("Could not run script to initialize jail:", err, " PATH:", os.Getenv("PATH"))) } setup.Wait() return nil }
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 }
// Syncronizes the shared resources and starts the deamon to sync them. func StartSharedSync() (*Module, os.Error) { name := "internal:shared" if ModuleRunning(name) { return GetModule(name) } var err os.Error _, err = osutil.WaitRun("shared-init", nil) if err != nil { return nil, err } mod := new(Module) mod.Name = name cmd, err := osutil.Run("shared-daemon", nil) if err != nil { return nil, err } mod.SyncProcess = cmd.Process mod.MainProcess = cmd.Process modules[name] = mod return mod, nil }
// TODO: Use syscall.Mkfifo, but it doesn't seem to work atm. // NOTE: perms are ignored, since this calls the mkfifo program to do it's work. // WARNING: Hackish implementation. func Mkfifo(name string, perms uint32) { osutil.WaitRun("mkfifo", []string{name}) }