2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-31 07:14:33 +01:00
|
|
|
"log"
|
|
|
|
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
|
|
|
"github.com/photoprism/photoprism/internal/server"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var StartCommand = cli.Command{
|
|
|
|
Name: "start",
|
|
|
|
Usage: "Starts web server",
|
|
|
|
Flags: startFlags,
|
|
|
|
Action: startAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
var startFlags = []cli.Flag{
|
|
|
|
cli.IntFlag{
|
|
|
|
Name: "server-port, p",
|
|
|
|
Usage: "HTTP server port",
|
|
|
|
Value: 80,
|
|
|
|
EnvVar: "PHOTOPRISM_SERVER_PORT",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "server-host, i",
|
|
|
|
Usage: "HTTP server host",
|
|
|
|
Value: "",
|
|
|
|
EnvVar: "PHOTOPRISM_SERVER_HOST",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "server-mode, m",
|
|
|
|
Usage: "debug, release or test",
|
|
|
|
Value: "",
|
|
|
|
EnvVar: "PHOTOPRISM_SERVER_MODE",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:42:54 +01:00
|
|
|
// Starts web serve using startFlags; called by startCommand
|
2018-09-24 09:53:16 +02:00
|
|
|
func startAction(context *cli.Context) error {
|
|
|
|
conf := photoprism.NewConfig(context)
|
|
|
|
|
2018-11-09 20:48:23 +01:00
|
|
|
if conf.GetServerPort() < 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()
|
|
|
|
|
|
|
|
fmt.Printf("Starting web server at %s:%d...\n", context.String("server-host"), context.Int("server-port"))
|
|
|
|
|
|
|
|
server.Start(conf)
|
|
|
|
|
|
|
|
fmt.Println("Done.")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|