From 20d48ec85f96cfcaade98bd7572a254a2a68c148 Mon Sep 17 00:00:00 2001 From: Jared Watts Date: Thu, 8 Sep 2016 13:09:23 -0700 Subject: [PATCH] CAS-1379 Basic process management for mon/osd procs --- glide.lock | 7 ++++--- glide.yaml | 2 ++ pkg/castled/cmd/castled.go | 10 +++++++--- pkg/castled/monagent.go | 9 +++++++-- pkg/castled/osd.go | 3 ++- pkg/castled/osdagent.go | 7 ++++++- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/glide.lock b/glide.lock index 5066a8d39..e92235299 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 92b0b86293cd8ff7e45e4b92b4d116a38ea8c3a7b92137fd618742f3c67a7b15 -updated: 2016-08-31T09:18:34.23005271-07:00 +hash: e304bcf51126db7c40de2ad0abe6cf24b9d5153ef72b49244c5722f30af4e61d +updated: 2016-09-08T13:07:22.421779478-07:00 imports: - name: github.com/coreos/etcd version: d53923c636e0e4ab7f00cb75681b97a8f11f5a9d @@ -15,11 +15,12 @@ imports: - name: github.com/inconshreveable/mousetrap version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 - name: github.com/quantum/clusterd - version: 27cbadad4d31c6769e8bd3d0cd4d7908f1fe5590 + version: dfc6f8c199d906c4206cce9e9f80a301ad1f22b8 subpackages: - pkg/inventory - pkg/orchestrator - pkg/util + - pkg/proc - name: github.com/spf13/cobra version: dbb7c2d02e284aa24423e3e6e105969dffe6e4d6 subpackages: diff --git a/glide.yaml b/glide.yaml index 8a2d9921f..ed053b781 100644 --- a/glide.yaml +++ b/glide.yaml @@ -8,10 +8,12 @@ import: - client - error - package: github.com/quantum/clusterd + version: dfc6f8c199d906c4206cce9e9f80a301ad1f22b8 subpackages: - pkg/inventory - pkg/orchestrator - pkg/util + - pkg/proc - package: github.com/spf13/pflag - package: github.com/google/uuid - package: github.com/go-ini/ini diff --git a/pkg/castled/cmd/castled.go b/pkg/castled/cmd/castled.go index 78b1f7af6..fccddd1cd 100644 --- a/pkg/castled/cmd/castled.go +++ b/pkg/castled/cmd/castled.go @@ -4,13 +4,14 @@ import ( "fmt" "os" "os/signal" + "time" "github.com/spf13/cobra" "github.com/quantum/castle/pkg/castled" "github.com/quantum/castle/pkg/util" "github.com/quantum/clusterd/pkg/orchestrator" - clusterutil "github.com/quantum/clusterd/pkg/util" + "github.com/quantum/clusterd/pkg/proc" ) var ( @@ -56,8 +57,11 @@ func joinCluster(cmd *cobra.Command, args []string) error { } services := []*orchestrator.ClusterService{castled.NewCephService(devices, forceFormat)} - procMan := &clusterutil.ProcManager{} - defer procMan.Shutdown() + procMan := &proc.ProcManager{} + defer func() { + procMan.Shutdown() + <-time.After(time.Duration(1) * time.Second) + }() // start the cluster orchestration services if err := orchestrator.StartJoinCluster(services, procMan, discoveryURL, privateIPv4); err != nil { diff --git a/pkg/castled/monagent.go b/pkg/castled/monagent.go index 7364a4875..21a9da093 100644 --- a/pkg/castled/monagent.go +++ b/pkg/castled/monagent.go @@ -7,11 +7,13 @@ import ( "os" "path" "path/filepath" + "regexp" "time" ctx "golang.org/x/net/context" "github.com/quantum/clusterd/pkg/orchestrator" + "github.com/quantum/clusterd/pkg/proc" "github.com/quantum/clusterd/pkg/util" ) @@ -138,11 +140,14 @@ func (a *monAgent) runMonitor(context *orchestrator.ClusterContext, monitor *Cep // start the monitor daemon in the foreground with the given config log.Printf("starting monitor %s", monitor.Name) + monNameArg := fmt.Sprintf("--name=mon.%s", monitor.Name) err := context.ProcMan.Start( "mon", + regexp.QuoteMeta(monNameArg), + proc.ReuseExisting, "--foreground", - fmt.Sprintf("--cluster=%v", a.cluster.Name), - fmt.Sprintf("--name=mon.%v", monitor.Name), + fmt.Sprintf("--cluster=%s", a.cluster.Name), + monNameArg, fmt.Sprintf("--mon-data=%s", getMonDataDirPath(monitor.Name)), fmt.Sprintf("--conf=%s", getConfFilePath(getMonRunDirPath(monitor.Name), a.cluster.Name)), fmt.Sprintf("--public-addr=%s", monitor.Endpoint)) diff --git a/pkg/castled/osd.go b/pkg/castled/osd.go index b0b55777d..18dd02251 100644 --- a/pkg/castled/osd.go +++ b/pkg/castled/osd.go @@ -16,6 +16,7 @@ import ( "github.com/google/uuid" "github.com/quantum/castle/pkg/cephd" + "github.com/quantum/clusterd/pkg/proc" "github.com/quantum/clusterd/pkg/util" ) @@ -400,7 +401,7 @@ func createOSDFileSystem(clusterName string, osdID int, osdUUID uuid.UUID, osdDa } // create the OSD file system and journal - err := util.RunChildProcess( + err := proc.RunChildProcess( "osd", "--mkfs", "--mkkey", diff --git a/pkg/castled/osdagent.go b/pkg/castled/osdagent.go index 2ff794ac2..c3f4fd1bc 100644 --- a/pkg/castled/osdagent.go +++ b/pkg/castled/osdagent.go @@ -6,6 +6,7 @@ import ( "os" "path" "path/filepath" + "regexp" "strconv" "strings" @@ -13,6 +14,7 @@ import ( "github.com/quantum/castle/pkg/cephd" "github.com/quantum/clusterd/pkg/orchestrator" + "github.com/quantum/clusterd/pkg/proc" "github.com/quantum/clusterd/pkg/util" ) @@ -157,8 +159,11 @@ func (a *osdAgent) createOSDs(adminConn *cephd.Conn, context *orchestrator.Clust func (a *osdAgent) runOSD(context *orchestrator.ClusterContext, clusterName string, osdID int, osdUUID uuid.UUID, osdDataPath string) error { // start the OSD daemon in the foreground with the given config log.Printf("starting osd %d at %s", osdID, osdDataPath) + osdUUIDArg := fmt.Sprintf("--osd-uuid=%s", osdUUID.String()) err := context.ProcMan.Start( "osd", + regexp.QuoteMeta(osdUUIDArg), + proc.ReuseExisting, "--foreground", fmt.Sprintf("--id=%s", strconv.Itoa(osdID)), fmt.Sprintf("--cluster=%s", clusterName), @@ -166,7 +171,7 @@ func (a *osdAgent) runOSD(context *orchestrator.ClusterContext, clusterName stri fmt.Sprintf("--osd-journal=%s", getOSDJournalPath(osdDataPath)), fmt.Sprintf("--conf=%s", getOSDConfFilePath(osdDataPath, clusterName)), fmt.Sprintf("--keyring=%s", getOSDKeyringPath(osdDataPath)), - fmt.Sprintf("--osd-uuid=%s", osdUUID.String())) + osdUUIDArg) if err != nil { return fmt.Errorf("failed to start osd %d: %+v", osdID, err) }