parent
deb3d7e935
commit
d06b03bbfe
@ -17,19 +17,26 @@ import "git.tebibyte.media/sashakoshka/go-service/routines"
|
||||
|
||||
func main () {
|
||||
// parse command line arguments
|
||||
flagPidFile := cli.NewInputFlag (
|
||||
'p', "pid-file",
|
||||
"Write the PID to the specified file",
|
||||
"", cli.ValString)
|
||||
flagAddress := cli.NewInputFlag (
|
||||
'a', "address",
|
||||
"The address to host the server on",
|
||||
":8080", cli.ValString)
|
||||
// TODO have in conf, override here
|
||||
flagErrorDocument := cli.NewInputFlag (
|
||||
0, "error-document",
|
||||
"The document to use for displaying errors",
|
||||
"", cli.ValString)
|
||||
// TODO have in conf, override here
|
||||
flagDirectories := cli.NewFlag (
|
||||
'd', "directories",
|
||||
"Serve the contents of directories")
|
||||
cmd := cli.New (
|
||||
"Run an HTTP server that automaticaly executes STEP files",
|
||||
flagPidFile,
|
||||
flagAddress,
|
||||
flagErrorDocument,
|
||||
flagDirectories,
|
||||
@ -75,8 +82,18 @@ func main () {
|
||||
|
||||
log.Println(`.// initialized.`)
|
||||
|
||||
// be a daemon
|
||||
ctx, done := context.WithCancel(context.Background())
|
||||
daemon.OnSigint(done)
|
||||
pidfile := daemon.PidFile(flagPidFile.Value)
|
||||
if !pidfile.Empty() {
|
||||
err := pidfile.Start()
|
||||
if err != nil { log.Println("!!! could not write pid:", err) }
|
||||
defer func () {
|
||||
err := pidfile.Close()
|
||||
if err != nil { log.Println("!!! could not delete pidfile:", err) }
|
||||
} ()
|
||||
}
|
||||
|
||||
log.Printf("(i) listening on %s\n", httpServer.Addr)
|
||||
if err := manager.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
|
||||
|
Loading…
Reference in New Issue
Block a user