rpc.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "log"
  17. "net"
  18. "net/http"
  19. "net/rpc"
  20. )
  21. func (a *Agent) serveRPC() {
  22. rpc.Register(a)
  23. rpc.HandleHTTP()
  24. l, e := net.Listen("tcp", ":9027")
  25. if e != nil {
  26. log.Fatal("agent:", e)
  27. }
  28. go http.Serve(l, nil)
  29. }
  30. func (a *Agent) RPCStart(args []string, pid *int) error {
  31. log.Printf("rpc: start etcd with args %v", args)
  32. err := a.start(args...)
  33. if err != nil {
  34. return err
  35. }
  36. *pid = a.cmd.Process.Pid
  37. return nil
  38. }
  39. func (a *Agent) RPCStop(args struct{}, reply *struct{}) error {
  40. log.Printf("rpc: stop etcd")
  41. return a.stop()
  42. }
  43. func (a *Agent) RPCRestart(args struct{}, pid *int) error {
  44. log.Printf("rpc: restart etcd")
  45. err := a.restart()
  46. if err != nil {
  47. return err
  48. }
  49. *pid = a.cmd.Process.Pid
  50. return nil
  51. }
  52. func (a *Agent) RPCCleanup(args struct{}, reply *struct{}) error {
  53. log.Printf("rpc: cleanup etcd")
  54. return a.cleanup()
  55. }
  56. func (a *Agent) RPCTerminate(args struct{}, reply *struct{}) error {
  57. log.Printf("rpc: terminate etcd")
  58. return a.terminate()
  59. }
  60. func (a *Agent) RPCIsolate(args struct{}, reply *struct{}) error {
  61. panic("not implemented")
  62. }