2020-03-16 22:24:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/sevlyar/go-daemon"
|
2020-05-08 10:46:18 +02:00
|
|
|
"gitlab.com/saburly/kiviscraplib/config"
|
2020-03-16 22:24:08 +01:00
|
|
|
"gitlab.com/saburly/kiviscraplib/structures"
|
|
|
|
|
"gitlab.com/saburly/kiviscraplib/webserver"
|
2020-03-18 20:42:16 +01:00
|
|
|
"gitlab.com/saburly/kiviscraplib/workerserver"
|
2020-03-16 22:24:08 +01:00
|
|
|
"log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var queue chan structures.Request
|
|
|
|
|
var end chan string
|
|
|
|
|
|
|
|
|
|
// To terminate the daemon use:
|
|
|
|
|
// kill `cat sample.pid`
|
|
|
|
|
func main() {
|
2020-05-08 10:46:18 +02:00
|
|
|
config.InitServerConfig()
|
|
|
|
|
|
2020-03-16 22:24:08 +01:00
|
|
|
cntxt := &daemon.Context{
|
|
|
|
|
PidFileName: "sample.pid",
|
|
|
|
|
PidFilePerm: 0644,
|
|
|
|
|
LogFileName: "sample.log",
|
|
|
|
|
LogFilePerm: 0640,
|
|
|
|
|
WorkDir: "./",
|
|
|
|
|
Umask: 027,
|
|
|
|
|
Args: []string{"[kivi scraping load balancer]"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d, err := cntxt.Reborn()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal("Unable to run: ", err)
|
|
|
|
|
}
|
|
|
|
|
if d != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer cntxt.Release()
|
|
|
|
|
|
|
|
|
|
// todo: put queue length in env variable
|
|
|
|
|
queue = make(chan structures.Request, 1000)
|
|
|
|
|
end = make(chan string)
|
|
|
|
|
|
|
|
|
|
go webserver.ServeHTTP(queue, end)
|
2020-03-18 20:42:16 +01:00
|
|
|
go workerserver.ServeWorkers(queue, end)
|
2020-03-16 22:24:08 +01:00
|
|
|
|
|
|
|
|
ended := <-end
|
|
|
|
|
|
2020-03-18 20:42:16 +01:00
|
|
|
log.Printf("%s ended so closing the daemon\n", ended)
|
2020-03-16 22:24:08 +01:00
|
|
|
}
|