1
0
Fork 0
forked from External/grumble

Add ssh admin 'restart' command.

This commit is contained in:
Mikkel Krautz 2011-11-12 02:33:22 +01:00
parent 64bdb5eb99
commit d59392b89a
2 changed files with 41 additions and 5 deletions

View file

@ -1193,7 +1193,7 @@ func (server *Server) initPerLaunchData() {
} }
// Clean per-launch data // Clean per-launch data
func (server *Server) cleanPerLaunchData() { func (server *Server) cleanPerLaunchData() {
server.pool = nil server.pool = nil
server.clients = nil server.clients = nil
server.hclients = nil server.hclients = nil
@ -1213,7 +1213,7 @@ func (server *Server) Port() int {
if port == 0 { if port == 0 {
return DefaultPort + int(server.Id) - 1 return DefaultPort + int(server.Id) - 1
} }
return 0 return port
} }
// Returns the port the server is currently listning // Returns the port the server is currently listning
@ -1235,7 +1235,7 @@ func (server *Server) HostAddress() string {
if host == "" { if host == "" {
return "0.0.0.0" return "0.0.0.0"
} }
return "" return host
} }
// Start the server. // Start the server.
@ -1248,7 +1248,7 @@ func (server *Server) Start() (err error) {
port := server.Port() port := server.Port()
// Setup our UDP listener // Setup our UDP listener
server.udpconn, err = net.ListenUDP("udp", &net.UDPAddr{ net.ParseIP(host), port }) server.udpconn, err = net.ListenUDP("udp", &net.UDPAddr{net.ParseIP(host), port})
if err != nil { if err != nil {
return err return err
} }
@ -1258,7 +1258,7 @@ func (server *Server) Start() (err error) {
} }
// Set up our TCP connection // Set up our TCP connection
server.tcpl, err = net.ListenTCP("tcp", &net.TCPAddr{ net.ParseIP(host), port }) server.tcpl, err = net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(host), port})
if err != nil { if err != nil {
return err return err
} }

36
ssh.go
View file

@ -62,6 +62,10 @@ func RunSSH() {
StopServerCmd, StopServerCmd,
"<id>", "<id>",
"Stops the server with the given id") "Stops the server with the given id")
RegisterSSHCmd("restart",
RestartServerCmd,
"<id>",
"Restarts the server with the given id")
RegisterSSHCmd("supw", RegisterSSHCmd("supw",
SetSuperUserPasswordCmd, SetSuperUserPasswordCmd,
"<id> <password>", "<id> <password>",
@ -262,6 +266,38 @@ func StopServerCmd(reply SshCmdReply, args []string) error {
return nil return nil
} }
func RestartServerCmd(reply SshCmdReply, args []string) error {
if len(args) != 2 {
return errors.New("argument count mismatch")
}
serverId, err := strconv.Atoi64(args[1])
if err != nil {
return errors.New("bad server id")
}
server, exists := servers[serverId]
if !exists {
return errors.New("no such server")
}
err = server.Stop()
if err != nil {
return fmt.Errorf("unable to stop: %v", err.Error())
}
reply.WriteString(fmt.Sprintf("[%v] Stopped\r\n", serverId))
err = server.Start()
if err != nil {
return fmt.Errorf("unable to start: %v", err.Error())
}
reply.WriteString(fmt.Sprintf("[%v] Started\r\n", serverId))
return nil
}
func SetSuperUserPasswordCmd(reply SshCmdReply, args []string) error { func SetSuperUserPasswordCmd(reply SshCmdReply, args []string) error {
if len(args) != 3 { if len(args) != 3 {
return errors.New("argument count mismatch") return errors.New("argument count mismatch")