0

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:

  • 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 .conf file. This program starts up on boot. I achieved the start up boot by creating a .service file for it and then enabling it using systemctl / systemd.

  • 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 .conf file through a simple form, and therefore configure the operation of the main program.

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 .conf 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.

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:

  • I've set up a new user of the name of the application. Call it user application-name.
  • The RS232/TCP/IP/VOIP program resides in the folder /home/application-name/. The .conf file also resides in here.
  • systemd starts the program on boot. I understand that the program is being run as root.
  • The web / CGI code is located in /home/application-name/web/. I've set up an alias in the Lighttpd configuration is that /cgi-bin/ points to here, and that works.
  • The Lighttpd server, which I understand is run as user 'http', happily accesses the web page and, on submitting of POST data, edits the ../.conf file accordingly. To allow the web server to edit the .conf file I did have to chmod that file to allow write access to others, but I am guessing that a better way to do this would be to put users application-name and http into a new user group (though I'd appreciate advice on this also).
  • After processing of the POST data, my C CGI program also uses system() to call a bash script, restart_application.sh.
  • Inside restart_application.sh, I'm making a call to systemctl to restart my main program. But it doesn't work, and I gather it doesn't work because no user except root can invoke systemctl.

So the main question is:

  • How should I make my program restart?

And also:

  • If I'm doing any absolute horrors here in terms of my setup and Linux system administration, please by all means shout angrily.

Edit 1: Unless anyone has a better approach, I'm thinking of trying the idea suggested here which is to basically 'sudo' within the bash file.

Community
  • 1
  • 1
Trevor
  • 10,903
  • 5
  • 61
  • 84
  • You could code your main application so that it is capable of reloading its parameters without a complete restart... – Jim Garrison Oct 02 '13 at 15:47
  • Hi Jim, that's a good point. Do you have any suggestion for means to indicate to the program that it should restart? One idea that does immediately come to mind is for it to periodically watch the file's timestamp. – Trevor Oct 02 '13 at 15:50
  • That's one way; the other is to have a CGI page that causes the reload when it receives a GET or POST – Jim Garrison Oct 02 '13 at 15:55
  • It's how the CGI page would signal the need to restart to the other program is where I'm stuck. – Trevor Oct 02 '13 at 16:00
  • Have the target program have a thread listening to a TCP socket for a specific packet (ignoring everything else); send that packet when you want to reload the config. Or, use a signal handler and handle, say, SIGHUP to reload. There are lots of ways to signal between processes. – Jim Garrison Oct 02 '13 at 16:41

0 Answers0