2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-31 07:14:33 +01:00
|
|
|
"log"
|
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/context"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/server"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2018-11-17 13:57:19 +01:00
|
|
|
// Starts web server (user interface)
|
2018-09-24 09:53:16 +02:00
|
|
|
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",
|
2018-09-24 09:53:16 +02:00
|
|
|
Usage: "HTTP server port",
|
|
|
|
Value: 80,
|
2018-12-21 03:11:06 +01:00
|
|
|
EnvVar: "PHOTOPRISM_HTTP_PORT",
|
2018-09-24 09:53:16 +02:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2018-12-21 03:11:06 +01:00
|
|
|
Name: "http-host, i",
|
2018-09-24 09:53:16 +02:00
|
|
|
Usage: "HTTP server host",
|
|
|
|
Value: "",
|
2018-12-21 03:11:06 +01:00
|
|
|
EnvVar: "PHOTOPRISM_HTTP_HOST",
|
2018-09-24 09:53:16 +02:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2018-12-21 03:11:06 +01:00
|
|
|
Name: "http-mode, m",
|
2018-09-24 09:53:16 +02:00
|
|
|
Usage: "debug, release or test",
|
|
|
|
Value: "",
|
2018-12-21 03:11:06 +01:00
|
|
|
EnvVar: "PHOTOPRISM_HTTP_MODE",
|
2018-09-24 09:53:16 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
func startAction(ctx *cli.Context) error {
|
|
|
|
conf := context.NewConfig(ctx)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2018-12-21 03:16:50 +01:00
|
|
|
if conf.HttpServerPort() < 1 {
|
2018-09-24 09:53:16 +02:00
|
|
|
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"))
|
2018-09-24 09:53:16 +02:00
|
|
|
|
|
|
|
server.Start(conf)
|
|
|
|
|
|
|
|
fmt.Println("Done.")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|