MySQL RouterでFabric Cacheプラグインを使うのがつらい

手元の環境はMySQL Router 2.0.3

なにがあったか

MySQL Fabricと一緒に使おうとMySQL RouterのFabric Cacheプラグインを有効にすると起動時に必ずMySQL Fabricのxmlrpcのパスワードを標準入力で聞いてくる。 設定ファイル上で設定する手段は提供されていないようにみえる。 コード上でもパスワードを回避するようなオプションはなさそうなところまでは確認した。

:mysql-router-2.0.3/src/fabric_cache/src/fabric_cache_plugin.cc

static int init(const AppInfo *info) {
  g_app_info = info;

  if (info && info->config) {

    if (info->config->get(kSectionName).size() > 1) {
      throw std::invalid_argument("Router supports only 1 fabric_cache section.");
    }

    for (auto &section: info->config->get(kSectionName)) {
      FabricCachePluginConfig config(section); // raises on errors
      fabric_cache::g_fabric_cache_config_sections.push_back(section->key);

      if (section->has("password")) {
        throw std::invalid_argument(
            "'password' option is not allowed in the configuration file. "
                "Router will prompt for password instead.");
      }

      auto password_key = make_cache_password(config.address, section->get("user"));
      if (have_cache_password(password_key)) {
        // we got the password already for this address and user
        continue;
      }
      // we need to prompt for the password
      auto prompt = mysqlrouter::string_format("Password for [%s%s%s], user %s",
                                               section->name.c_str(),
                                               section->key.empty() ? "" : ":",
                                               section->key.c_str(), config.user.c_str());
      auto password = prompt_password(prompt);
      fabric_cache_passwords.emplace(std::make_pair(password_key, password));
    }
  }

  return 0;
}

バックグラウンド起動しようとすると標準入力が切られるのでここで失敗して動作しない。 また、いやなことにrpmに同梱してあるsystemd向けのmysqlrouter.serviceも同様の問題を抱えている。

どう対応したか

標準入力から受けつける口しか用意していないのならば、標準入力から渡すしかない。 つまりこうなる。

:/etc/mysqlrouter/fabric_password

password
:/usr/lib/systemd/system/mysqlrouter.service

[Unit]
Description=MySQL Router
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql

PIDFile=/var/run/mysqlrouter/mysqlrouter.pid

ExecStart=/bin/sh -c 'cat /etc/mysqlrouter/fabric_password | /usr/sbin/mysqlrouter'

PrivateTmp=true

[Install]
WantedBy=multi-user.target