Browse Source

Merge pull request #323 from slingamn/initdb.1

fix #322
tags/v1.0.0-rc1
Daniel Oaks 5 years ago
parent
commit
ea970f94a0
No account linked to committer's email address
6 changed files with 41 additions and 29 deletions
  1. 0
    1
      README
  2. 0
    1
      README.md
  3. 10
    12
      docs/MANUAL.md
  4. 18
    12
      irc/database.go
  5. 12
    3
      irc/server.go
  6. 1
    0
      oragono.yaml

+ 0
- 1
README View File

@@ -34,7 +34,6 @@ To generate passwords for opers and connect passwords, you can use this command:
34 34
 
35 35
 Run these commands in order -- these will setup each section of the server:
36 36
 
37
-    $ oragono initdb
38 37
     $ oragono mkcerts
39 38
     $ oragono run
40 39
 

+ 0
- 1
README.md View File

@@ -43,7 +43,6 @@ Extract it into a folder, then run the following commands:
43 43
 ```sh
44 44
 cp oragono.yaml ircd.yaml
45 45
 vim ircd.yaml  # modify the config file to your liking
46
-oragono initdb
47 46
 oragono mkcerts
48 47
 ```
49 48
 

+ 10
- 12
docs/MANUAL.md View File

@@ -78,12 +78,11 @@ In this section, we'll explain how to install and use the Oragono IRC server.
78 78
 To get started with Oragono on Windows:
79 79
 
80 80
 1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) downloaded.
81
-2. Extract the zip file to a folder.
82
-3. Copy and rename `oragono.yaml` to `ircd.yaml`.
83
-4. Open up `ircd.yaml` using any text editor, and then save it once you're happy.
84
-5. Open up a `cmd.exe` window, then `cd` to where you have Oragono extracted.
85
-6. Run `oragono.exe initdb` (this creates the database).
86
-7. Run `oragono.exe mkcerts` if you want to generate new self-signed SSL/TLS certificates (note that you can't enable STS if you use self-signed certs).
81
+1. Extract the zip file to a folder.
82
+1. Copy and rename `oragono.yaml` to `ircd.yaml`.
83
+1. Open up `ircd.yaml` using any text editor, and then save it once you're happy.
84
+1. Open up a `cmd.exe` window, then `cd` to where you have Oragono extracted.
85
+1. Run `oragono.exe mkcerts` if you want to generate new self-signed SSL/TLS certificates (note that you can't enable STS if you use self-signed certs).
87 86
 
88 87
 To start the server, type `oragono.exe run` and hit enter, and the server should start!
89 88
 
@@ -93,12 +92,11 @@ To start the server, type `oragono.exe run` and hit enter, and the server should
93 92
 To get started with Oragono on macOS, Linux, or on a Raspberry Pi:
94 93
 
95 94
 1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) for your OS/distro downloaded.
96
-2. Extract the tar.gz file to a folder.
97
-3. Copy and rename `oragono.yaml` to `ircd.yaml`.
98
-4. Open up `ircd.yaml` using any text editor, and then save it once you're happy.
99
-5. Open up a Terminal window, then `cd` to where you have Oragono extracted.
100
-6. Run `./oragono initdb` (this creates the database).
101
-7. Run `./oragono mkcerts` if you want to generate new self-signed SSL/TLS certificates (note that you can't enable STS if you use self-signed certs).
95
+1. Extract the tar.gz file to a folder.
96
+1. Copy and rename `oragono.yaml` to `ircd.yaml`.
97
+1. Open up `ircd.yaml` using any text editor, and then save it once you're happy.
98
+1. Open up a Terminal window, then `cd` to where you have Oragono extracted.
99
+1. Run `./oragono mkcerts` if you want to generate new self-signed SSL/TLS certificates (note that you can't enable STS if you use self-signed certs).
102 100
 
103 101
 To start the server, type `./oragono run` and hit enter, and the server should be ready to use!
104 102
 

+ 18
- 12
irc/database.go View File

@@ -52,14 +52,26 @@ func (err *incompatibleSchemaError) Error() string {
52 52
 	return fmt.Sprintf("Database requires update. Expected schema v%s, got v%s", err.requiredVersion, err.currentVersion)
53 53
 }
54 54
 
55
-// InitDB creates the database.
55
+// InitDB creates the database, implementing the `oragono initdb` command.
56 56
 func InitDB(path string) {
57
-	// prepare kvstore db
58
-	//TODO(dan): fail if already exists instead? don't want to overwrite good data
59
-	os.Remove(path)
57
+	_, err := os.Stat(path)
58
+	if err == nil {
59
+		log.Fatal("Datastore already exists (delete it manually to continue): ", path)
60
+	} else if !os.IsNotExist(err) {
61
+		log.Fatal("Datastore path is inaccessible: ", err.Error())
62
+	}
63
+
64
+	err = initializeDB(path)
65
+	if err != nil {
66
+		log.Fatal("Could not save datastore: ", err.Error())
67
+	}
68
+}
69
+
70
+// internal database initialization code
71
+func initializeDB(path string) error {
60 72
 	store, err := buntdb.Open(path)
61 73
 	if err != nil {
62
-		log.Fatal(fmt.Sprintf("Failed to open datastore: %s", err.Error()))
74
+		return err
63 75
 	}
64 76
 	defer store.Close()
65 77
 
@@ -69,9 +81,7 @@ func InitDB(path string) {
69 81
 		return nil
70 82
 	})
71 83
 
72
-	if err != nil {
73
-		log.Fatal("Could not save datastore:", err.Error())
74
-	}
84
+	return err
75 85
 }
76 86
 
77 87
 // OpenDatabase returns an existing database, performing a schema version check.
@@ -81,10 +91,6 @@ func OpenDatabase(config *Config) (*buntdb.DB, error) {
81 91
 
82 92
 // open the database, giving it at most one chance to auto-upgrade the schema
83 93
 func openDatabaseInternal(config *Config, allowAutoupgrade bool) (db *buntdb.DB, err error) {
84
-	_, err = os.Stat(config.Datastore.Path)
85
-	if os.IsNotExist(err) {
86
-		return
87
-	}
88 94
 	db, err = buntdb.Open(config.Datastore.Path)
89 95
 	if err != nil {
90 96
 		return

+ 12
- 3
irc/server.go View File

@@ -883,6 +883,15 @@ func (server *Server) loadDatastore(config *Config) error {
883 883
 	// open the datastore and load server state for which it (rather than config)
884 884
 	// is the source of truth
885 885
 
886
+	_, err := os.Stat(config.Datastore.Path)
887
+	if os.IsNotExist(err) {
888
+		server.logger.Warning("rehash", "database does not exist, creating it", config.Datastore.Path)
889
+		err = initializeDB(config.Datastore.Path)
890
+		if err != nil {
891
+			return err
892
+		}
893
+	}
894
+
886 895
 	db, err := OpenDatabase(config)
887 896
 	if err == nil {
888 897
 		server.store = db
@@ -891,7 +900,7 @@ func (server *Server) loadDatastore(config *Config) error {
891 900
 	}
892 901
 
893 902
 	// load *lines (from the datastores)
894
-	server.logger.Debug("startup", "Loading D/Klines")
903
+	server.logger.Debug("rehash", "Loading D/Klines")
895 904
 	server.loadDLines()
896 905
 	server.loadKLines()
897 906
 
@@ -963,7 +972,7 @@ func (server *Server) setupListeners(config *Config) (err error) {
963 972
 	}
964 973
 
965 974
 	if len(tlsListeners) == 0 {
966
-		server.logger.Warning("startup", "You are not exposing an SSL/TLS listening port. You should expose at least one port (typically 6697) to accept TLS connections")
975
+		server.logger.Warning("rehash", "You are not exposing an SSL/TLS listening port. You should expose at least one port (typically 6697) to accept TLS connections")
967 976
 	}
968 977
 
969 978
 	var usesStandardTLSPort bool
@@ -974,7 +983,7 @@ func (server *Server) setupListeners(config *Config) (err error) {
974 983
 		}
975 984
 	}
976 985
 	if 0 < len(tlsListeners) && !usesStandardTLSPort {
977
-		server.logger.Warning("startup", "Port 6697 is the standard TLS port for IRC. You should (also) expose port 6697 as a TLS port to ensure clients can connect securely")
986
+		server.logger.Warning("rehash", "Port 6697 is the standard TLS port for IRC. You should (also) expose port 6697 as a TLS port to ensure clients can connect securely")
978 987
 	}
979 988
 
980 989
 	return

+ 1
- 0
oragono.yaml View File

@@ -358,6 +358,7 @@ logging:
358 358
         #   commands        command calling and operations
359 359
         #   opers           oper actions, authentication, etc
360 360
         #   password        password hashing and comparing
361
+        #   rehash          server startup and rehash events
361 362
         #   userinput       raw lines sent by users
362 363
         #   useroutput      raw lines sent to users
363 364
         type: "* -userinput -useroutput -localconnect -localconnect-ip"

Loading…
Cancel
Save