mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
add silent mode
This commit is contained in:
parent
a79543f0af
commit
d114b6996a
@ -23,11 +23,14 @@ var (
|
|||||||
parallism = flag.Int("parallism", 4, "control the # of concurrency execution")
|
parallism = flag.Int("parallism", 4, "control the # of concurrency execution")
|
||||||
tmpFsParam = flag.String("tmpfs", "size=8m,nr_inodes=4k", "tmpfs mount data")
|
tmpFsParam = flag.String("tmpfs", "size=8m,nr_inodes=4k", "tmpfs mount data")
|
||||||
dir = flag.String("dir", "", "specifies direcotry to store file upload / download (in memory by default)")
|
dir = flag.String("dir", "", "specifies direcotry to store file upload / download (in memory by default)")
|
||||||
|
silent = flag.Bool("silent", false, "do not print logs")
|
||||||
|
|
||||||
envPool envexec.EnvironmentPool
|
envPool envexec.EnvironmentPool
|
||||||
cgroupPool envexec.CgroupPool
|
cgroupPool envexec.CgroupPool
|
||||||
|
|
||||||
fs fileStore
|
fs fileStore
|
||||||
|
|
||||||
|
printLog = log.Println
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -43,12 +46,15 @@ func main() {
|
|||||||
os.MkdirAll(*dir, 0755)
|
os.MkdirAll(*dir, 0755)
|
||||||
fs = newFileLocalStore(*dir)
|
fs = newFileLocalStore(*dir)
|
||||||
}
|
}
|
||||||
|
if *silent {
|
||||||
|
printLog = func(v ...interface{}) {}
|
||||||
|
}
|
||||||
|
|
||||||
root, err := ioutil.TempDir("", "dm")
|
root, err := ioutil.TempDir("", "dm")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("Created tmp dir for container root at:", root)
|
printLog("Created tmp dir for container root at:", root)
|
||||||
|
|
||||||
mb := mount.NewBuilder().
|
mb := mount.NewBuilder().
|
||||||
// basic exec and lib
|
// basic exec and lib
|
||||||
@ -56,7 +62,6 @@ func main() {
|
|||||||
WithBind("/lib", "lib", true).
|
WithBind("/lib", "lib", true).
|
||||||
WithBind("/lib64", "lib64", true).
|
WithBind("/lib64", "lib64", true).
|
||||||
WithBind("/usr", "usr", true).
|
WithBind("/usr", "usr", true).
|
||||||
WithBind("/var/lib/ghc", "var/lib/ghc", true).
|
|
||||||
// java wants /proc/self/exe as it need relative path for lib
|
// java wants /proc/self/exe as it need relative path for lib
|
||||||
// however, /proc gives interface like /proc/1/fd/3 ..
|
// however, /proc gives interface like /proc/1/fd/3 ..
|
||||||
// it is fine since open that file will be a EPERM
|
// it is fine since open that file will be a EPERM
|
||||||
@ -68,6 +73,8 @@ func main() {
|
|||||||
WithBind("/etc/fpc.cfg", "etc/fpc.cfg", true).
|
WithBind("/etc/fpc.cfg", "etc/fpc.cfg", true).
|
||||||
// go wants /dev/null
|
// go wants /dev/null
|
||||||
WithBind("/dev/null", "dev/null", false).
|
WithBind("/dev/null", "dev/null", false).
|
||||||
|
// ghc wants /var/lib/ghc
|
||||||
|
WithBind("/var/lib/ghc", "var/lib/ghc", true).
|
||||||
// work dir
|
// work dir
|
||||||
WithTmpfs("w", *tmpFsParam).
|
WithTmpfs("w", *tmpFsParam).
|
||||||
// tmp dir
|
// tmp dir
|
||||||
@ -76,7 +83,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("Created default container mount at:", mb)
|
printLog("Created default container mount at:", mb)
|
||||||
|
|
||||||
b := &container.Builder{
|
b := &container.Builder{
|
||||||
Root: root,
|
Root: root,
|
||||||
@ -88,22 +95,28 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("Created cgroup builder with:", cgb)
|
printLog("Created cgroup builder with:", cgb)
|
||||||
|
|
||||||
envPool = pool.NewEnvPool(b)
|
envPool = pool.NewEnvPool(b)
|
||||||
cgroupPool = pool.NewFakeCgroupPool(cgb)
|
cgroupPool = pool.NewFakeCgroupPool(cgb)
|
||||||
|
|
||||||
log.Println("Starting worker with parallism", *parallism)
|
printLog("Starting worker with parallism", *parallism)
|
||||||
startWorkers()
|
startWorkers()
|
||||||
|
|
||||||
r := gin.Default()
|
var r *gin.Engine
|
||||||
|
if *silent {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
r = gin.New()
|
||||||
|
} else {
|
||||||
|
r = gin.Default()
|
||||||
|
}
|
||||||
r.GET("/file", fileGet)
|
r.GET("/file", fileGet)
|
||||||
r.POST("/file", filePost)
|
r.POST("/file", filePost)
|
||||||
r.GET("/file/:fid", fileIDGet)
|
r.GET("/file/:fid", fileIDGet)
|
||||||
r.DELETE("/file/:fid", fileIDDelete)
|
r.DELETE("/file/:fid", fileIDDelete)
|
||||||
r.POST("/run", handleRun)
|
r.POST("/run", handleRun)
|
||||||
|
|
||||||
log.Println("Starting http server at", *addr)
|
printLog("Starting http server at", *addr)
|
||||||
r.Run(*addr)
|
r.Run(*addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -176,6 +176,9 @@ func prepareCmd(rc cmd) (*envexec.Cmd, map[string]bool, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
copyIn, err := prepareCopyIn(rc.CopyIn)
|
copyIn, err := prepareCopyIn(rc.CopyIn)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
copyOutSet := make(map[string]bool)
|
copyOutSet := make(map[string]bool)
|
||||||
// pipe default copyout
|
// pipe default copyout
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user