github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/cmd/platform/mattermost.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"errors"
     8  	"fmt"
     9  	"os"
    10  
    11  	"github.com/spf13/cobra"
    12  
    13  	// Plugins
    14  	_ "github.com/mattermost/mattermost-server/model/gitlab"
    15  
    16  	// Enterprise Imports
    17  	_ "github.com/mattermost/mattermost-server/imports"
    18  
    19  	// Enterprise Deps
    20  	_ "github.com/dgryski/dgoogauth"
    21  	_ "github.com/go-ldap/ldap"
    22  	_ "github.com/hashicorp/memberlist"
    23  	_ "github.com/mattermost/rsc/qr"
    24  	_ "github.com/prometheus/client_golang/prometheus"
    25  	_ "github.com/prometheus/client_golang/prometheus/promhttp"
    26  	_ "github.com/tylerb/graceful"
    27  	_ "gopkg.in/olivere/elastic.v5"
    28  
    29  	// Temp imports for new dependencies
    30  	_ "github.com/gorilla/schema"
    31  )
    32  
    33  func main() {
    34  	if err := rootCmd.Execute(); err != nil {
    35  		os.Exit(1)
    36  	}
    37  }
    38  
    39  func init() {
    40  	rootCmd.PersistentFlags().StringP("config", "c", "config.json", "Configuration file to use.")
    41  	rootCmd.PersistentFlags().Bool("disableconfigwatch", false, "When set config.json will not be loaded from disk when the file is changed.")
    42  
    43  	resetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
    44  
    45  	rootCmd.AddCommand(serverCmd, versionCmd, userCmd, teamCmd, licenseCmd, importCmd, resetCmd, channelCmd, rolesCmd, testCmd, ldapCmd, configCmd, jobserverCmd, commandCmd, messageExportCmd, sampleDataCmd)
    46  }
    47  
    48  var rootCmd = &cobra.Command{
    49  	Use:   "platform",
    50  	Short: "Open source, self-hosted Slack-alternative",
    51  	Long:  `Mattermost offers workplace messaging across web, PC and phones with archiving, search and integration with your existing systems. Documentation available at https://docs.mattermost.com`,
    52  	RunE:  runServerCmd,
    53  }
    54  
    55  var resetCmd = &cobra.Command{
    56  	Use:   "reset",
    57  	Short: "Reset the database to initial state",
    58  	Long:  "Completely erases the database causing the loss of all data. This will reset Mattermost to its initial state.",
    59  	RunE:  resetCmdF,
    60  }
    61  
    62  func resetCmdF(cmd *cobra.Command, args []string) error {
    63  	a, err := initDBCommandContextCobra(cmd)
    64  	if err != nil {
    65  		return err
    66  	}
    67  
    68  	confirmFlag, _ := cmd.Flags().GetBool("confirm")
    69  	if !confirmFlag {
    70  		var confirm string
    71  		CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
    72  		fmt.Scanln(&confirm)
    73  
    74  		if confirm != "YES" {
    75  			return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
    76  		}
    77  		CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ")
    78  		fmt.Scanln(&confirm)
    79  		if confirm != "YES" {
    80  			return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
    81  		}
    82  	}
    83  
    84  	a.Srv.Store.DropAllTables()
    85  	CommandPrettyPrintln("Database sucessfully reset")
    86  
    87  	return nil
    88  }