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 usingsystemctl
/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 tochmod
that file to allow write access to others, but I am guessing that a better way to do this would be to put usersapplication-name
andhttp
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 tosystemctl
to restart my main program. But it doesn't work, and I gather it doesn't work because no user exceptroot
can invokesystemctl
.
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.