title: Programmatically start systemd service or test if service running
body: <p>I need to start a service and (later) detect if it running from within a C++ program.  Is there a simpler approach than invoking systemctl with suitable arguments and parsing the output?</p>
  
  <p>The source of the service is entirely under my control.  (Currently it is written in bash, but a C++ wrapper is entirely possible.)</p>
  
  <p>(I've had a brief look at DBus - it is clearly very powerful, but fails the "simpler" test.)</p>
  
  <p>The source of the service is entirely under my control.  (Currently it is written in bash, but C++ is entirely possible.)</p>
  
  <p>The code is for an embedded device running a variant of Debian Jessie.  Portability is not a major concern (but obviously the answer will be more useful to others if it is portable).</p>