LoginSignup
2
2

More than 5 years have passed since last update.

Vagrant で作った VM 上で service iptables start できない問題

Last updated at Posted at 2015-01-18

症状

iptables の設定をするような chef のレシピを書いて Vagrant で作った VM 上で実行したら、次のようなエラーが出た。iptables サービスを起動できていないようだ。

  ================================================================================
    Error executing action `start` on resource 'service[iptables]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '6'
    ---- Begin output of /sbin/service iptables start ----
    STDOUT: 
    STDERR: 
    ---- End output of /sbin/service iptables start ----
    Ran /sbin/service iptables start returned 6

試しに手動で $ sudo service iptables start してみると、なんのメッセージも表示されない。

原因

/etc/sysconfig/iptables が存在しないと /etc/init.d/iptables がエラーを吐くから。


# Do not start if there is no config file.
[ ! -f "$IPTABLES_DATA" ] && return 6

参考: http://serverfault.com/questions/405791/service-iptables-doesnt-display-message

Box ファイルにもよるのかもしれませんが、僕の手元の VM にはデフォルトで iptables ファイルが存在しませんでした。

解決策

not_if で条件を付けつつ templete リソースから notifies する。

service "iptables" do
  supports :status => true, :restart => true, :stop => true
  action [:enable, :start]
  only_if "ls /etc/sysconfig/iptables"
end

template "#{node[:iptables][:path]}/iptables" do
  source "iptables.erb"
  owner "root"
  group "root"
  mode "0644"
  notifies :restart, "service[iptables]"
end

一瞬 service リソースの action を nothing にしようかとも思ったけど、そうすると「何らかの理由で手動で iptables を止めて、かつ設定ファイルに変更がない」場合に chef-solo 実行でサービスが起動できないのでやめました。

2
2
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
2
2