LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2014, 12:59 AM   #1
unclesamcrazy
Member
 
Registered: May 2013
Posts: 189

Rep: Reputation: 1
Restart Apache from cgi-bin shell script url


I want to restart the apache server using url.
I am using cgi-bin shell script to do so but I am not able to do it.
I have created a file apache and put it in /var/www/cgi-bin.
I have written following code in the file apache.
Code:
#!/bin/bash
 echo "Content-type: text/html"
 echo ""
 echo "<html><head><title>Demo</title></head><body>"
service httpd restart
 echo "</body></html>"
but when I execute the file in the browser using
Code:
http://server_ip/cgi-bin/apache
it gives me following output on the web page
Code:
 Stopping httpd: [FAILED] Starting httpd:
I have updated /etc/sudoers file and put following content in it
Code:
www-data    ALL=NOPASSWD:/sbin/service httpd restart
but I am not able to restart apache using url.
I can execute only commands which do not require sudo.

I want to restart apache using web url. Please help me.

Thanks a lot !!!
 
Old 04-24-2014, 08:23 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,696

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
Think about what you are trying to do... a restart requires apache to stop. To stop apache means that the CGI must also be stopped... To stop the CGI means the command requesting the restart is also stopped - and before the process can finish.

Now it CAN be done, but you would have to allow the sudo command to submit the restart command to cron (use the "batch" command, or the "at" command) so that nothing running under apache is running at the time the cron request restarts apache.

You can TRY putting the sudo command into background, but it may just be killed as part of the process tree (can try using the "nohup" command, but I'm not sure about the timing - you might have to put a 1 second sleep in there to give time for the CGI to finish).

Last edited by jpollard; 04-24-2014 at 08:26 AM.
 
Old 04-24-2014, 10:19 AM   #3
unclesamcrazy
Member
 
Registered: May 2013
Posts: 189

Original Poster
Rep: Reputation: 1
Thanks for your answer. Yes it is happening what you are saying. Restart means stop the service and start it again but cgi-bin script needs apache running to execute the complete script and when I say restart, it stops the apache and once apache is stopped, the script is not able to start it again. I have to do it manually using command line.
So is it a dead lock? can't it be done?
You are saying about `at` command but I don't know how to use it.

Well again thanks for your help. if you could do please help me with nohup so It will start the apache after 5 seconds or 10 seconds after thescript execution and stop apache immediately with running cgi-bin script.
so I think it can solve my problem, the procedure will like
Code:
first set command in the script to start apache after 10 seconds --> stop apache with the script --> after 10 seconds --> apache started automatically
Thanks again !

Last edited by unclesamcrazy; 04-24-2014 at 10:20 AM.
 
Old 04-24-2014, 11:43 AM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,093

Rep: Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474Reputation: 2474
i would use ssh like you are supposed to do

allowing some person access THROUGH the web page to restart the server is asking for a TON of TROUBLE

a "script kiddy" WILL end up having a LOT of "fun" at your expense
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not Found The requested URL /nagios/cgi-bin/tac.cgi was not found on this server. amanamu Linux - Server 5 02-07-2013 03:45 AM
could not execute bin folder of a package from cgi bin script using python ashish hasani Linux - Server 1 04-05-2012 12:18 AM
Need Help with Apache Cgi-bin? your_shadow03 Linux - Newbie 1 08-21-2009 06:22 AM
Running a shell script via CGI-BIN chrisk5527 Linux - General 3 05-09-2003 11:44 AM
apache cgi-bin roadie Linux - General 6 06-16-2001 07:15 PM


All times are GMT -5. The time now is 01:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration