forked from External/grumble
Add ssh admin 'restart' command.
This commit is contained in:
parent
64bdb5eb99
commit
d59392b89a
2 changed files with 41 additions and 5 deletions
|
|
@ -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.
|
||||
|
|
@ -1248,7 +1248,7 @@ func (server *Server) Start() (err error) {
|
|||
port := server.Port()
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1258,7 +1258,7 @@ func (server *Server) Start() (err error) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
36
ssh.go
36
ssh.go
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue