~emersion/soju-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 2

[PATCH] Check for configuration in /etc/soju/config

Details
Message ID
<20210525135708.291405-1-philipk@posteo.net>
DKIM signature
pass
Download raw message
Patch: +22 -10
If no configuration path was specified, check if /etc/soju/config
exists before using the default configuration.
---
 cmd/soju/main.go    | 16 +++++++++++-----
 cmd/sojuctl/main.go | 16 +++++++++++-----
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/cmd/soju/main.go b/cmd/soju/main.go
index f7f8a42..5f94e2e 100644
--- a/cmd/soju/main.go
+++ b/cmd/soju/main.go
@@ -46,14 +46,20 @@ func main() {
	flag.Parse()

	var cfg *config.Server
	var err error
	if configPath != "" {
		var err error
		cfg, err = config.Load(configPath)
		if err != nil {
			log.Fatalf("failed to load config file: %v", err)
		}
	} else {
		cfg = config.Defaults()
		configPath = `/etc/soju/config`
		_, err = os.Stat(configPath)
		if os.IsNotExist(err) {
			cfg = config.Defaults()
		} else if err == nil {
			cfg, err = config.Load(configPath)
		}
	}
	if err != nil {
		log.Fatalf("failed to load config file: %v", err)
	}

	cfg.Listen = append(cfg.Listen, listen...)
diff --git a/cmd/sojuctl/main.go b/cmd/sojuctl/main.go
index 730832c..e290914 100644
--- a/cmd/sojuctl/main.go
+++ b/cmd/sojuctl/main.go
@@ -33,14 +33,20 @@ func main() {
	flag.Parse()

	var cfg *config.Server
	var err error
	if configPath != "" {
		var err error
		cfg, err = config.Load(configPath)
		if err != nil {
			log.Fatalf("failed to load config file: %v", err)
		}
	} else {
		cfg = config.Defaults()
		configPath = `/etc/soju/config`
		_, err = os.Stat(configPath)
		if os.IsNotExist(err) {
			cfg = config.Defaults()
		} else if err == nil {
			cfg, err = config.Load(configPath)
		}
	}
	if err != nil {
		log.Fatalf("failed to load config file: %v", err)
	}

	db, err := soju.OpenSQLDB(cfg.SQLDriver, cfg.SQLSource)
-- 
2.30.2
Details
Message ID
<tRB-u0tx8553EN2TN_dm18lEJLO__zDwVpAzLmt3qey93x04tTYX-dP6if-tqG30yUJ7mtaGzrASRcHCpF7aL2Vxwc9In24Af5OJjf3gtkA=@emersion.fr>
In-Reply-To
<20210525135708.291405-1-philipk@posteo.net> (view parent)
DKIM signature
pass
Download raw message
Sorry, I've decided against this approach, and instead let the service
specify `-config /etc/soju/config`.
Details
Message ID
<87fsyasydb.fsf@icterid>
In-Reply-To
<tRB-u0tx8553EN2TN_dm18lEJLO__zDwVpAzLmt3qey93x04tTYX-dP6if-tqG30yUJ7mtaGzrASRcHCpF7aL2Vxwc9In24Af5OJjf3gtkA=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
Simon Ser <contact@emersion.fr> writes:

> Sorry, I've decided against this approach, and instead let the service
> specify `-config /etc/soju/config`.

Hmm, ok. The reason I proposed this was because the Makefile made it
seems as though /etc/soju/config was checked by default, and I was
surprised to see that it was not the case, despite the docs saying

    *-config* <path>
            Path to the config file. If unset, a default config file is used.

-- 
	Philip K.
Details
Message ID
<D6ktgLMbmq91twSjhtEjIZYB-V6zQ-FIzUyzaVAHiqlrXAt2JvLX5nyOQN8roWZRl5wrGXDs7sdW6_HhVMaloZr3-5ZB9cSquFE-tKS9WNI=@emersion.fr>
In-Reply-To
<87fsyasydb.fsf@icterid> (view parent)
DKIM signature
pass
Download raw message
On Tuesday, May 25th, 2021 at 4:04 PM, Philip Kaludercic <philipk@posteo.net> wrote:

> Simon Ser contact@emersion.fr writes:
>
> > Sorry, I've decided against this approach, and instead let the service
> > specify `-config /etc/soju/config`.
>
> Hmm, ok. The reason I proposed this was because the Makefile made it
> seems as though /etc/soju/config was checked by default, and I was
> surprised to see that it was not the case, despite the docs saying
>
> -config <path>
>             Path to the config file. If unset, a default config file is used.

Right. The motivation here is that I still want to make it easy for
people to try out soju with a simple command like:

    soju -listen irc+insecure://127.0.0.1:6667

If /etc/soju/config is read by default things won't be as nice,
because the default system-wide config wants write access to
/var/lib/soju.

Additionally, I'd like to fail hard if something goes wrong. If the
user intends to load the system-wide config and it's missing, I don't
want to silently ignore the error.

I'm open to ideas to improve all of this.
Details
Message ID
<87im36hmx5.fsf@icterid>
In-Reply-To
<D6ktgLMbmq91twSjhtEjIZYB-V6zQ-FIzUyzaVAHiqlrXAt2JvLX5nyOQN8roWZRl5wrGXDs7sdW6_HhVMaloZr3-5ZB9cSquFE-tKS9WNI=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
Simon Ser <contact@emersion.fr> writes:

> On Tuesday, May 25th, 2021 at 4:04 PM, Philip Kaludercic <philipk@posteo.net> wrote:
>
>> Simon Ser contact@emersion.fr writes:
>>
>> > Sorry, I've decided against this approach, and instead let the service
>> > specify `-config /etc/soju/config`.
>>
>> Hmm, ok. The reason I proposed this was because the Makefile made it
>> seems as though /etc/soju/config was checked by default, and I was
>> surprised to see that it was not the case, despite the docs saying
>>
>> -config <path>
>>             Path to the config file. If unset, a default config file is used.
>
> Right. The motivation here is that I still want to make it easy for
> people to try out soju with a simple command like:
>
>     soju -listen irc+insecure://127.0.0.1:6667
>
> If /etc/soju/config is read by default things won't be as nice,
> because the default system-wide config wants write access to
> /var/lib/soju.
>
> Additionally, I'd like to fail hard if something goes wrong. If the
> user intends to load the system-wide config and it's missing, I don't
> want to silently ignore the error.
>
> I'm open to ideas to improve all of this.

I understand the issue you are describing, but am not sure how to fix it
either... I'll try to think about it.

-- 
	Philip K.
Reply to thread Export thread (mbox)