Esempio n. 1
0
func TestLaunchd(t *testing.T) {
	if !util.Darwin() {
		t.Skip("FIXME - OSX only")
		return
	}
	t.Parallel()
	l, err := detectLaunchd("darwin/")
	assert.Nil(t, err)
	assert.NotNil(t, l)

	// Verify we can find a known good service.
	// Should be running on all OSX machines, right?
	st, err := l.LookupService("com.apple.Finder")
	assert.NotNil(t, st)
	assert.Nil(t, err)
	assert.True(t, st.Pid > 0, "Expected positive value for PID")
	assert.Equal(t, Up, st.Status)

	st, err = l.LookupService("some.fake.service")
	assert.Nil(t, st)
	assert.NotNil(t, err)

	err = l.Restart("some.jacked.up.name")
	assert.NotNil(t, err)

	st1, err := l.LookupService("homebrew.mxcl.memcached")
	if err == nil && st1.Pid > 0 && st1.Status == Up {
		err = l.Restart("homebrew.mxcl.memcached")
		assert.Nil(t, err)
		st2, err := l.LookupService("homebrew.mxcl.memcached")
		assert.Nil(t, err)
		assert.Equal(t, Up, st2.Status)
		assert.NotEqual(t, st1.Pid, st2.Pid)
	}
}
Esempio n. 2
0
func findDownPid() int {
	if util.Darwin() {
		return 2
	}

	pid := 2
	for {
		_, err := os.Stat(fmt.Sprintf("/proc/%d", pid))
		if err != nil && os.IsNotExist(err) {
			return pid
		}
		pid++
		if pid == 1000 {
			panic("Unable to find available PID slot")
		}
	}
}
Esempio n. 3
0
func detectLaunchd(rootDir string) (InitSystem, error) {
	if !util.Darwin() {
		return nil, nil
	}
	util.Info("Detected OSX, using launchd")

	usr, err := user.Current()
	if err != nil {
		return nil, err
	}

	dir := usr.HomeDir
	paths := []string{
		dir + "/Library/LaunchAgents",
		"/Library/LaunchAgents",
		"/Library/LaunchDaemons",
		"/System/Library/LaunchDaemons",
	}
	return &Launchd{paths}, nil
}