Skip to content

Commit

Permalink
(Testing branch) testing CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverLok committed Aug 19, 2024
1 parent d8306bd commit d392d7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
25 changes: 11 additions & 14 deletions internal/api/unix_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"net"
"os"
"os/signal"
"syscall"

"github.com/edulinq/autograder/internal/api/core"
"github.com/edulinq/autograder/internal/common"
Expand All @@ -15,26 +17,21 @@ import (

func startExclusiveUnixServer() error {
var socketPath = config.UNIX_SOCKET_PATH.Get()
os.Remove(socketPath)
fmt.Println("socketPath: ", socketPath)

unixSocket, err := net.Listen("unix", socketPath)
if err != nil {
log.Fatal("Failed to listen on a Unix socket.", err)
}

defer os.Remove(socketPath)
// sigc := make(chan os.Signal, 1)
// signal.Notify(sigc, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)
// go func(c chan os.Signal) {
// // Wait for a SIGINT or SIGKILL:
// sig := <-c
// fmt.Println("Caught signal %s: shutting down.", sig)
// // Stop listening (and unlink the socket if unix type):
// unixSocket.Close()
// os.Remove(socketPath)
// // And we're done:
// os.Exit(0)
// }(sigc)
defer unixSocket.Close()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
os.Remove(socketPath)
unixSocket.Close()
}()

log.Info("Unix Server Started", log.NewAttr("unix_socket", socketPath))

Expand Down
4 changes: 2 additions & 2 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var (
// Server
WEB_PORT = MustNewIntOption("web.port", 8080, "The port for the web interface to serve on.")
WEB_MAX_FILE_SIZE_KB = MustNewIntOption("web.maxsizekb", 2*1024, "The maximum allowed file size (in KB) submitted via POST request. The default is 2048 KB (2 MB).")
UNIX_SOCKET_PATH = MustNewStringOption("unix.socket", GetUnixSocketPath(), "The socket for CMD requests to serve on.")
PID_PATH = MustNewStringOption("pid.path", GetPidPath(), "The pid file to ensure only one instance of a server runs at a time.")
UNIX_SOCKET_PATH = MustNewStringOption("unix.socket", "/tmp/autograder.sock", "The socket for CMD requests to serve on.")
PID_PATH = MustNewStringOption("pid.path", "/tmp/autograder.pid", "The pid file to ensure only one instance of a server runs at a time.")
BUFFER_SIZE = MustNewIntOption("buffer.size", 8, "The length of the byte slice for the unix socket to read the size of the request.")
BIT_SIZE = MustNewIntOption("bit.size", 64, "The number of bits to generate a random hexidecimal string.")

Expand Down
1 change: 0 additions & 1 deletion internal/procedures/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func Start() error {

defer os.Remove(pidFilePath)

// Remove the unix socket file when the program terminates abruptly.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
Expand Down

0 comments on commit d392d7d

Please sign in to comment.