# Run Chef as Daemon

**URL:** <https://discourse.chef.io/t/run-chef-as-daemon/15148>\
**Category:** Chef Infra (archive)\
**Created:** [May 17, 2019, 2:10pm UTC](https://discourse.chef.io/t/run-chef-as-daemon/15148 "2019-05-17T14:10:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexpatt](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@alexpatt](https://discourse.chef.io/u/alexpatt)\
**Post date:** [May 17, 2019, 2:10pm UTC](https://discourse.chef.io/t/run-chef-as-daemon/15148/1 "2019-05-17T14:10:41Z")

</div>

Hello,

Is there a way to daemonize chef-client even if I don't have the server open? (Still running though of course) Or do I have to explicitly open the command line and keep it open until I don't want to run as daemon anymore?

---

<div class="post-metadata">

**Author:** ![r4hul](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@r4hul](https://discourse.chef.io/u/r4hul)\
**Post date:** [May 17, 2019, 5:49pm UTC](https://discourse.chef.io/t/run-chef-as-daemon/15148/2 "2019-05-17T17:49:21Z")

</div>

If you want it to run just one time as a background job then you can create a cron and run it on demand. If you want to run periodically then set the schedule on the cron and it will even if you are not logged on. Is that what you are looking for ?

---

<div class="post-metadata">

**Author:** ![alexpatt](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@alexpatt](https://discourse.chef.io/u/alexpatt)\
**Post date:** [May 17, 2019, 6:14pm UTC](https://discourse.chef.io/t/run-chef-as-daemon/15148/3 "2019-05-17T18:14:06Z")

</div>

Yes thats perfect, thank you. One thing though, would I be creating the cron as a recipe using the chef resource or would that be an outside thing id have to install?

---

<div class="post-metadata">

**Author:** ![r4hul](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@r4hul](https://discourse.chef.io/u/r4hul)\
**Post date:** [May 17, 2019, 10:20pm UTC](https://discourse.chef.io/t/run-chef-as-daemon/15148/4 "2019-05-17T22:20:54Z")

</div>

You can do it either ways. If you have a bootstrapping cookbook that runs when VM starts up for the first time then you can put a cron resource within a recipe of that cookbook and it will auto create the cron job with your chef-client ... as the command. Then for example if there multiple reboots during bootstrap you want chef client to be running automatically on each reboot then just configure the cron to start when system boots up. It will run chef client command automatically on each system boot up. One thing to ensure there is all your resources in cookbooks are idempotent otherwise same config will be applied on each run over and over.

---

<div class="post-metadata">

**Author:** ![bcorner\_fan](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bcorner_fan/32/2237_2.png) [@bcorner\_fan](https://discourse.chef.io/u/bcorner_fan)\
**Post date:** [May 18, 2019, 6:54pm UTC](https://discourse.chef.io/t/run-chef-as-daemon/15148/5 "2019-05-18T18:54:23Z")

</div>

Use the chef-client cookbook and simply using attributes you can switch it up from systemv service to cron or on demand. Very configurable.  
Simply search the [supermarket.chef.io](http://supermarket.chef.io) for the cookbook. Also love the chef updater cookbook to pin the environment.
