Need help getting a web page to start a server.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help getting a web page to start a server.
# 1  
Old 11-03-2018
Solved: Need help getting a web page to start a server.

Wont let me add the solved tag, say's im over the max. Removing 2 tags did not help.



No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial


One of my game servers keeps going offline and so I want to give the users the ability to bring it back up.
The easiest way I could think of is to create a web page that would execute a bash
script. Here is the code I used.

Code:
<?php

if ($_GET['run']) {
  $old_path = getcwd();
  chdir('/home/warmc/servers/snapshot/');
  
  $output = shell_exec("./teststart.sh");
  echo $output;

  chdir($old_path);
}
?>


<a href="?run=true">Click Me!</a>

My web page works and will execute the script but all it does is echo to the webpage.
I thought maybe it was because the web page user needs root access and I found a source that suggested adding the following to the sudoers file.


Code:
 www-data ALL=NOPASSWD: /path/to/script

The problem is that when trying to use visudo from Webmin Command Shell I get this.


Code:
 [host@Username ~]# visudo Error opening terminal: unknown. 
 visudo: /etc/sudoers.tmp unchanged 
 [host@Username ~]#

So how do I edit the sudoers file?
Am I on the right track?

Last edited by Stuperfied; 11-13-2018 at 12:21 AM.. Reason: Solved
# 2  
Old 11-04-2018
Well, it's not the way I would do it.

I would create a cron script and run the script from cron to check if the game server is up and running and then restart if it has stopped.

For example in crontab:

Code:
* * * * * /usr/bin/nice -n 19 /usr/local/neo/bin/check_apache > /dev/null 2>&1

Then script like this, for example:

Code:
$ cat /usr/local/neo/bin/check_apache 


#!/bin/sh 

/bin/ps ax | grep apache2 | grep -v grep  > /dev/null

if [ $? -ne 0 ]; 
then 
/usr/sbin/service apache2 start > /dev/null 2>&1 
else
 /bin/ps ax | grep mysqld | grep -v grep  > /dev/null
 if [ $? -ne 0 ]; 
 then
    /usr/sbin/service mysql start > /dev/null 2>&1 
 fi 
fi

# 3  
Old 11-04-2018
I did think of that but we are trying to make everything controlled by web interface and this is just one small part of a larger project yet to come.
# 4  
Old 11-04-2018
Putting sudo scripts embedded in php code at user clicks is not advisable nor desirable.
It is a major security issue and should be treated like that.

Why not use existing tools, which have agents and API(s) at your disposal.
Include those in your project if you require such actions.
Restarts, deployments will be transparent to user, not dependent on application itself and fairly secure.

If you really need user interaction for such tasks, otherwise cron is fine, and best would be to see why application needs to be restarted Smilie

Hope that helps
Regards
Peasant.
# 5  
Old 11-04-2018
Quote:
Originally Posted by Stuperfied
I did think of that but we are trying to make everything controlled by web interface and this is just one small part of a larger project yet to come.
Hmmm.

I used to think that way, but without really great serve-side sys admin skills you may be creating unnecessary security risks. Even guys like me with a decades of years experience on the server side, do not use the web to do superuser-required tasks. It just takes one mistake and you could lose your server and your data.

Yes, you can kludge solutions together which will work, but they will leave you vulnerable to major security risks.

I suggest you do this with a cron file, to insure your game servers are running, and move on to other tasks Smilie

Never, in the spirit of creating a "perfect solution" do things which leave your server vulnerable. After you have done 100 tasks and written 29999 lines of code, you will forget all the insecure code you wrote and you will have problems later on.

Why make problems for yourself when you can do the same thing in a more secure way which will not expose you to security risks?
# 6  
Old 11-04-2018
Quote:
Originally Posted by Peasant
best would be to see why application needs to be restarted
Amen!

If i have learned anything in the nearly fourty years i work in IT it is this: if there is a problem, DO NOT create a workaround - solve the problem instead! Workarounds may be implemented faster sometimes but they inadvertently come back to haunt you and most probably they bite you in the behind in the least convenient moment.

Instead of creating ways to faster restart the server find out why it needs to be restarted. Your description ("...one of our servers...") implies that it is just one server, not the other ones. So, where is the difference? What is special in this server so that it keeps crashing the application? Have you considered reinstalling it from scratch?

In your place i'd investigate this instead of finding ways to selectively poking holes into my server security.

I hope this helps.

bakunin
These 2 Users Gave Thanks to bakunin For This Post:
# 7  
Old 11-04-2018
Dudes, this is a minecraft server. I dont really care about security, ive lost everything multiple times before due to hosting issues and I gotta tell you it wasn't the end of the world. The community adapted.



My issue now is that we are running the latest snapshot servers and they are really unstable. They shut down randomly because of updates or bugs and there is nothing I can do about that. Now my server managers really would like to be able to start / stop servers through a web app rather than having to login and go to cron jobs all the time. They already have RCon at their disposal but that doesn't help them start the servers after they have been stopped. Now a few simple buttons with start, stop, restart is probably not so much of a security risk and let them hack me if they want to waste their time cause there's no secure info kept on these servers.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Web Development

Unable to start the apache web server

Hi All, I'm getting this below error bash-4.1$ ./apachectl -k start (98)Address already in use: make_sock: could not bind to address hostname:18000 no listening sockets available, shutting down Unable to open logs I tried to change the port number, still same error: ... (5 Replies)
Discussion started by: raghur77
5 Replies

2. Web Development

Call shell script from HTML page - without web server

Hi, I have html page in my unix machine(server), which I will open with firefox or mozilla available in unix machine. Firefox or mozilla will be opened using x windows. Since I have access to unix machien(like other users) and this HTML page is for user having access to Unix machine, I see no... (7 Replies)
Discussion started by: vamanu9
7 Replies

3. Cybersecurity

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both, when... (1 Reply)
Discussion started by: WhotheWhat
1 Replies

4. Web Development

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both,... (2 Replies)
Discussion started by: WhotheWhat
2 Replies

5. UNIX for Dummies Questions & Answers

Opening web page in remote server

Hi all, I am new to UNIX and so am struggling a bit on using the right commands. I am working on a remote UNIX server and i need to load a web page using firefox. I can use the client IP address to access the web page but i am not able to do so because the command i am typing is wrong. ... (1 Reply)
Discussion started by: greg15
1 Replies

6. Solaris

Solaris 9 Web Start Upgrade using -nowin - still complains about X server

Hi there. I'm trying to upgrade a Sun Blade 100 to Solaris 9. I downloaded and burned the install, disc 1, disc 2 and tools CDs from Sun. I turned off auto-boot, put in the CD and enter the following: # boot cdrom -nowin The cdrom boot starts, and I get prompted to choose a language... (2 Replies)
Discussion started by: calenti
2 Replies

7. Shell Programming and Scripting

finding the web page on server

Wish you all a very happy new year. I have a web url "http://marabou.mis.amat.com/cgi-bin/iman?IMAN_server_report=full" where marabou.mis.amat.com is my server name. the page content is below. ********************************************************* TcEng Web server report Thu Jan 4... (4 Replies)
Discussion started by: Krrishv
4 Replies

8. UNIX for Dummies Questions & Answers

Accessing Web Page

Hello, I am new to unix, but wanted to know how can we fetch data from a web page (i.e. an HTML Page), my requirement is to read an html page and wanted to create a flat file (text file) based on the contents available in the mentioned HTML page. Thanks Imtiaz (3 Replies)
Discussion started by: Imtiaz
3 Replies
Login or Register to Ask a Question