@@ -19,22 +19,28 @@ import (
1919 "transcoder/server/repository"
2020 "transcoder/server/scheduler"
2121 "transcoder/server/web"
22+ "transcoder/update"
23+ "transcoder/version"
2224)
2325
2426type CmdLineOpts struct {
25- Database repository.SQLServerConfig `mapstructure:"database"`
26- Web web.WebServerConfig `mapstructure:"web"`
27- Scheduler scheduler.SchedulerConfig `mapstructure:"scheduler"`
27+ Database repository.SQLServerConfig `mapstructure:"database"`
28+ Web web.WebServerConfig `mapstructure:"web"`
29+ Scheduler scheduler.SchedulerConfig `mapstructure:"scheduler"`
30+ NoUpdateMode bool `mapstructure:"noUpdateMode"`
31+ NoUpdates bool `mapstructure:"noUpdates"`
2832}
2933
3034var (
31- opts CmdLineOpts
32- ApplicationFileName string
35+ ApplicationName = "transcoderd-server"
36+ showVersion = false
37+ opts CmdLineOpts
3338)
3439
3540func init () {
3641 //Scheduler
3742 var verbose bool
43+ pflag .BoolVar (& showVersion , "version" , false , "Print version and exit" )
3844 pflag .BoolVar (& verbose , "verbose" , false , "Enable verbose logging" )
3945 pflag .Duration ("scheduler.scheduleTime" , time .Minute * 5 , "Execute the scheduling loop every X seconds" )
4046 pflag .Duration ("scheduler.jobTimeout" , time .Hour * 24 , "Requeue jobs that are running for more than X minutes" )
@@ -52,6 +58,7 @@ func init() {
5258 pflag .String ("database.User" , "postgres" , "DB User" )
5359 pflag .String ("database.Password" , "postgres" , "DB Password" )
5460 pflag .String ("database.Scheme" , "server" , "DB Scheme" )
61+ update .PFlags ()
5562 pflag .Usage = usage
5663
5764 //pflag.Parse()
@@ -104,18 +111,6 @@ func init() {
104111 //Fix Paths
105112 opts .Scheduler .SourcePath = filepath .Clean (opts .Scheduler .SourcePath )
106113 helper .CheckPath (opts .Scheduler .SourcePath )
107-
108- /*
109- scheduleTimeDuration, err := time.ParseDuration(opts.ScheduleTime)
110- if err!=nil {
111- log.Panic(err)
112- }
113- jobTimeout, err := time.ParseDuration(opts.JobTimeout)
114- if err!=nil {
115- log.Panic(err)
116- }
117- opts.Scheduler.ScheduleTime = scheduleTimeDuration
118- opts.Scheduler.JobTimeout = jobTimeout*/
119114}
120115
121116func usage () {
@@ -125,6 +120,10 @@ func usage() {
125120}
126121
127122func main () {
123+ if showVersion {
124+ version .LogVersion ()
125+ os .Exit (0 )
126+ }
128127 wg := & sync.WaitGroup {}
129128 ctx , cancel := context .WithCancel (context .Background ())
130129 sigs := make (chan os.Signal , 1 )
@@ -133,8 +132,28 @@ func main() {
133132 shutdownHandler (ctx , sigs , cancel )
134133 wg .Done ()
135134 }()
136- //Prepare resources
137- log .Infof ("Preparing to RunWithContext..." )
135+
136+ if opts .NoUpdates {
137+ version .AppLogger ().Warnf ("Updates are disabled, %s won't check for updates" , ApplicationName )
138+ }
139+
140+ updater , err := update .NewUpdater (version .Version , ApplicationName , opts .NoUpdates , os .TempDir ())
141+ if err != nil {
142+ log .Panic (err )
143+ }
144+
145+ if opts .NoUpdateMode || opts .NoUpdates {
146+ version .AppLogger ().Infof ("Starting server" )
147+ applicationRun (wg , ctx , updater )
148+ } else {
149+ updater .Run (wg , ctx )
150+ }
151+
152+ wg .Wait ()
153+ log .Info ("Exit..." )
154+ }
155+
156+ func applicationRun (wg * sync.WaitGroup , ctx context.Context , updater * update.Updater ) {
138157 //Repository persist
139158 var repo repository.Repository
140159 repo , err := repository .NewSQLRepository (opts .Database )
@@ -155,9 +174,8 @@ func main() {
155174
156175 //WebConfig Server
157176 var webServer * web.WebServer
158- webServer = web .NewWebServer (opts .Web , scheduler )
177+ webServer = web .NewWebServer (opts .Web , scheduler , updater )
159178 webServer .Run (wg , ctx )
160- wg .Wait ()
161179}
162180
163181func shutdownHandler (ctx context.Context , sigs chan os.Signal , cancel context.CancelFunc ) {
0 commit comments