[GH-ISSUE #93] PostgreSQL go driver #38

Closed
opened 2026-03-13 15:28:11 +03:00 by kerem · 8 comments
Owner

Originally created by @sh511 on GitHub (Jul 2, 2018).
Original GitHub issue: https://github.com/acme-dns/acme-dns/issues/93

I set up acme-dns as a service with an unprivileged acme-dns user. I edited the config file to use PostgreSQL and downloaded the pq driver for go. However, being new to go, I am at a lost about where to place the pq package. The command "go get githup/com/lib/pq" installs the river in ~/go by default but since acme-dns is shell-less, where does the package should be installed. The recommendation is to set the $GOPATH variable but I believe that this would not work for acme-dns.

The messages log file (on CENTOS) shows:
acme-dns: time="2018-06-27T22:36:18-04:00" level=error msg="Could not open database [sql: unknown driver "" (forgotten import?)]"

For go neophytes, an addition to the documentation would be greatly appreciated.

Originally created by @sh511 on GitHub (Jul 2, 2018). Original GitHub issue: https://github.com/acme-dns/acme-dns/issues/93 I set up acme-dns as a service with an unprivileged acme-dns user. I edited the config file to use PostgreSQL and downloaded the pq driver for go. However, being new to go, I am at a lost about where to place the pq package. The command "go get githup/com/lib/pq" installs the river in ~/go by default but since acme-dns is shell-less, where does the package should be installed. The recommendation is to set the $GOPATH variable but I believe that this would not work for acme-dns. The messages log file (on CENTOS) shows: acme-dns: time="2018-06-27T22:36:18-04:00" level=error msg="Could not open database [sql: unknown driver \"\" (forgotten import?)]" For go neophytes, an addition to the documentation would be greatly appreciated.
kerem 2026-03-13 15:28:11 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@joohoi commented on GitHub (Jul 3, 2018):

The PgSQL driver is baked in the acme-dns itself, so there's no need to install your own. Your issue seems to be that the database engine option in the config file seems to be empty (or commented out):

It should be:

...
[database]
# Database engine to use, sqlite3 or postgres
engine = "postgres"
...
<!-- gh-comment-id:402092630 --> @joohoi commented on GitHub (Jul 3, 2018): The PgSQL driver is baked in the acme-dns itself, so there's no need to install your own. Your issue seems to be that the database engine option in the config file seems to be empty (or commented out): It should be: ``` ... [database] # Database engine to use, sqlite3 or postgres engine = "postgres" ... ```
Author
Owner

@sh511 commented on GitHub (Jul 4, 2018):

Thank you for pointing out that the driver is embedded in the binary. I forgot to check under the vendor folder.

Regarding my config.cfg file I do have engine="postgres" specified. The file is in /etc/acme-dns and owned by acme-dns:acme-dns as per service file.

I get the same error if I run acme-dns directly

INFO[0000] Using config file file=/etc/acme-dns/config.cfg
ERRO[0000] Could not open database [sql: unknown driver "" (forgotten import?)]

Actually it does not matter what string I use in the config file, even
engine = "nonsense"
I get the same error unknown driver "" (i.e. empty string).

Completely confused ...

<!-- gh-comment-id:402345262 --> @sh511 commented on GitHub (Jul 4, 2018): Thank you for pointing out that the driver is embedded in the binary. I forgot to check under the vendor folder. Regarding my config.cfg file I do have engine="postgres" specified. The file is in /etc/acme-dns and owned by acme-dns:acme-dns as per service file. I get the same error if I run acme-dns directly INFO[0000] Using config file file=/etc/acme-dns/config.cfg ERRO[0000] Could not open database [sql: unknown driver "" (forgotten import?)] Actually it does not matter what string I use in the config file, even engine = "nonsense" I get the same error unknown driver "" (i.e. empty string). Completely confused ...
Author
Owner

@joohoi commented on GitHub (Jul 4, 2018):

The error message implies that the engine value within [database] block couldn't be read for some reason. I wonder if you might have commented the [database] block out or something? Anyway acme-dns is unable to read the value of engine configuration variable for reason or another.

<!-- gh-comment-id:402487006 --> @joohoi commented on GitHub (Jul 4, 2018): The error message implies that the `engine` value within `[database]` block couldn't be read for some reason. I wonder if you might have commented the `[database]` block out or something? Anyway acme-dns is unable to read the value of `engine` configuration variable for reason or another.
Author
Owner

@sh511 commented on GitHub (Jul 6, 2018):

After learning how to get around in GOLANG, I tracked down the issue. I had left out the quotes around the ip parameters. Since util.go does not check for errors in toml.DecodeFile, because it "Practically never errors" 8-), the error was not caught and no parameters was returned in Config then resulting in the "" driver error. So I would suggest not to assume that users will not make an error while editing the config file.

Also, if the permissions are not set properly on the config file, the os.Stat check in fileExists will not flag a file that exists but cannot be read. Using os.Open and checking for an error is more reliable (then closing the file is there is no error). There might be a more GOLANG way of doing the same.

<!-- gh-comment-id:402906927 --> @sh511 commented on GitHub (Jul 6, 2018): After learning how to get around in GOLANG, I tracked down the issue. I had left out the quotes around the ip parameters. Since util.go does not check for errors in toml.DecodeFile, because it "Practically never errors" 8-), the error was not caught and no parameters was returned in Config then resulting in the "" driver error. So I would suggest not to assume that users will not make an error while editing the config file. Also, if the permissions are not set properly on the config file, the os.Stat check in fileExists will not flag a file that exists but cannot be read. Using os.Open and checking for an error is more reliable (then closing the file is there is no error). There might be a more GOLANG way of doing the same.
Author
Owner

@joohoi commented on GitHub (Jul 6, 2018):

Ah, most awesome that you got it to work!

Since util.go does not check for errors in toml.DecodeFile, because it "Practically never errors" 8-),

Burn! I'm very sorry that the sloppy error handling did bite you :/

This definitely is a bug, and should get fixed. As you dug into the code already, would you like to submit a PR to fix the issue? If not, I'll do it.

<!-- gh-comment-id:402991739 --> @joohoi commented on GitHub (Jul 6, 2018): Ah, most awesome that you got it to work! > Since util.go does not check for errors in toml.DecodeFile, because it "Practically never errors" 8-), Burn! I'm very sorry that the sloppy error handling did bite you :/ This definitely is a bug, and should get fixed. As you dug into the code already, would you like to submit a PR to fix the issue? If not, I'll do it.
Author
Owner

@sh511 commented on GitHub (Jul 14, 2018):

Finally got around submitting a PR. Just did a bit more testing not to introduce new features. I think that the documentation should direct the user to always place the configuration file in /etc/acme-dns/ if running as a service and non-privileged user acme-dns. I am not sure what the "current" directory is for a service.

Also regarding the configuration file, I would suggest including the ip:port option and not only the :port option for listen, e.g.

Edit the following line to the ip address that acme-dns is listening to

#listen = "198.51.100.1:53"

If acme-dns is listening to all addresses on the server, use

listen = ":53"

Since I am running acme-dns along the "main" DNS server, I needed to specify separate IP addresses to listen to. Rather obvious in retrospect but a note in the configuration file would be useful.

<!-- gh-comment-id:405030165 --> @sh511 commented on GitHub (Jul 14, 2018): Finally got around submitting a PR. Just did a bit more testing not to introduce new features. I think that the documentation should direct the user to always place the configuration file in /etc/acme-dns/ if running as a service and non-privileged user acme-dns. I am not sure what the "current" directory is for a service. Also regarding the configuration file, I would suggest including the ip:port option and not only the :port option for listen, e.g. # Edit the following line to the ip address that acme-dns is listening to #listen = "198.51.100.1:53" # If acme-dns is listening to all addresses on the server, use listen = ":53" Since I am running acme-dns along the "main" DNS server, I needed to specify separate IP addresses to listen to. Rather obvious in retrospect but a note in the configuration file would be useful.
Author
Owner

@LinuxCuba commented on GitHub (Aug 9, 2018):

This is my conf referent to database
[database]

Database engine to use, sqlite3 or postgres

engine = "sqlite3"

Connection string, filename for sqlite3 and postgres://$username:$password@$host/$db_name for postgres

connection = "/var/lib/acme-dns/acme-dns.db"
The problem is persistent

<!-- gh-comment-id:411833525 --> @LinuxCuba commented on GitHub (Aug 9, 2018): This is my conf referent to database [database] # Database engine to use, sqlite3 or postgres engine = "sqlite3" # Connection string, filename for sqlite3 and postgres://$username:$password@$host/$db_name for postgres connection = "/var/lib/acme-dns/acme-dns.db" The problem is persistent
Author
Owner

@joohoi commented on GitHub (Aug 12, 2018):

The error messages should be a lot better now when #99 and #101 have landed to reveal the underlying issue.

<!-- gh-comment-id:412357785 --> @joohoi commented on GitHub (Aug 12, 2018): The error messages should be a lot better now when #99 and #101 have landed to reveal the underlying issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/acme-dns#38
No description provided.