mirror of https://github.com/statping/statping
exit 0 for non processing commands
parent
73d7a65c39
commit
fcb448ab56
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
@ -23,6 +24,7 @@ var versionCmd = &cobra.Command{
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s\n", VERSION)
|
fmt.Printf("%s\n", VERSION)
|
||||||
}
|
}
|
||||||
|
os.Exit(0)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +32,11 @@ var assetsCmd = &cobra.Command{
|
||||||
Use: "assets",
|
Use: "assets",
|
||||||
Short: "Dump all assets used locally to be edited",
|
Short: "Dump all assets used locally to be edited",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return assetsCli()
|
if err := assetsCli(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +44,11 @@ var exportCmd = &cobra.Command{
|
||||||
Use: "export",
|
Use: "export",
|
||||||
Short: "Exports your Statping settings to a 'statping-export.json' file.",
|
Short: "Exports your Statping settings to a 'statping-export.json' file.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return exportCli(args)
|
if err := exportCli(args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +56,11 @@ var sassCmd = &cobra.Command{
|
||||||
Use: "sass",
|
Use: "sass",
|
||||||
Short: "Compile .scss files into the css directory",
|
Short: "Compile .scss files into the css directory",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return sassCli()
|
if err := sassCli(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +68,11 @@ var envCmd = &cobra.Command{
|
||||||
Use: "env",
|
Use: "env",
|
||||||
Short: "Return the configs that will be ran",
|
Short: "Return the configs that will be ran",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return envCli()
|
if err := envCli(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +80,11 @@ var resetCmd = &cobra.Command{
|
||||||
Use: "reset",
|
Use: "reset",
|
||||||
Short: "Start a fresh copy of Statping",
|
Short: "Start a fresh copy of Statping",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return resetCli()
|
if err := resetCli(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +92,11 @@ var onceCmd = &cobra.Command{
|
||||||
Use: "once",
|
Use: "once",
|
||||||
Short: "Check all services 1 time and then quit",
|
Short: "Check all services 1 time and then quit",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return onceCli()
|
if err := onceCli(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +104,11 @@ var importCmd = &cobra.Command{
|
||||||
Use: "import [.json file]",
|
Use: "import [.json file]",
|
||||||
Short: "Imports settings from a previously saved JSON file.",
|
Short: "Imports settings from a previously saved JSON file.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return importCli(args)
|
if err := importCli(args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
|
|
18
cmd/main.go
18
cmd/main.go
|
@ -23,11 +23,11 @@ var (
|
||||||
COMMIT string
|
COMMIT string
|
||||||
log = utils.Log.WithField("type", "cmd")
|
log = utils.Log.WithField("type", "cmd")
|
||||||
confgs *configs.DbConfig
|
confgs *configs.DbConfig
|
||||||
process chan struct{}
|
stopped chan bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
process = make(chan struct{})
|
stopped = make(chan bool, 1)
|
||||||
core.New(VERSION)
|
core.New(VERSION)
|
||||||
utils.InitEnvs()
|
utils.InitEnvs()
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func init() {
|
||||||
func exit(err error) {
|
func exit(err error) {
|
||||||
utils.SentryErr(err)
|
utils.SentryErr(err)
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
close(process)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close will gracefully stop the database connection, and log file
|
// Close will gracefully stop the database connection, and log file
|
||||||
|
@ -59,9 +59,8 @@ func Close() {
|
||||||
|
|
||||||
// main will run the Statping application
|
// main will run the Statping application
|
||||||
func main() {
|
func main() {
|
||||||
utils.InitLogs()
|
|
||||||
go Execute()
|
go Execute()
|
||||||
<-process
|
<-stopped
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +145,7 @@ func sigterm() {
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-sigs
|
<-sigs
|
||||||
close(process)
|
stopped <- true
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mainProcess will initialize the Statping application and run the HTTP server
|
// mainProcess will initialize the Statping application and run the HTTP server
|
||||||
|
@ -169,15 +167,21 @@ func mainProcess() error {
|
||||||
// This function will gather all services in database, add/init Notifiers,
|
// This function will gather all services in database, add/init Notifiers,
|
||||||
// and start the database cleanup routine
|
// and start the database cleanup routine
|
||||||
func InitApp() error {
|
func InitApp() error {
|
||||||
|
// fetch Core row information about this instance.
|
||||||
if _, err := core.Select(); err != nil {
|
if _, err := core.Select(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// select all services in database and store services in a mapping of Service pointers
|
||||||
if _, err := services.SelectAllServices(true); err != nil {
|
if _, err := services.SelectAllServices(true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// start routines for each service checking process
|
||||||
services.CheckServices()
|
services.CheckServices()
|
||||||
|
// connect each notifier, added them into database if needed
|
||||||
notifiers.InitNotifiers()
|
notifiers.InitNotifiers()
|
||||||
|
// start routine to delete old records (failures, hits)
|
||||||
go database.Maintenance()
|
go database.Maintenance()
|
||||||
|
// init Sentry error monitoring (its useful)
|
||||||
utils.SentryInit(&VERSION, core.App.AllowReports.Bool)
|
utils.SentryInit(&VERSION, core.App.AllowReports.Bool)
|
||||||
core.App.Setup = true
|
core.App.Setup = true
|
||||||
core.App.Started = utils.Now()
|
core.App.Started = utils.Now()
|
||||||
|
|
10
install.sh
10
install.sh
|
@ -34,11 +34,9 @@ statping_get_tarball() {
|
||||||
fi
|
fi
|
||||||
printf "$green> Installing to $DEST/statping\n"
|
printf "$green> Installing to $DEST/statping\n"
|
||||||
mv "$temp"/statping "$DEST"
|
mv "$temp"/statping "$DEST"
|
||||||
newversion=`$DEST/statping version`
|
|
||||||
rm -rf "$temp"
|
rm -rf "$temp"
|
||||||
rm $tarball_tmp*
|
rm $tarball_tmp*
|
||||||
printf "$cyan> Statping is now installed! $reset\n"
|
printf "$cyan> Statping is now installed! $reset\n"
|
||||||
printf "$white> Version: $newversion $reset\n"
|
|
||||||
printf "$white> Repo: $repo $reset\n"
|
printf "$white> Repo: $repo $reset\n"
|
||||||
printf "$white> Wiki: $repo/wiki $reset\n"
|
printf "$white> Wiki: $repo/wiki $reset\n"
|
||||||
printf "$white> Issues: $repo/issues $reset\n"
|
printf "$white> Issues: $repo/issues $reset\n"
|
||||||
|
@ -71,11 +69,7 @@ statping_install() {
|
||||||
printf "${white}Installing Statping!$reset\n"
|
printf "${white}Installing Statping!$reset\n"
|
||||||
getOS
|
getOS
|
||||||
getArch
|
getArch
|
||||||
if [ "$OS" == "darwin" ]; then
|
statping_get_tarball $OS $ARCH
|
||||||
statping_brew_install
|
|
||||||
else
|
|
||||||
statping_get_tarball $OS $ARCH
|
|
||||||
fi
|
|
||||||
statping_reset
|
statping_reset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +134,7 @@ getArch() {
|
||||||
ARCH="amd64"
|
ARCH="amd64"
|
||||||
elif [ ${MACHINE_TYPE} == 'arm' ]; then
|
elif [ ${MACHINE_TYPE} == 'arm' ]; then
|
||||||
ARCH="arm"
|
ARCH="arm"
|
||||||
elif [ ${MACHINE_TYPE} == 'arm64' ] || [ ${MACHINE_TYPE} == 'aarch64' ] || [ ${MACHINE_TYPE} == 'armv8b' ] || [ ${MACHINE_TYPE} == 'armv8l' ] || [ ${MACHINE_TYPE} == 'aarch64_be' ]; then
|
elif [ ${MACHINE_TYPE} == 'arm64' ]; then
|
||||||
ARCH="arm64"
|
ARCH="arm64"
|
||||||
else
|
else
|
||||||
ARCH="386"
|
ARCH="386"
|
||||||
|
|
Loading…
Reference in New Issue