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