photoprism/internal/commands/start.go

62 lines
1.1 KiB
Go
Raw Normal View History

package commands
import (
"fmt"
"log"
"github.com/photoprism/photoprism/internal/context"
"github.com/photoprism/photoprism/internal/server"
"github.com/urfave/cli"
)
// Starts web server (user interface)
var StartCommand = cli.Command{
Name: "start",
Usage: "Starts web server",
Flags: startFlags,
Action: startAction,
}
var startFlags = []cli.Flag{
cli.IntFlag{
2018-12-21 03:11:06 +01:00
Name: "http-port, p",
Usage: "HTTP server port",
Value: 80,
2018-12-21 03:11:06 +01:00
EnvVar: "PHOTOPRISM_HTTP_PORT",
},
cli.StringFlag{
2018-12-21 03:11:06 +01:00
Name: "http-host, i",
Usage: "HTTP server host",
Value: "",
2018-12-21 03:11:06 +01:00
EnvVar: "PHOTOPRISM_HTTP_HOST",
},
cli.StringFlag{
2018-12-21 03:11:06 +01:00
Name: "http-mode, m",
Usage: "debug, release or test",
Value: "",
2018-12-21 03:11:06 +01:00
EnvVar: "PHOTOPRISM_HTTP_MODE",
},
}
func startAction(ctx *cli.Context) error {
conf := context.NewConfig(ctx)
if conf.HttpServerPort() < 1 {
log.Fatal("Server port must be a positive integer")
}
if err := conf.CreateDirectories(); err != nil {
log.Fatal(err)
}
conf.MigrateDb()
2018-12-21 03:11:06 +01:00
fmt.Printf("Starting web server at %s:%d...\n", ctx.String("http-host"), ctx.Int("http-port"))
server.Start(conf)
fmt.Println("Done.")
return nil
}