2016-04-08 19:29:13 +00:00
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cli
import (
"github.com/spf13/cobra"
"github.com/abcum/surreal/db"
2019-11-20 13:20:27 +00:00
"github.com/abcum/surreal/kvs"
2016-07-19 11:05:32 +00:00
"github.com/abcum/surreal/log"
2016-04-08 19:29:13 +00:00
"github.com/abcum/surreal/web"
)
var startCmd = & cobra . Command {
2017-02-19 19:25:47 +00:00
Use : "start [flags]" ,
2016-04-08 19:29:13 +00:00
Short : "Start the database and http server" ,
2016-07-04 10:33:07 +00:00
PreRun : func ( cmd * cobra . Command , args [ ] string ) {
2018-05-02 01:31:31 +00:00
log . Display ( logo )
2016-04-08 19:29:13 +00:00
} ,
RunE : func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
2019-11-20 13:20:27 +00:00
if err = kvs . Setup ( opts ) ; err != nil {
log . Fatal ( err )
return
}
2016-07-04 10:33:07 +00:00
if err = db . Setup ( opts ) ; err != nil {
2016-07-19 11:05:32 +00:00
log . Fatal ( err )
2016-04-08 19:29:13 +00:00
return
}
2016-07-04 10:33:07 +00:00
if err = web . Setup ( opts ) ; err != nil {
2016-07-19 11:05:32 +00:00
log . Fatal ( err )
2016-04-08 19:29:13 +00:00
return
}
return
} ,
2017-11-16 20:00:51 +00:00
PostRunE : func ( cmd * cobra . Command , args [ ] string ) ( err error ) {
2016-04-08 19:29:13 +00:00
2019-11-20 13:20:27 +00:00
if err = web . Exit ( opts ) ; err != nil {
log . Fatal ( err )
return
}
if err = db . Exit ( opts ) ; err != nil {
2017-11-16 20:00:51 +00:00
log . Fatal ( err )
return
}
2019-11-20 13:20:27 +00:00
if err = kvs . Exit ( opts ) ; err != nil {
2017-11-16 20:00:51 +00:00
log . Fatal ( err )
return
}
return
2016-04-08 19:29:13 +00:00
} ,
}
func init ( ) {
2019-06-16 07:05:59 +00:00
startCmd . PersistentFlags ( ) . StringVarP ( & opts . Auth . Auth , "auth" , "a" , "root:root" , "Master database authentication details" )
startCmd . PersistentFlags ( ) . StringVar ( & opts . Auth . User , "auth-user" , "" , "The master username for the database. Use this as an alternative to the --auth flag" )
startCmd . PersistentFlags ( ) . StringVar ( & opts . Auth . Pass , "auth-pass" , "" , "The master password for the database. Use this as an alternative to the --auth flag" )
startCmd . PersistentFlags ( ) . StringSliceVar ( & opts . Auth . Addr , "auth-addr" , [ ] string { "0.0.0.0/0" , "0:0:0:0:0:0:0:0/0" } , "The IP address ranges from which master authentication is possible" )
2016-04-08 19:29:13 +00:00
2019-06-16 07:05:59 +00:00
startCmd . PersistentFlags ( ) . StringVar ( & opts . DB . Path , "path" , "" , "Database path used for storing data" )
startCmd . PersistentFlags ( ) . IntVar ( & opts . Port , "port" , 8000 , "The port on which to serve the web server" )
startCmd . PersistentFlags ( ) . StringVarP ( & opts . Bind , "bind" , "b" , "0.0.0.0" , "The hostname or ip address to listen for connections on" )
2016-07-04 10:33:07 +00:00
2020-09-22 09:46:00 +00:00
startCmd . PersistentFlags ( ) . DurationVar ( & opts . Query . Timeout , "timeout" , 0 , "" )
2019-06-16 07:05:59 +00:00
startCmd . PersistentFlags ( ) . StringVarP ( & opts . DB . Code , "key" , "k" , "" , "Encryption key to use for on-disk encryption" )
2018-05-02 01:42:16 +00:00
2019-10-07 23:43:39 +00:00
startCmd . PersistentFlags ( ) . DurationVar ( & opts . DB . Proc . Flush , "db-flush" , 0 , "A time duration to use when syncing data to persistent storage" )
2019-06-16 07:05:59 +00:00
startCmd . PersistentFlags ( ) . DurationVar ( & opts . DB . Proc . Shrink , "db-shrink" , 0 , "A time duration to use when shrinking data on persistent storage" )
2016-04-08 19:29:13 +00:00
2019-06-16 07:05:59 +00:00
startCmd . PersistentFlags ( ) . StringVar ( & opts . DB . Cert . CA , "kvs-ca" , "" , "Path to the CA file used to connect to the remote database" )
startCmd . PersistentFlags ( ) . StringVar ( & opts . DB . Cert . Crt , "kvs-crt" , "" , "Path to the certificate file used to connect to the remote database" )
startCmd . PersistentFlags ( ) . StringVar ( & opts . DB . Cert . Key , "kvs-key" , "" , "Path to the private key file used to connect to the remote database" )
2016-07-19 11:05:32 +00:00
2019-06-16 07:05:59 +00:00
startCmd . PersistentFlags ( ) . StringVar ( & opts . Cert . Crt , "web-crt" , "" , "Path to the server certificate. Needed when running in secure mode" )
startCmd . PersistentFlags ( ) . StringVar ( & opts . Cert . Key , "web-key" , "" , "Path to the server private key. Needed when running in secure mode" )
2016-04-08 19:29:13 +00:00
}