pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 470 forks source link

Doesn't parse environment variables in conf file #1105

Closed SteveRedka closed 5 years ago

SteveRedka commented 6 years ago

In my sphinx.conf file I have this:

  sql_user = $MYSQL_USER
  sql_pass = $MYSQL_PASSWORD

And it is a recommended way to handle environment variables by sphinx documentation.

When I run tasks through sphinx alone, it works fine. However, when I run it through app, it passes variables as plain text:

2018-07-20T11:58:24.684680Z 21 [Note] Access denied for user '$MYSQL_USER'@'172.17.0.5' (using password: YES)
pat commented 6 years ago

I know it's been a couple of months, but I've not forgotten about this issue. Hoping to get to it soon, it's just that it might require some behaviour changes for Riddle rather than TS.

pat commented 6 years ago

Finally making some time to look into this, and wishing I'd responded far more quickly.

Firstly: did you find a way of making this work?

My initial investigation suggested that Rails itself is not set up to use environment variables like this in the config/database.yml file, so as a workaround I added sql_host: $SQL_HOST to my config/thinking_sphinx.yml file in the appropriate environment. This ensured the Sphinx configuration file was generated accordingly.

However, even when I invoke indexing directly with Sphinx (e.g. SQL_USER=root indexer --config config/development.sphinx.conf --rotate --all) it doesn't work:

ERROR: index 'article_core': sql_connect: Access denied for user '$SQL_USER'@'localhost' (using password: NO)

Did you find the behaviour was different? And if so, which version of Sphinx are you using?

SteveRedka commented 6 years ago

Yes, I made it work. I just forgot to add a shebang string to make it a bash executable.

So, now sphinx.conf looks like this:

#!/bin/bash

printf "

...

  sql_user = $MYSQL_USER
  sql_pass = $MYSQL_PASSWORD

...

"
pat commented 6 years ago

Ah, and you have to make that change after every regeneration of the Sphinx configuration file?

pat commented 5 years ago

I'm going to close this issue as it's been dormant for a while. Certainly if there's more to discuss, chime in anyway!