LoginSignup
13
13

More than 5 years have passed since last update.

Chefでsupervisorのレシピを適用する時、デフォルトのreloadは全てのプロセスを再起動してしまうので注意

Last updated at Posted at 2013-11-14

※ fluentd自体は問題ではありません。が、supervisorを使って複数のプロセスを管理していると起こりえる問題です。

Chefを使ったProvisioningで初回の起動時にsupervisorで動かしているfluentdのプロセスが多重起動してしまう事があったのでメモ。

起こった現象

以前のレシピ

site-cookbooks/supervisord/recipes/default.rb
template "supervisord.conf" do
    path "/etc/supervisord.conf"
    source "supervisord.conf.erb"
    owner "root"
    group "root"
    mode "0644"
end

service "supervisord" do
    supports :status => true, :restart => true, :reload => true
    action [ :enable, :start ]
    subscribes :reload, "template[supervisord.conf]"
end

上記レシピでは最初の起動時にsupervisorがstartした直後(fluentdが起動し終わる前に)reloadが実行されfluentdが多重起動してしまいます。

このように対応しました

  • reload_commandを定義してデフォルトのreloadでなくsupervisorctl updateを使うようにしました。

変更後のレシピ

site-cookbooks/supervisord/recipes/default.rb
template "supervisord.conf" do
    path "/etc/supervisord.conf"
    source "supervisord.conf.erb"
    owner "root"
    group "root"
    mode "0644"
    notifies :reload, "service[supervisord]", :delayed
end

service "supervisord" do
    supports :status => true, :restart => false, :reload => true
    reload_command "supervisorctl update"
    action [:enable, :start]
end

/etc/init.d/supervisordのuploadでなくsupervisorctl updateが実行するようになるので、fluentdのプロセスが多重に起動されることはなくなりました。

/etc/init.d/supervisordのuploadとsupervisorctl updateにはどういう違いがあるのか?

/etc/init.d/supervisordのuploadはHUPのシグナルを送っているようです。

/etc/init.d/supervisord
reload()
{
        echo -n $"Reloading $prog: "
        if [ -n "`pidfileofproc $SUPERVISORD`" ] ; then
            killproc $SUPERVISORD -HUP
        else
            # Fails if the pid file does not exist BEFORE the reload
            failure $"Reloading $prog"
        fi
        sleep 1
        if [ ! -e $PID_FILE ] ; then
            # Fails if the pid file does not exist AFTER the reload
            failure $"Reloading $prog"
        fi
        RETVAL=$?
        echo
}

HUPのシグナルを送ると、supervisorはプロセスを全てリスタートしてしまうようです。

SIGHUP
supervisord will stop all processes, reload the configuration from the first config file it finds, and restart all processes.

プロセスが多重に起動してしまうのはreloadによるプロセスの再起動が原因だったようです。

supervisorctl update

supervisorctl updateというコマンドを使えば、変更があった設定のプロセスだけ再起動されるので、start直後の設定の変更がないので状態ではreloadは無視されるのでプロセスが再起動されることはありません。

This command only updates the changes. It does not restart any of the managed applications, even if their configuration has changed. New application configurations cannot be started, neither. (See the “update” command below)

supervisorctl update

まとめ

  • chefのserviceリソースで supervisord を使う場合、デフォルトのreloadが実行された場合全てのプロセスを再起動されます。
  • supervisordの初回起動時にはstartの直後にreloadが実行されるのでプロセスが多重起動されてしまう場合もあるかもしれません。
  • そこでデフォルト(/etc/init.d/supervisord)のreloadでプロセスが再起動しないようにreload_commandで上書きして設定に変更のあったものだけ再起動するようupdateを使うようにして対応しました。

他に解決方法などあったら教えてください。よろしくお願いします。

以上

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13