title: How can I restart a service or reboot triggered by a Lighttpd CGI command?
body: <p>I have created an application to run on an Olinuxino Maxi board which is presently running an Arch Linux ARM distribution. My somewhat simple application can be considered to be in two parts:</p>
  
  <ul>
  <li><p>A program that performs communication between RS232 and TCP/IP, and initiates / accepts VOIP calls via the Linphone library. How this program behaves is configured through a <code>.conf</code> file. This program starts up on boot. I achieved the start up boot by creating a <code>.service</code> file for it and then enabling it using <code>systemctl</code> / <code>systemd</code>. </p></li>
  <li><p>A simple web page that is accessed via Lighttpd. The CGI page is written in C. This page provides means for a user to edit the <code>.conf</code> file through a simple form, and therefore configure the operation of the main program. </p></li>
  </ul>
  
  <p>All of the above now works. The specific problem I have relates to how I can cause my service program to restart (so that it configures itself again from the <code>.conf</code> file) when the user submits new settings via the web page. I'm stuck on this areas because, while I'm a fairly experienced C programmer, doing development on Linux and general Linux administration is fairly new ground to me.</p>
  
  <p>In case it's relevant, I'll discuss a bit about how I've set this up, including how I've set up users and so forth:</p>
  
  <ul>
  <li>I've set up a new user of the name of the application. Call it user <em>application-name</em>.</li>
  <li>The RS232/TCP/IP/VOIP program resides in the folder <code>/home/application-name/</code>. The <code>.conf</code> file also resides in here.</li>
  <li><code>systemd</code> starts the program on boot. I understand that the program is being run as root.</li>
  <li>The web / CGI code is located in <code>/home/application-name/web/</code>. I've set up an alias in the Lighttpd configuration is that <code>/cgi-bin/</code> points to here, and that works. </li>
  <li>The Lighttpd server, which I understand is run as user 'http', happily accesses the web page and, on submitting of POST data, edits the <code>../.conf</code> file accordingly. To allow the web server to edit the <code>.conf</code> file I did have to <code>chmod</code> that file to allow write access to others, but I am guessing that a better way to do this would be to put users <code>application-name</code> and <code>http</code> into a new user group (though I'd appreciate advice on this also).</li>
  <li>After processing of the POST data, my C CGI program also uses <code>system()</code> to call a bash script, <code>restart_application.sh</code>. </li>
  <li>Inside <code>restart_application.sh</code>, I'm making a call to <code>systemctl</code> to restart my main program. But it doesn't work, and I gather it doesn't work because no user except <code>root</code> can invoke <code>systemctl</code>. </li>
  </ul>
  
  <p>So the main question is:</p>
  
  <ul>
  <li>How should I make my program restart?</li>
  </ul>
  
  <p>And also:</p>
  
  <ul>
  <li>If I'm doing any absolute horrors here in terms of my setup and Linux system administration, please by all means shout angrily. </li>
  </ul>
  
  <p><strong>Edit 1</strong>: Unless anyone has a better approach, I'm thinking of trying the idea suggested <a href="https://stackoverflow.com/questions/349884/how-do-i-programatically-restart-a-system-servicenot-apache-from-apache-in-lin">here</a> which is to basically 'sudo' within the bash file.</p>