Add environmental variables
This commit is contained in:
parent
b0628d42d2
commit
1fc65d9506
|
@ -18,6 +18,8 @@ Then edit the configuration file `orion.conf` to your wishes and launch the prog
|
|||
|
||||
./orion -config orion.conf
|
||||
|
||||
`orion` can also be configured via [environmental variables](variables.md), which should be particularly useful for containerized applications.
|
||||
|
||||
### Create self-signed certificates
|
||||
|
||||
To create self-signed certificates for quick testing, you can use the following recipe
|
||||
|
@ -45,6 +47,8 @@ It's recommended to place your certificates in the `/conf` direcory and use the
|
|||
|
||||
Note: Use the `chroot` setting in containers for additional security.
|
||||
|
||||
See also the supported [environmental variables](variables.md) for additional configuration possibilities.
|
||||
|
||||
## Credits
|
||||
|
||||
* This project was inspired by the [titan2](https://gitlab.com/lostleonardo/titan2) minimalistic Gemini server written by lostleonardo.
|
||||
|
|
|
@ -27,6 +27,38 @@ func (cf *Config) SetDefaults() {
|
|||
cf.ContentDir = "gemini/"
|
||||
}
|
||||
|
||||
// getenv reads a given environmental variable and returns it's value if present or defval if not present or empty
|
||||
func getenv(key string, defval string) string {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
return defval
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func getenv_i(key string, defval int) int {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
return defval
|
||||
} else if ret, err := strconv.Atoi(val); err != nil {
|
||||
return defval
|
||||
} else {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
// Load environmental variables
|
||||
func (cf *Config) LoadEnv() {
|
||||
cf.Hostname = getenv("ORION_HOSTNAME", cf.Hostname)
|
||||
cf.CertFile = getenv("ORION_CERTFILE", cf.CertFile)
|
||||
cf.Keyfile = getenv("ORION_KEYFILE", cf.Keyfile)
|
||||
cf.BindAddr = getenv("ORION_BIND", cf.BindAddr)
|
||||
cf.ContentDir = getenv("ORION_CONTENTDIR", cf.ContentDir)
|
||||
cf.Chroot = getenv("ORION_CHROOT", cf.Chroot)
|
||||
cf.Uid = getenv_i("ORION_UID", cf.Uid)
|
||||
cf.Gid = getenv_i("ORION_UID", cf.Gid)
|
||||
}
|
||||
|
||||
func (cf *Config) LoadConfigFile(filename string) error {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
|
|
|
@ -74,6 +74,7 @@ func setgid(gid int) error {
|
|||
|
||||
func main() {
|
||||
config.SetDefaults()
|
||||
config.LoadEnv()
|
||||
|
||||
customConfigFile := flag.String("config", "", "Configuration file")
|
||||
flag.Parse()
|
||||
|
|
15
variables.md
Normal file
15
variables.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Environmental variables
|
||||
|
||||
|
||||
The following table lists all supported environmental variables for usage in `orion`. Environmental variables are in particular useful when working with `orion` as containerized application.
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| `ORION_HOSTNAME` | Server hostname to use |
|
||||
| `ORION_CERTFILE` | TLS certificate file |
|
||||
| `ORION_KEYFILE` | TLS key file |
|
||||
| `ORION_BIND` | Bind address for orion (e.g. `:1965`) |
|
||||
| `ORION_CONTENTDIR` | Content/data directory |
|
||||
| `ORION_CHROOT` | If set, orion will chroot into this directory |
|
||||
| `ORION_UID` | If set, orion will perform a setuid to this uid after initialization |
|
||||
| `ORION_GID` | If set, orion will perform a setgid to this gid after initialization |
|
Loading…
Reference in a new issue