--- a/serve/command.go Thu Oct 28 06:18:36 2021 -0500
+++ b/serve/command.go Sun Dec 05 03:25:10 2021 -0600
@@ -1,6 +1,7 @@
@@ -18,9 +19,15 @@
SSHHostKeysPath string `kong:"flag,name='ssh-host-keys-path',env='HGK_SSH_HOST_KEYS_PATH',short='H',help='the path where host keys are kept',default='host-keys'"`
HTTPAddr string `kong:"flag,name='http-listen-addr',env='HGK_HTTP_LISTEN_ADDR',help='what address the http server listens on',default=':8080'"`
CacheSize int `kong:"flag,name='cache-size',env='HGK_HTTP_CACHE_SIZE',help='number of pages to cache',default='1000'"`
+ DisableSSH bool `kong:"flag,name='disable-ssh',env='HGK_DISABLE_SSH',help='disable the SSH server',default='false'"` + DisableHTTP bool `kong:"flag,name='disable-http',env='HGK_DISABLE_HTTP',help='disable the HTTP server',default='false'"` func (c *Command) Run(g *globals.Globals) error {
+ if c.DisableHTTP && c.DisableSSH { + return fmt.Errorf("both HTTP and SSH servers have been disabled") if err := access.Setup(g.ReposPath, g.AdminRepo); err != nil {
@@ -31,29 +38,46 @@
errChan := make(chan error, 10)
- ssh, err := ssh.NewServer(c.SSHHostKeysPath, g.ReposPath, access.AdminRepoPath())
+ var sshServer *ssh.Server + var hgwebServer *hgweb.Server - hgweb, err := hgweb.NewServer(c.HTTPAddr, c.CacheSize)
+ log.Info("SSH server has been disabled") + sshServer, err = ssh.NewServer(c.SSHHostKeysPath, g.ReposPath, access.AdminRepoPath()) + defer sshServer.Close()
- if err := ssh.Listen(c.SSHAddr); err != nil {
+ log.Info("HTTP server has been disabled") + hgwebServer, err = hgweb.NewServer(c.HTTPAddr, c.CacheSize)
+ defer hgwebServer.Close()
- if err := hgweb.Listen(); err != nil {
+ if err := sshServer.Listen(c.SSHAddr); err != nil { + if err := hgwebServer.Listen(); err != nil {