<p>The usual way to do that is to use a service manager (systemd or supervisord) to handle the service lifecycle (keeping the consul program running and restarting it if it fails for exemple) there's cookbooks existing to help creating those service units.</p>

<p>The cheap alternative if you count on chef running periodically and handling that is to use <a href="https://en.wikipedia.org/wiki/Nohup" rel="nofollow noreferrer">nohup</a> which is a linux program made exactly for this.</p>

CC BY-SA 4.0
2018-11-09T09:02:20.190Z
2019-01-08T12:17:33.990Z
2019-01-08T12:17:33.990Z
Tensibai
<p>I am trying to create a Chef cookbook that will run Hashicorp Consul in the background and will continue with the rest of the recipe and not get hung on starting Consul.</p>

<p>I have tried the <code>&amp;</code> method at the end of the command but when chef-client exits it kills the process and will not let me run any checks / testing against Consul. </p>

<p>Anyone have a suggestion on how to resolve this? I know I have seen a few implementations where they use ruby scripts but I would like to avoid that as I suck at ruby. Also do not want to use another cookbook from online, rather make my own to learn how as this is a learning project. </p>

<chef><process><bash><consul>
Running consul in the background using Chef
Josh Kirby
# Running consul in the background using Chef

(Asked by: username_0 on 2018-11-08)

I am trying to create a Chef cookbook that will run Hashicorp Consul in the background and will continue with the rest of the recipe and not get hung on starting Consul.

I have tried the `&` method at the end of the command but when chef-client exits it kills the process and will not let me run any checks / testing against Consul.

Anyone have a suggestion on how to resolve this? I know I have seen a few implementations where they use ruby scripts but I would like to avoid that as I suck at ruby. Also do not want to use another cookbook from online, rather make my own to learn how as this is a learning project.

**Tags:** chef, process, bash, consul


---

## 1 answers

### Answer by username_1 on 2018-11-09. Score: 1

The usual way to do that is to use a service manager (systemd or supervisord) to handle the service lifecycle (keeping the consul program running and restarting it if it fails for exemple) there's cookbooks existing to help creating those service units.

The cheap alternative if you count on chef running periodically and handling that is to use [nohup](https://en.wikipedia.org/wiki/Nohup) which is a linux program made exactly for this.


---

