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
 
34
 
35
 Run these commands in order -- these will setup each section of the server:
35
 Run these commands in order -- these will setup each section of the server:
36
 
36
 
37
-    $ oragono initdb
38
     $ oragono mkcerts
37
     $ oragono mkcerts
39
     $ oragono run
38
     $ oragono run
40
 
39
 

+ 0
- 1
README.md View File

43
 ```sh
43
 ```sh
44
 cp oragono.yaml ircd.yaml
44
 cp oragono.yaml ircd.yaml
45
 vim ircd.yaml  # modify the config file to your liking
45
 vim ircd.yaml  # modify the config file to your liking
46
-oragono initdb
47
 oragono mkcerts
46
 oragono mkcerts
48
 ```
47
 ```
49
 
48
 

+ 10
- 12
docs/MANUAL.md View File

78
 To get started with Oragono on Windows:
78
 To get started with Oragono on Windows:
79
 
79
 
80
 1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) downloaded.
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
 To start the server, type `oragono.exe run` and hit enter, and the server should start!
87
 To start the server, type `oragono.exe run` and hit enter, and the server should start!
89
 
88
 
93
 To get started with Oragono on macOS, Linux, or on a Raspberry Pi:
92
 To get started with Oragono on macOS, Linux, or on a Raspberry Pi:
94
 
93
 
95
 1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) for your OS/distro downloaded.
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
 To start the server, type `./oragono run` and hit enter, and the server should be ready to use!
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
 	return fmt.Sprintf("Database requires update. Expected schema v%s, got v%s", err.requiredVersion, err.currentVersion)
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
 func InitDB(path string) {
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
 	store, err := buntdb.Open(path)
72
 	store, err := buntdb.Open(path)
61
 	if err != nil {
73
 	if err != nil {
62
-		log.Fatal(fmt.Sprintf("Failed to open datastore: %s", err.Error()))
74
+		return err
63
 	}
75
 	}
64
 	defer store.Close()
76
 	defer store.Close()
65
 
77
 
69
 		return nil
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
 // OpenDatabase returns an existing database, performing a schema version check.
87
 // OpenDatabase returns an existing database, performing a schema version check.
81
 
91
 
82
 // open the database, giving it at most one chance to auto-upgrade the schema
92
 // open the database, giving it at most one chance to auto-upgrade the schema
83
 func openDatabaseInternal(config *Config, allowAutoupgrade bool) (db *buntdb.DB, err error) {
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
 	db, err = buntdb.Open(config.Datastore.Path)
94
 	db, err = buntdb.Open(config.Datastore.Path)
89
 	if err != nil {
95
 	if err != nil {
90
 		return
96
 		return

+ 12
- 3
irc/server.go View File

883
 	// open the datastore and load server state for which it (rather than config)
883
 	// open the datastore and load server state for which it (rather than config)
884
 	// is the source of truth
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
 	db, err := OpenDatabase(config)
895
 	db, err := OpenDatabase(config)
887
 	if err == nil {
896
 	if err == nil {
888
 		server.store = db
897
 		server.store = db
891
 	}
900
 	}
892
 
901
 
893
 	// load *lines (from the datastores)
902
 	// load *lines (from the datastores)
894
-	server.logger.Debug("startup", "Loading D/Klines")
903
+	server.logger.Debug("rehash", "Loading D/Klines")
895
 	server.loadDLines()
904
 	server.loadDLines()
896
 	server.loadKLines()
905
 	server.loadKLines()
897
 
906
 
963
 	}
972
 	}
964
 
973
 
965
 	if len(tlsListeners) == 0 {
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
 	var usesStandardTLSPort bool
978
 	var usesStandardTLSPort bool
974
 		}
983
 		}
975
 	}
984
 	}
976
 	if 0 < len(tlsListeners) && !usesStandardTLSPort {
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
 	return
989
 	return

+ 1
- 0
oragono.yaml View File

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

Loading…
Cancel
Save