github.com/dschalla/mattermost-server@v4.8.1-rc1+incompatible/cmd/platform/jobserver.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 package main 4 5 import ( 6 "os" 7 "os/signal" 8 "syscall" 9 10 l4g "github.com/alecthomas/log4go" 11 "github.com/spf13/cobra" 12 ) 13 14 var jobserverCmd = &cobra.Command{ 15 Use: "jobserver", 16 Short: "Start the Mattermost job server", 17 Run: jobserverCmdF, 18 } 19 20 func init() { 21 jobserverCmd.Flags().Bool("nojobs", false, "Do not run jobs on this jobserver.") 22 jobserverCmd.Flags().Bool("noschedule", false, "Do not schedule jobs from this jobserver.") 23 } 24 25 func jobserverCmdF(cmd *cobra.Command, args []string) { 26 // Options 27 noJobs, _ := cmd.Flags().GetBool("nojobs") 28 noSchedule, _ := cmd.Flags().GetBool("noschedule") 29 30 // Initialize 31 a, err := initDBCommandContext("config.json") 32 if err != nil { 33 panic(err.Error()) 34 } 35 defer l4g.Close() 36 defer a.Shutdown() 37 38 a.LoadLicense() 39 40 // Run jobs 41 l4g.Info("Starting Mattermost job server") 42 if !noJobs { 43 a.Jobs.StartWorkers() 44 } 45 if !noSchedule { 46 a.Jobs.StartSchedulers() 47 } 48 49 signalChan := make(chan os.Signal, 1) 50 signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) 51 <-signalChan 52 53 // Cleanup anything that isn't handled by a defer statement 54 l4g.Info("Stopping Mattermost job server") 55 56 a.Jobs.StopSchedulers() 57 a.Jobs.StopWorkers() 58 59 l4g.Info("Stopped Mattermost job server") 60 }