veyron/tools/*: Remove dependence on rt.R()/rt.Init()

Change-Id: I2dd04028a2eaefdf99efa1177926dada7d54f91c
diff --git a/tools/application/impl.go b/tools/application/impl.go
index e37608f..033775b 100644
--- a/tools/application/impl.go
+++ b/tools/application/impl.go
@@ -14,7 +14,6 @@
 	"veyron.io/lib/cmdline"
 	"veyron.io/veyron/veyron/services/mgmt/repository"
 	"veyron.io/veyron/veyron2/context"
-	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/services/mgmt/application"
 )
 
@@ -67,7 +66,7 @@
 	}
 	name, profiles := args[0], args[1]
 	app := repository.ApplicationClient(name)
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	j, err := getEnvelopeJSON(ctx, app, profiles)
 	if err != nil {
@@ -99,7 +98,7 @@
 	if err != nil {
 		return fmt.Errorf("ReadFile(%v): %v", envelope, err)
 	}
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	if err = putEnvelopeJSON(ctx, app, profiles, j); err != nil {
 		return err
@@ -125,7 +124,7 @@
 	}
 	name, profile := args[0], args[1]
 	app := repository.ApplicationClient(name)
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	if err := app.Remove(ctx, profile); err != nil {
 		return err
@@ -159,7 +158,7 @@
 	f.Close()
 	defer os.Remove(fileName)
 
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	envData, err := getEnvelopeJSON(ctx, app, profile)
 	if err != nil {
diff --git a/tools/application/impl_test.go b/tools/application/impl_test.go
index 526f4f5..d7a6421 100644
--- a/tools/application/impl_test.go
+++ b/tools/application/impl_test.go
@@ -104,7 +104,13 @@
 }
 
 func TestApplicationClient(t *testing.T) {
-	runtime := rt.Init()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	defer runtime.Cleanup()
+
 	server, endpoint, err := startServer(t, runtime)
 	if err != nil {
 		return
diff --git a/tools/application/main.go b/tools/application/main.go
index 9e5d556..66c4112 100644
--- a/tools/application/main.go
+++ b/tools/application/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }
diff --git a/tools/binary/impl.go b/tools/binary/impl.go
index 69f0f51..3874c2c 100644
--- a/tools/binary/impl.go
+++ b/tools/binary/impl.go
@@ -21,7 +21,7 @@
 		return cmd.UsageErrorf("delete: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	von := args[0]
-	if err := binary.Delete(von); err != nil {
+	if err := binary.Delete(runtime.NewContext(), von); err != nil {
 		return err
 	}
 	fmt.Fprintf(cmd.Stdout(), "Binary deleted successfully\n")
@@ -48,7 +48,7 @@
 		return cmd.UsageErrorf("download: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	von, filename := args[0], args[1]
-	if err := binary.DownloadToFile(von, filename); err != nil {
+	if err := binary.DownloadToFile(runtime.NewContext(), von, filename); err != nil {
 		return err
 	}
 	fmt.Fprintf(cmd.Stdout(), "Binary downloaded to file %s\n", filename)
@@ -75,7 +75,7 @@
 		return cmd.UsageErrorf("upload: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	von, filename := args[0], args[1]
-	if err := binary.UploadFromFile(von, filename); err != nil {
+	if err := binary.UploadFromFile(runtime.NewContext(), von, filename); err != nil {
 		return err
 	}
 	fmt.Fprintf(cmd.Stdout(), "Binary uploaded from file %s\n", filename)
diff --git a/tools/binary/impl_test.go b/tools/binary/impl_test.go
index d438459..b1f18fd 100644
--- a/tools/binary/impl_test.go
+++ b/tools/binary/impl_test.go
@@ -107,7 +107,13 @@
 }
 
 func TestBinaryClient(t *testing.T) {
-	runtime := rt.Init()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	defer runtime.Cleanup()
+
 	server, endpoint, err := startServer(t, runtime)
 	if err != nil {
 		return
diff --git a/tools/binary/main.go b/tools/binary/main.go
index 9e5d556..66c4112 100644
--- a/tools/binary/main.go
+++ b/tools/binary/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }
diff --git a/tools/build/impl.go b/tools/build/impl.go
index a4b9b87..e03779f 100644
--- a/tools/build/impl.go
+++ b/tools/build/impl.go
@@ -6,13 +6,12 @@
 	"io/ioutil"
 	"os"
 	"path/filepath"
-	"runtime"
+	goruntime "runtime"
 	"strings"
 	"time"
 
 	"veyron.io/lib/cmdline"
 	"veyron.io/veyron/veyron2/context"
-	"veyron.io/veyron/veyron2/rt"
 	vbuild "veyron.io/veyron/veyron2/services/mgmt/build"
 )
 
@@ -22,8 +21,8 @@
 )
 
 func init() {
-	cmdBuild.Flags.StringVar(&flagArch, "arch", runtime.GOARCH, "Target architecture.")
-	cmdBuild.Flags.StringVar(&flagOS, "os", runtime.GOOS, "Target operating system.")
+	cmdBuild.Flags.StringVar(&flagArch, "arch", goruntime.GOARCH, "Target architecture.")
+	cmdBuild.Flags.StringVar(&flagOS, "os", goruntime.GOOS, "Target operating system.")
 }
 
 var cmdRoot = &cmdline.Command{
@@ -140,7 +139,6 @@
 	binaries := make(chan vbuild.File)
 	go func() {
 		defer close(binaries)
-		rt.Init()
 		client := vbuild.BuilderClient(name)
 		stream, err := client.Build(ctx, vbuild.Architecture(flagArch), vbuild.OperatingSystem(flagOS))
 		if err != nil {
@@ -211,7 +209,7 @@
 	cancel, errchan := make(chan struct{}), make(chan error)
 	defer close(errchan)
 
-	ctx, ctxCancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, ctxCancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer ctxCancel()
 
 	// Start all stages of the pipeline.
diff --git a/tools/build/impl_test.go b/tools/build/impl_test.go
index 2778896..4f4d3f7 100644
--- a/tools/build/impl_test.go
+++ b/tools/build/impl_test.go
@@ -5,6 +5,7 @@
 	"strings"
 	"testing"
 
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/naming"
 	"veyron.io/veyron/veyron2/rt"
@@ -39,8 +40,8 @@
 
 type dispatcher struct{}
 
-func startServer(t *testing.T) (ipc.Server, naming.Endpoint) {
-	server, err := rt.R().NewServer()
+func startServer(runtime veyron2.Runtime, t *testing.T) (ipc.Server, naming.Endpoint) {
+	server, err := runtime.NewServer()
 	if err != nil {
 		t.Fatalf("NewServer failed: %v", err)
 	}
@@ -62,8 +63,12 @@
 }
 
 func TestBuildClient(t *testing.T) {
-	rt.Init()
-	server, endpoint := startServer(t)
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	server, endpoint := startServer(runtime, t)
 	defer stopServer(t, server)
 
 	cmd := root()
diff --git a/tools/build/main.go b/tools/build/main.go
index 9e5d556..66c4112 100644
--- a/tools/build/main.go
+++ b/tools/build/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }
diff --git a/tools/mounttable/impl.go b/tools/mounttable/impl.go
index efa69fc..6afca98 100644
--- a/tools/mounttable/impl.go
+++ b/tools/mounttable/impl.go
@@ -8,12 +8,11 @@
 	"veyron.io/veyron/veyron2/context"
 	"veyron.io/veyron/veyron2/naming"
 	"veyron.io/veyron/veyron2/options"
-	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/services/mounttable"
 )
 
 func bindMT(ctx context.T, name string) (mounttable.MountTableClientMethods, error) {
-	e, err := rt.R().Namespace().ResolveToMountTableX(ctx, name)
+	e, err := runtime.Namespace().ResolveToMountTableX(ctx, name)
 	if err != nil {
 		return nil, err
 	}
@@ -48,7 +47,7 @@
 	if expected, got := 2, len(args); expected != got {
 		return cmd.UsageErrorf("glob: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	c, err := bindMT(ctx, args[0])
 	if err != nil {
@@ -117,9 +116,9 @@
 			}
 		}
 	}
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
-	call, err := rt.R().Client().StartCall(ctx, args[0], "Mount", []interface{}{args[1], seconds, 0}, options.NoResolve(true))
+	call, err := runtime.Client().StartCall(ctx, args[0], "Mount", []interface{}{args[1], seconds, 0}, options.NoResolve(true))
 	if err != nil {
 		return err
 	}
@@ -147,9 +146,9 @@
 	if expected, got := 2, len(args); expected != got {
 		return cmd.UsageErrorf("unmount: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
-	call, err := rt.R().Client().StartCall(ctx, args[0], "Unmount", []interface{}{args[1]}, options.NoResolve(true))
+	call, err := runtime.Client().StartCall(ctx, args[0], "Unmount", []interface{}{args[1]}, options.NoResolve(true))
 	if err != nil {
 		return err
 	}
@@ -176,9 +175,9 @@
 	if expected, got := 1, len(args); expected != got {
 		return cmd.UsageErrorf("mount: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
-	call, err := rt.R().Client().StartCall(ctx, args[0], "ResolveStepX", []interface{}{}, options.NoResolve(true))
+	call, err := runtime.Client().StartCall(ctx, args[0], "ResolveStepX", []interface{}{}, options.NoResolve(true))
 	if err != nil {
 		return err
 	}
diff --git a/tools/mounttable/impl_test.go b/tools/mounttable/impl_test.go
index 90e83e2..9c59eb6 100644
--- a/tools/mounttable/impl_test.go
+++ b/tools/mounttable/impl_test.go
@@ -85,7 +85,13 @@
 }
 
 func TestMountTableClient(t *testing.T) {
-	runtime := rt.Init()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	defer runtime.Cleanup()
+
 	server, endpoint, err := startServer(t, runtime)
 	if err != nil {
 		return
diff --git a/tools/mounttable/main.go b/tools/mounttable/main.go
index 9e5d556..66c4112 100644
--- a/tools/mounttable/main.go
+++ b/tools/mounttable/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }
diff --git a/tools/namespace/impl.go b/tools/namespace/impl.go
index a1f1f47..5af02db 100644
--- a/tools/namespace/impl.go
+++ b/tools/namespace/impl.go
@@ -6,7 +6,6 @@
 
 	"veyron.io/lib/cmdline"
 	"veyron.io/veyron/veyron2/naming"
-	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/vlog"
 )
 
@@ -27,8 +26,8 @@
 		return cmd.UsageErrorf("glob: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	pattern := args[0]
-	ns := rt.R().Namespace()
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ns := runtime.Namespace()
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	c, err := ns.Glob(ctx, pattern)
 	if err != nil {
@@ -71,8 +70,8 @@
 	if err != nil {
 		return fmt.Errorf("TTL parse error: %v", err)
 	}
-	ns := rt.R().Namespace()
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ns := runtime.Namespace()
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	if err = ns.Mount(ctx, name, server, ttl); err != nil {
 		vlog.Infof("ns.Mount(%q, %q, %s) failed: %v", name, server, ttl, err)
@@ -100,8 +99,8 @@
 	}
 	name := args[0]
 	server := args[1]
-	ns := rt.R().Namespace()
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ns := runtime.Namespace()
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	if err := ns.Unmount(ctx, name, server); err != nil {
 		vlog.Infof("ns.Unmount(%q, %q) failed: %v", name, server, err)
@@ -125,8 +124,8 @@
 		return cmd.UsageErrorf("resolve: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	name := args[0]
-	ns := rt.R().Namespace()
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ns := runtime.Namespace()
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	servers, err := ns.Resolve(ctx, name)
 	if err != nil {
@@ -153,8 +152,8 @@
 		return cmd.UsageErrorf("resolvetomt: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	name := args[0]
-	ns := rt.R().Namespace()
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ns := runtime.Namespace()
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	e, err := ns.ResolveToMountTableX(ctx, name)
 	if err != nil {
@@ -181,8 +180,8 @@
 		return cmd.UsageErrorf("unresolve: incorrect number of arguments, expected %d, got %d", expected, got)
 	}
 	name := args[0]
-	ns := rt.R().Namespace()
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ns := runtime.Namespace()
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	servers, err := ns.Unresolve(ctx, name)
 	if err != nil {
diff --git a/tools/namespace/main.go b/tools/namespace/main.go
index 9e5d556..66c4112 100644
--- a/tools/namespace/main.go
+++ b/tools/namespace/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }
diff --git a/tools/principal/main.go b/tools/principal/main.go
index 9096bb3..570af91 100644
--- a/tools/principal/main.go
+++ b/tools/principal/main.go
@@ -25,6 +25,8 @@
 )
 
 var (
+	runtime veyron2.Runtime
+
 	// Flags for the "blessself" command
 	flagBlessSelfFor time.Duration
 
@@ -53,7 +55,7 @@
 that this tool is running in.
 `,
 		Run: func(cmd *cmdline.Command, args []string) error {
-			p := rt.Init().Principal()
+			p := runtime.Principal()
 			fmt.Printf("Public key : %v\n", p.PublicKey())
 			fmt.Println("---------------- BlessingStore ----------------")
 			fmt.Printf("%v", p.BlessingStore().DebugString())
@@ -140,7 +142,7 @@
 				}
 				caveats = append(caveats, cav)
 			}
-			blessing, err := rt.Init().Principal().BlessSelf(name, caveats...)
+			blessing, err := runtime.Principal().BlessSelf(name, caveats...)
 			if err != nil {
 				return fmt.Errorf("failed to create self-signed blessing for name %q: %v", name, err)
 			}
@@ -189,8 +191,7 @@
 			if len(args) != 2 {
 				return fmt.Errorf("require exactly two arguments, provided %d", len(args))
 			}
-			r := rt.Init()
-			p := r.Principal()
+			p := runtime.Principal()
 
 			var with security.Blessings
 			var err error
@@ -217,7 +218,7 @@
 			if len(flagBlessRemoteKey) > 0 {
 				// Send blessings to a "server" started by a "recvblessings" command
 				granter := &granter{p, with, extension, caveats, flagBlessRemoteKey}
-				return sendBlessings(r, tobless, granter, flagBlessRemoteToken)
+				return sendBlessings(runtime, tobless, granter, flagBlessRemoteToken)
 			}
 			// Blessing a principal whose key is available locally.
 			var key security.PublicKey
@@ -261,7 +262,7 @@
 blessings set on the store with the "..." pattern).
 `,
 		Run: func(cmd *cmdline.Command, args []string) error {
-			return dumpBlessings(rt.Init().Principal().BlessingStore().ForPeer(args...))
+			return dumpBlessings(runtime.Principal().BlessingStore().ForPeer(args...))
 		},
 	}
 
@@ -273,7 +274,7 @@
 the environment that this tool is running in.
 `,
 		Run: func(cmd *cmdline.Command, args []string) error {
-			return dumpBlessings(rt.Init().Principal().BlessingStore().Default())
+			return dumpBlessings(runtime.Principal().BlessingStore().Default())
 		},
 	}
 
@@ -311,7 +312,7 @@
 				return fmt.Errorf("failed to decode provided blessings: %v", err)
 			}
 			pattern := security.BlessingPattern(args[1])
-			p := rt.Init().Principal()
+			p := runtime.Principal()
 			if _, err := p.BlessingStore().Set(blessings, pattern); err != nil {
 				return fmt.Errorf("failed to set blessings %v for peers %v: %v", blessings, pattern, err)
 			}
@@ -347,7 +348,7 @@
 			if err != nil {
 				return fmt.Errorf("failed to decode provided blessings: %v", err)
 			}
-			p := rt.Init().Principal()
+			p := runtime.Principal()
 			if err := p.BlessingStore().SetDefault(blessings); err != nil {
 				return fmt.Errorf("failed to set blessings %v as default: %v", blessings, err)
 			}
@@ -433,7 +434,6 @@
 		Run: func(cmd *cmdline.Command, args []string) error {
 			// Initialize the runtime first so that any local errors are reported
 			// before the HTTP roundtrips for obtaining the macaroon begin.
-			r := rt.Init()
 			blessedChan := make(chan string)
 			defer close(blessedChan)
 			macaroonChan, err := getMacaroonForBlessRPC(flagSeekBlessingsFrom, blessedChan)
@@ -442,7 +442,7 @@
 			}
 			macaroon := <-macaroonChan
 			service := <-macaroonChan
-			ctx, cancel := r.NewContext().WithTimeout(time.Minute)
+			ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 			defer cancel()
 
 			var reply security.WireBlessings
@@ -459,17 +459,17 @@
 			<-macaroonChan
 
 			if flagSeekBlessingsSetDefault {
-				if err := r.Principal().BlessingStore().SetDefault(blessings); err != nil {
+				if err := runtime.Principal().BlessingStore().SetDefault(blessings); err != nil {
 					return fmt.Errorf("failed to set blessings %v as default: %v", blessings, err)
 				}
 			}
 			if pattern := security.BlessingPattern(flagSeekBlessingsForPeer); len(pattern) > 0 {
-				if _, err := r.Principal().BlessingStore().Set(blessings, pattern); err != nil {
+				if _, err := runtime.Principal().BlessingStore().Set(blessings, pattern); err != nil {
 					return fmt.Errorf("failed to set blessings %v for peers %v: %v", blessings, pattern, err)
 				}
 			}
 			if flagAddToRoots {
-				if err := r.Principal().AddToRoots(blessings); err != nil {
+				if err := runtime.Principal().AddToRoots(blessings); err != nil {
 					return fmt.Errorf("AddToRoots failed: %v", err)
 				}
 			}
@@ -514,8 +514,7 @@
 			if len(args) != 0 {
 				return fmt.Errorf("command accepts no arguments")
 			}
-			r := rt.Init()
-			server, err := r.NewServer()
+			server, err := runtime.NewServer()
 			if err != nil {
 				return fmt.Errorf("failed to create server to listen for blessings: %v", err)
 			}
@@ -529,7 +528,7 @@
 				return fmt.Errorf("unable to generate token: %v", err)
 			}
 			service := &recvBlessingsService{
-				principal: r.Principal(),
+				principal: runtime.Principal(),
 				token:     base64.URLEncoding.EncodeToString(token[:]),
 				notify:    make(chan error),
 			}
@@ -542,7 +541,7 @@
 			fmt.Println("You may want to adjust flags affecting the caveats on this blessing, for example using")
 			fmt.Println("the --for flag, or change the extension to something more meaningful")
 			fmt.Println()
-			fmt.Printf("principal bless --remote_key=%v --remote_token=%v %v %v\n", r.Principal().PublicKey(), service.token, naming.JoinAddressName(ep.String(), ""), extension)
+			fmt.Printf("principal bless --remote_key=%v --remote_token=%v %v %v\n", runtime.Principal().PublicKey(), service.token, naming.JoinAddressName(ep.String(), ""), extension)
 			fmt.Println()
 			fmt.Println("...waiting for sender..")
 			return <-service.notify
@@ -551,6 +550,13 @@
 )
 
 func main() {
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
+
 	cmdBlessSelf.Flags.DurationVar(&flagBlessSelfFor, "for", 0, "Duration of blessing validity (zero means no that the blessing is always valid)")
 
 	cmdBless.Flags.DurationVar(&flagBlessFor, "for", time.Minute, "Duration of blessing validity")
diff --git a/tools/profile/impl.go b/tools/profile/impl.go
index 459b2ab..8869787 100644
--- a/tools/profile/impl.go
+++ b/tools/profile/impl.go
@@ -7,7 +7,6 @@
 	"veyron.io/lib/cmdline"
 	"veyron.io/veyron/veyron/services/mgmt/profile"
 	"veyron.io/veyron/veyron/services/mgmt/repository"
-	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/services/mgmt/build"
 )
 
@@ -26,7 +25,7 @@
 	}
 	name := args[0]
 	p := repository.ProfileClient(name)
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	label, err := p.Label(ctx)
 	if err != nil {
@@ -51,7 +50,7 @@
 	}
 	name := args[0]
 	p := repository.ProfileClient(name)
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	desc, err := p.Description(ctx)
 	if err != nil {
@@ -76,7 +75,7 @@
 	}
 	name := args[0]
 	p := repository.ProfileClient(name)
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	spec, err := p.Specification(ctx)
 	if err != nil {
@@ -111,7 +110,7 @@
 		Label:       "example",
 		OS:          build.Linux,
 	}
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	if err := p.Put(ctx, spec); err != nil {
 		return err
@@ -135,7 +134,7 @@
 	}
 	name := args[0]
 	p := repository.ProfileClient(name)
-	ctx, cancel := rt.R().NewContext().WithTimeout(time.Minute)
+	ctx, cancel := runtime.NewContext().WithTimeout(time.Minute)
 	defer cancel()
 	if err := p.Remove(ctx); err != nil {
 		return err
diff --git a/tools/profile/impl_test.go b/tools/profile/impl_test.go
index 1dd149d..b442271 100644
--- a/tools/profile/impl_test.go
+++ b/tools/profile/impl_test.go
@@ -108,7 +108,13 @@
 }
 
 func TestProfileClient(t *testing.T) {
-	runtime := rt.Init()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	defer runtime.Cleanup()
+
 	server, endpoint, err := startServer(t, runtime)
 	if err != nil {
 		return
diff --git a/tools/profile/main.go b/tools/profile/main.go
index 9e5d556..66c4112 100644
--- a/tools/profile/main.go
+++ b/tools/profile/main.go
@@ -4,12 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
 
 	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }
diff --git a/tools/vrpc/impl.go b/tools/vrpc/impl.go
index 7d0e560..4a87c67 100644
--- a/tools/vrpc/impl.go
+++ b/tools/vrpc/impl.go
@@ -13,7 +13,6 @@
 	"veyron.io/veyron/veyron2/context"
 	"veyron.io/veyron/veyron2/ipc"
 	"veyron.io/veyron/veyron2/naming"
-	"veyron.io/veyron/veyron2/rt"
 	"veyron.io/veyron/veyron2/vdl/vdlutil"
 	"veyron.io/veyron/veyron2/vom"
 	"veyron.io/veyron/veyron2/wiretype"
@@ -53,8 +52,6 @@
 		return cmd.UsageErrorf("describe: incorrect number of arguments, expected 1, got %d", len(args))
 	}
 
-	runtime := rt.R()
-
 	client, err := setupClient(cmd, runtime)
 	if err != nil {
 		return err
@@ -93,8 +90,6 @@
 	}
 	server, method, args := args[0], args[1], args[2:]
 
-	runtime := rt.R()
-
 	client, err := setupClient(cmd, runtime)
 	if err != nil {
 		return err
diff --git a/tools/vrpc/impl_test.go b/tools/vrpc/impl_test.go
index f585f2b..cfbef5d 100644
--- a/tools/vrpc/impl_test.go
+++ b/tools/vrpc/impl_test.go
@@ -169,7 +169,13 @@
 }
 
 func TestVRPC(t *testing.T) {
-	runtime := rt.Init()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		t.Fatalf("Unexpected error initializing runtime: %s", err)
+	}
+	defer runtime.Cleanup()
+
 	// Skip defer runtime.Cleanup() to avoid messing up other tests in the
 	// same process.
 	server, endpoint, err := startServer(t, runtime)
diff --git a/tools/vrpc/main.go b/tools/vrpc/main.go
index f52ab6f..66c4112 100644
--- a/tools/vrpc/main.go
+++ b/tools/vrpc/main.go
@@ -4,10 +4,20 @@
 package main
 
 import (
+	"veyron.io/veyron/veyron2"
 	"veyron.io/veyron/veyron2/rt"
+
+	_ "veyron.io/veyron/veyron/profiles"
 )
 
+var runtime veyron2.Runtime
+
 func main() {
-	defer rt.Init().Cleanup()
+	var err error
+	runtime, err = rt.New()
+	if err != nil {
+		panic(err)
+	}
+	defer runtime.Cleanup()
 	root().Main()
 }