Running Chef-Client as daemon helps in knowing the state of all the nodes at any point of time. This help in running the Chef-Client at any point of time.
Pre-requisites
The node should be registered with Chef server and it should be running Chef-Client without any error.
Chef-Client in Daemon Mode
Start Chef-Client in daemon mode, running every 30 minutes.
user@server:~$ sudo chef-client -i 1800
In the above code, – i enables to run the Chef-Client in daemon mode on the required node and 1800 seconds define that the Chef-Client daemon should run in every 30 minutes.
Validating Daemon Run
Validate that the Chef-Client is running as a daemon.
user@server:~$ ps auxw | grep chef-client
The above command will grep the running daemon process of Chef-Client.
Other Ways
Instead of running Chef-Client as a daemon, we can run the same as a cron job.
user@server:~$ subl /etc/cron.d/chef_client PATH=/usr/local/bin:/usr/bin:/bin # m h dom mon dow user command */15 * * * * root chef-client -l warn | grep -v 'retrying [1234]/5 in'
The above cron job will run after every 15 minutes.