3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Merge pull request #323 from slingamn/initdb.1

fix #322
This commit is contained in:
Daniel Oaks 2019-01-03 09:18:19 +10:00 committed by GitHub
commit ea970f94a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 29 deletions

1
README
View File

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

View File

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

View File

@ -78,12 +78,11 @@ In this section, we'll explain how to install and use the Oragono IRC server.
To get started with Oragono on Windows: To get started with Oragono on Windows:
1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) downloaded. 1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) downloaded.
2. Extract the zip file to a folder. 1. Extract the zip file to a folder.
3. Copy and rename `oragono.yaml` to `ircd.yaml`. 1. Copy and rename `oragono.yaml` to `ircd.yaml`.
4. Open up `ircd.yaml` using any text editor, and then save it once you're happy. 1. Open up `ircd.yaml` using any text editor, and then save it once you're happy.
5. Open up a `cmd.exe` window, then `cd` to where you have Oragono extracted. 1. Open up a `cmd.exe` window, then `cd` to where you have Oragono extracted.
6. Run `oragono.exe initdb` (this creates the database). 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).
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).
To start the server, type `oragono.exe run` and hit enter, and the server should start! To start the server, type `oragono.exe run` and hit enter, and the server should start!
@ -93,12 +92,11 @@ To start the server, type `oragono.exe run` and hit enter, and the server should
To get started with Oragono on macOS, Linux, or on a Raspberry Pi: To get started with Oragono on macOS, Linux, or on a Raspberry Pi:
1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) for your OS/distro downloaded. 1. Make sure you have the [latest release](https://github.com/oragono/oragono/releases/latest) for your OS/distro downloaded.
2. Extract the tar.gz file to a folder. 1. Extract the tar.gz file to a folder.
3. Copy and rename `oragono.yaml` to `ircd.yaml`. 1. Copy and rename `oragono.yaml` to `ircd.yaml`.
4. Open up `ircd.yaml` using any text editor, and then save it once you're happy. 1. Open up `ircd.yaml` using any text editor, and then save it once you're happy.
5. Open up a Terminal window, then `cd` to where you have Oragono extracted. 1. Open up a Terminal window, then `cd` to where you have Oragono extracted.
6. Run `./oragono initdb` (this creates the database). 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).
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).
To start the server, type `./oragono run` and hit enter, and the server should be ready to use! To start the server, type `./oragono run` and hit enter, and the server should be ready to use!

View File

@ -52,14 +52,26 @@ func (err *incompatibleSchemaError) Error() string {
return fmt.Sprintf("Database requires update. Expected schema v%s, got v%s", err.requiredVersion, err.currentVersion) return fmt.Sprintf("Database requires update. Expected schema v%s, got v%s", err.requiredVersion, err.currentVersion)
} }
// InitDB creates the database. // InitDB creates the database, implementing the `oragono initdb` command.
func InitDB(path string) { func InitDB(path string) {
// prepare kvstore db _, err := os.Stat(path)
//TODO(dan): fail if already exists instead? don't want to overwrite good data if err == nil {
os.Remove(path) log.Fatal("Datastore already exists (delete it manually to continue): ", path)
} else if !os.IsNotExist(err) {
log.Fatal("Datastore path is inaccessible: ", err.Error())
}
err = initializeDB(path)
if err != nil {
log.Fatal("Could not save datastore: ", err.Error())
}
}
// internal database initialization code
func initializeDB(path string) error {
store, err := buntdb.Open(path) store, err := buntdb.Open(path)
if err != nil { if err != nil {
log.Fatal(fmt.Sprintf("Failed to open datastore: %s", err.Error())) return err
} }
defer store.Close() defer store.Close()
@ -69,9 +81,7 @@ func InitDB(path string) {
return nil return nil
}) })
if err != nil { return err
log.Fatal("Could not save datastore:", err.Error())
}
} }
// OpenDatabase returns an existing database, performing a schema version check. // OpenDatabase returns an existing database, performing a schema version check.
@ -81,10 +91,6 @@ func OpenDatabase(config *Config) (*buntdb.DB, error) {
// open the database, giving it at most one chance to auto-upgrade the schema // open the database, giving it at most one chance to auto-upgrade the schema
func openDatabaseInternal(config *Config, allowAutoupgrade bool) (db *buntdb.DB, err error) { func openDatabaseInternal(config *Config, allowAutoupgrade bool) (db *buntdb.DB, err error) {
_, err = os.Stat(config.Datastore.Path)
if os.IsNotExist(err) {
return
}
db, err = buntdb.Open(config.Datastore.Path) db, err = buntdb.Open(config.Datastore.Path)
if err != nil { if err != nil {
return return

View File

@ -883,6 +883,15 @@ func (server *Server) loadDatastore(config *Config) error {
// open the datastore and load server state for which it (rather than config) // open the datastore and load server state for which it (rather than config)
// is the source of truth // is the source of truth
_, err := os.Stat(config.Datastore.Path)
if os.IsNotExist(err) {
server.logger.Warning("rehash", "database does not exist, creating it", config.Datastore.Path)
err = initializeDB(config.Datastore.Path)
if err != nil {
return err
}
}
db, err := OpenDatabase(config) db, err := OpenDatabase(config)
if err == nil { if err == nil {
server.store = db server.store = db
@ -891,7 +900,7 @@ func (server *Server) loadDatastore(config *Config) error {
} }
// load *lines (from the datastores) // load *lines (from the datastores)
server.logger.Debug("startup", "Loading D/Klines") server.logger.Debug("rehash", "Loading D/Klines")
server.loadDLines() server.loadDLines()
server.loadKLines() server.loadKLines()
@ -963,7 +972,7 @@ func (server *Server) setupListeners(config *Config) (err error) {
} }
if len(tlsListeners) == 0 { if len(tlsListeners) == 0 {
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") 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")
} }
var usesStandardTLSPort bool var usesStandardTLSPort bool
@ -974,7 +983,7 @@ func (server *Server) setupListeners(config *Config) (err error) {
} }
} }
if 0 < len(tlsListeners) && !usesStandardTLSPort { if 0 < len(tlsListeners) && !usesStandardTLSPort {
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") 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")
} }
return return

View File

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