title: Can systemd automatically restart / stop dependent services?
body: <p>For performance reasons I need to run multiple instances of an app, pinned to CPU, listening on different ports. An HAProxy TCP load balancer sits in front of them to distribute the traffic.</p>
  
  <p>This is done to prevent any thread context switching and to enforce a shared-nothing design (so no need for any sort of locks within an application, assuming it is single threaded).</p>
  
  <p>So that means on a server with 64 CPUs, I may have HAProxy pinned to CPU 0 and then 63 instances of my app each pinned to separate CPUs (1-63).</p>
  
  <p>Obviously that is quite complex to manage in terms of startup, restart, shutdown, etc.</p>
  
  <p>I was wondering if there is any way I could use systemd to handle this complexity for me.</p>
  
  <p>I know that if I defined HAProxy as a unit and then stated it Requires the other apps it needs to talk to, it could solve the start up problem, e.g.</p>
  
  <pre><code>Require=app1,app2,.....,app63
  </code></pre>
  
  <p>I could do</p>
  
  <pre><code> systemctl start myhaproxy
  </code></pre>
  
  <p>and it would first start the 63 instances it requires (assuming each of them is defined as a separate systemd unit during app installation).</p>
  
  <p>However, I am wondering if there is anyway I could get this to also work for restart and shutdown.</p>
  
  <p>So if I do:</p>
  
  <pre><code>systemctl stop myhaproxy
  </code></pre>
  
  <p>I would like it to automatically shutdown all the 63 instances of the app it talks to.</p>
  
  <p>And if I do</p>
  
  <pre><code>systemctl restart myhaproxy
  </code></pre>
  
  <p>then I would like it to first restart all the services listed in Require before restarting itself at the end.</p>
  
  <p>Is that possible? Or does that go beyond what systemd can provide?</p>