LoginSignup
4
3

More than 5 years have passed since last update.

Ubuntu14.04でservice startが1を返すためchefがエラーになる現象を回避

Posted at
Ubuntu12.04LTS
$ lsb_release -r; sudo service nginx start; echo $?
Release:        12.04
Starting nginx: nginx.
0
Ubuntu14.04LTS
$ lsb_release -r; sudo service nginx start; echo $?
Release:        14.04
start: Job is already running: nginx
1

この動きはどうなんだと思う. ;; serviceで上げ下げする前に必ずstatus見ろってこと?
結果として, chefを実行したときaction :startが失敗扱いになる.

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

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of /etc/init.d/nginx start ----
    STDOUT:
    STDERR:
    ---- End output of /etc/init.d/nginx start ----
    Ran /etc/init.d/nginx start returned 1

    Resource Declaration:
    ---------------------
    # In /tmp/chef-repo/cookbooks/nginx/recipes/default.rb

     48: service 'nginx' do
     49:   supports :status => true, :restart => false, :start => true
     50:   action [ :enable, :start ]
     51: end
     52:

2015-01-16 at 4.02 PM.png

TalkingQuickly/basic_security-tlq

https://tickets.opscode.com/browse/COOK-3910 によれば

/lib/lsb/init-functions
# If the currently running init daemon is upstart, return zero; if the
# calling init script belongs to a package which also provides a native
# upstart job, it should generally exit non-zero in this case.
init_is_upstart()
{
   if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | /bin/grep -q upstart; then
       return 0
   fi
   return 1
}

にコメントが書かれており, initctlがupstartなら0を返す動きになる.

ので,
https://github.com/andreychernih/openssh/commit/ee011fdda086547c876bceff79f63d751d0893b9 あたりの解決策を見るとserviceブロックにproviderを渡せばよさそう

+service_provider = Chef::Provider::Service::Upstart if 'ubuntu' == node['platform'] && Chef::VersionConstraint.new('>= 13.10').include?(node['platform_version'])
 service 'nginx' do
+  provider service_provider
   supports :status => true, :restart => true, :start => true
   action [ :enable, :start ]
 end
4
3
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
4
3