hacdias / webdav

A simple and standalone WebDAV server.
MIT License
3.41k stars 426 forks source link

About unix bug: 'bind: address already in use. ' #139

Closed zmaplex closed 3 months ago

zmaplex commented 2 years ago

First start

-# ./webdav -c config.yaml
2022-09-18T22:18:08.522-0400    info    Listening       {"address": "/run/ui-ssh-webdav.socket"}

Second launch after ending the process with ctrl + c command

-# ./webdav -c config.yaml
2022/09/18 22:19:34 listen unix /run/ui-ssh-webdav.socket: bind: address already in use

Must be executerm -rf /run/ui-ssh-webdav.socket command to resolve it.

config.yaml

address: unix:/run/ui-ssh-webdav.socket
auth: true
....

Hope the following information can help you

https://stackoverflow.com/questions/16681944/how-to-reliably-unlink-a-unix-domain-socket-in-go-programming-language

// Create the socket to listen on:
l, err := net.Listen(socketType, socketAddr)
if err != nil {
    log.Fatal(err)
    return
}

// Unix sockets must be unlink()ed before being reused again.

// Handle common process-killing signals so we can gracefully shut down:
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM)
go func(c chan os.Signal) {
    // Wait for a SIGINT or SIGKILL:
    sig := <-c
    log.Printf("Caught signal %s: shutting down.", sig)
    // Stop listening (and unlink the socket if unix type):
    l.Close()
    // And we're done:
    os.Exit(0)
}(sigc)

// Start the HTTP server:
log.Fatal(http.Serve(l, http.HandlerFunc(indexHtml)))