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

@ -1213,7 +1213,7 @@ func (server *Server) Port() int {
if port == 0 {
return DefaultPort + int(server.Id) - 1
}
return 0
return port
}
// Returns the port the server is currently listning
@ -1235,7 +1235,7 @@ func (server *Server) HostAddress() string {
if host == "" {
return "0.0.0.0"
}
return ""
return host
}
// Start the server.

36
ssh.go
View file

@ -62,6 +62,10 @@ func RunSSH() {
StopServerCmd,
"<id>",
"Stops the server with the given id")
RegisterSSHCmd("restart",
RestartServerCmd,
"<id>",
"Restarts the server with the given id")
RegisterSSHCmd("supw",
SetSuperUserPasswordCmd,
"<id> <password>",
@ -262,6 +266,38 @@ func StopServerCmd(reply SshCmdReply, args []string) error {
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 {
if len(args) != 3 {
return errors.New("argument count mismatch")