Chef-solo 12.1.1 usermod: user www-data is currently used by process 801

1.1k views Asked by At

Provisioning of a custom cookbook fails on a users_manage resource:

users_manage "www-data" do action :create end

The reason is that this user is currently running the nginx worker process.

A simple fix should be to stop the service while users_manage is running. What is the best way to do this in Chef?

1

There are 1 answers

0
Roland On

One solution may be something like:

service 'nginx' do
  action :stop
  only_if ... # (add your condition check here, like a `ps` call to get the user of the nginx process)
end

users_manage 'www-data' do 
  action :create
end

service 'nginx' do
  action :start
end

A better way would probably be to backfill the data bag for the users cookbook to keep it in sync with the current system so it won't change anything, given that you first call the users cookbook and later install nginx (in the run_list).

An even better way would be to add your custom users to the www-group and leave nginx alone. Nginx's user/group memberships are defined by the package/distro and various things assume specific settings, e.g. logrotate cronjobs. If you change that, you'll probably gonna have a bad timeā€¦