Beispiel #1
0
// initd listens on a socket, spawns requested processes and reaps their
// exit statuses.
func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Fprintf(os.Stderr, "initd: panicked: %s\n", r)
			os.Exit(4)
		}
	}()

	dropCaps := flag.Bool("dropCapabilities", false, "drop capabilities before running processes")
	flag.Parse()

	container_daemon.Detach("/dev/null", "/dev/null")
	logger := lager.NewLogger("initd")

	syncWriter := os.NewFile(uintptr(4), "/dev/sync_writer")
	syscall.RawSyscall(syscall.SYS_FCNTL, uintptr(4), syscall.F_SETFD, syscall.FD_CLOEXEC)
	defer syncWriter.Close()

	sync := &containerizer.PipeSynchronizer{
		Writer: syncWriter,
	}

	reaper := system.StartReaper(logger)
	defer reaper.Stop()

	daemon := &container_daemon.ContainerDaemon{
		CmdPreparer: &container_daemon.ProcessSpecPreparer{
			Users:                  container_daemon.LibContainerUser{},
			Rlimits:                &container_daemon.RlimitsManager{},
			ProcStarterPath:        "/sbin/proc_starter",
			AlwaysDropCapabilities: *dropCaps,
		},
		Spawner: &container_daemon.Spawn{
			Runner: reaper,
			PTY:    system.KrPty,
		},
	}

	socketFile := os.NewFile(uintptr(5), "/dev/host.sock")
	listener, err := unix_socket.NewListenerFromFile(socketFile)
	if err != nil {
		fail(fmt.Sprintf("initd: failed to create listener: %s\n", err), 5)
	}

	socketFile.Close()

	if err := sync.SignalSuccess(); err != nil {
		fail(fmt.Sprintf("signal host: %s", err), 6)
	}

	if err := daemon.Run(listener); err != nil {
		fail(fmt.Sprintf("run daemon: %s", err), 7)
	}
}
Beispiel #2
0
func main() {
	logger := lager.NewLogger("initd")
	socketPath := flag.String("socket", "/run/initd.sock", "path to listen for spawn requests on")
	//unmountPath := flag.String("unmountAfterListening", "/run", "directory to unmount after succesfully listening on -socketPath")
	flag.String("unmountAfterListening", "/run", "directory to unmount after succesfully listening on -socketPath")
	flag.Parse()

	reaper := system.StartReaper(logger)
	defer reaper.Stop()

	listener, err := unix_socket.NewListenerFromPath(*socketPath)
	if err != nil {
		fmt.Printf("open %s: %s", *socketPath, err)
		os.Exit(1)
	}

	daemon := &container_daemon.ContainerDaemon{
		CmdPreparer: &container_daemon.ProcessSpecPreparer{
			Users: container_daemon.LibContainerUser{},
			AlwaysDropCapabilities: false,
		},
		Spawner: &container_daemon.Spawn{
			Runner: reaper,
			PTY:    system.KrPty,
		},
	}

	// unmount the bind-mounted socket volume now we've started listening
	// if err := syscall.Unmount(*unmountPath, syscall.MNT_DETACH); err != nil {
	// 	fmt.Printf("unmount %s: %s", *unmountPath, err)
	// 	os.Exit(2)
	// }

	if err := daemon.Run(listener); err != nil {
		fmt.Sprintf("run daemon: %s", err)
		os.Exit(1)
	}
}
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("ProcessReaper", func() {
	var reaper *system.ProcessReaper
	var waitFunc system.Wait4Func

	BeforeEach(func() {
		waitFunc = syscall.Wait4
	})

	JustBeforeEach(func() {
		logger := lager.NewLogger("process_reaper_test_logger")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.ERROR))
		reaper = system.StartReaper(logger, waitFunc)
	})

	AfterEach(func() {
		reaper.Stop()
	})

	It("waits for a process to return and returns its exit status", func() {
		cmd := exec.Command("sh", "-c", "exit 3")
		Expect(reaper.Start(cmd)).To(Succeed())

		Expect(reaper.Wait(cmd)).To(Equal(byte(3)))
	})

	It("waits for multiple processes", func() {
		cmd1 := exec.Command("sh", "-c", "exit 3")
	"github.com/cloudfoundry-incubator/garden-linux/containerizer/system"
	"github.com/pivotal-golang/lager"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("ProcessReaper", func() {
	var reaper *system.ProcessReaper

	BeforeEach(func() {
		logger := lager.NewLogger("process_reaper_test_logger")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.ERROR))
		reaper = system.StartReaper(logger)
	})

	AfterEach(func() {
		reaper.Stop()
	})

	It("waits for a process to return and returns its exit status", func() {
		cmd := exec.Command("sh", "-c", "exit 3")
		Expect(reaper.Start(cmd)).To(Succeed())

		Expect(reaper.Wait(cmd)).To(Equal(byte(3)))
	})

	It("waits for multiple processes", func() {
		cmd1 := exec.Command("sh", "-c", "exit 3")