Jump to content

Server startup script


Stickybit

Recommended Posts

Hi Guys

Having installed the server program on a linux server.. i realized the the program needed some kind of startup script... so I wrote one: /sbin/mta. here is the simple code:

#!/usr/bin/perl


use English;


die "\nYou must be root in order to start the MTA server.\n\n" if ($EFFECTIVE_USER_ID != 0);
die "\nUsage: $PROGRAM_NAME {start|stop}\n\n" if (!(($ARGV[0] eq 'start') or ($ARGV[0] eq 'stop')));


$action = $ARGV[0];
$user   = 'mta';
$dir    = '/opt/MTAServer-0.3/';
$bin    = 'MTAServer0.3';


CASE: {

  ($action eq 'start') && do {

     print "\nStarting MTA daemon.\n\n";
     chdir($dir);
     system('sudo -u '. $user .' '. $dir . $bin .' -b') == 0 or die "Error while starting server.\n";
     last CASE;

  };

  ($action eq 'stop') && do {

     print "\nStopping MTA daemon.\n\n";
     exec ('ps -C '. $bin .' -o pid= | xargs kill -9') == 0 or die "Error while stopping server.\n";
     last CASE;

  };

}

Before you can use this script.. you must create a non-priveleged user called "mta"... and alter the content of $dir to reflect your MTA install directory. For increased security, I have set these permissions on the files:

-rw------- 1 mta mta 0 Oct 26 17:31 banned.lst

-rw------- 1 mta mta 1417 Dec 31 02:46 CHANGELOG

-rw------- 1 mta mta 49 Feb 8 11:02 motd.txt

-rwx------ 1 mta mta 178897 Dec 31 20:32 MTAServer0.3

-rw------- 1 mta mta 8489 Feb 8 11:00 mtaserver.conf

-rw------- 1 mta mta 3092 Dec 31 02:48 README

That was my 50 cent. Thanks for a great program. :)

-Sticky bit

Link to comment
  • 5 months later...

.. and for ver. 0.4 - pretty much the same:

#!/usr/bin/perl

use English;

die "\nYou must be root in order to start the MTA server.\n\n" if ($EFFECTIVE_USER_ID != 0);
die "\nUsage: $PROGRAM_NAME {start|stop}\n\n" if (!(($ARGV[0] eq 'start') or ($ARGV[0] eq 'stop')));

$action = $ARGV[0];
$user   = 'mta';
$dir    = '/opt/MTAServer-0.4/';
$bin    = 'MTAServer0.4';

CASE: {

  ($action eq 'start') && do {

     print "\nStarting MTA daemon.\n\n";
     chdir($dir);
     system('sudo -u ' . $user . ' ' . $dir . $bin . ' -b') == 0 or die "Fatal error while starting server.\n";
     last CASE;

  };

  ($action eq 'stop') && do {

     print "\nStopping MTA daemon.\n\n";
     system ('ps -C ' . $bin  . ' -o pid= | xargs kill -9') == 0 or die "Fatal error while stopping server.\n";
     last CASE;

  };

}

-Sticky bit

Link to comment
  • 1 year later...

K dude whats for latest version 5 got any script? just repace 0.4 with latest one right?

and what about rebooting the server? and why root access only , cant u just password protect the directory , cause most webhosts dont give root access , so whats the solution to that?

Just a note i tried ur script and all it does is give internal server error.

Link to comment
K dude whats for latest version 5 got any script? just repace 0.4 with latest one right?

The script for version 5 is the same as for version 4. Just replace the version numbers.

and what about rebooting the server?

The script should be part of the init.d / rc.d scripts - and could then be automaticly started and stopped when entering / exiting specific runlevels.

and why root access only , cant u just password protect the directory , cause most webhosts dont give root access , so whats the solution to that?

This ain't a cgi script for a webserver, so password protected directory's isn't an option. Password protected diretory's isn't really security anyway - it's just a webserver feature. Only root should be able to start daemons, and daemons (especially 3. party daemons without sourcecode) should never run as root. That is the reason for the sudo'ing.

Just a note i tried ur script and all it does is give internal server error.

This isn't a script for your webpage. It's a plain perl script for shell execution.

-Sticky bit

Link to comment

Oh i wanted such a script but i just made one using other scripts and merged to enable auto reboot of mta server if it goes down. You close the server via admin shutdown button and ask ur hoster to run ur auto start script in background and tada it starts ur server after the time specified by u in script say 10 sec or 20 sec or more. Pretty neat huh?

Does this one of ur does the same thing ? or is it just a script for only linux root to run the server , cause if people have shell access on a webhost they dont have root access u have to keep that in mind dude.

Link to comment
Oh i wanted such a script but i just made one using other scripts and merged to enable auto reboot of mta server if it goes down. You close the server via admin shutdown button and ask ur hoster to run ur auto start script in background and tada it starts ur server after the time specified by u in script say 10 sec or 20 sec or more. Pretty neat huh?

Does this one of ur does the same thing ?

Nope.

or is it just a script for only linux root to run the server

Yes.

cause if people have shell access on a webhost they dont have root access u have to keep that in mind dude.

Nope. Only real sysadm's who has root acces - and who can handle root acces, should mess with daemons.

-Stickybit

Link to comment
  • MTA Team

If you rent a dedicated server, you get full acces to that server, including root

If you rent a dedicated game server, you may get ssh acces, but not root

If you rent a shell account, you will get ssh access but not root

If you rent web space you will not get ssh access

The best way to keep an MTA server alive is by writing a script that checks if the server is running or not and if it is not restart it. This script should be runnable from normal user and be placed as a cron job that runs every 5 or 10 minutes.

Link to comment

The best way to keep an MTA server alive is by writing a script that checks if the server is running or not and if it is not restart it. This script should be runnable from normal user and be placed as a cron job that runs every 5 or 10 minutes.

Yup thats the script i use and its like 10 seconds checkup not 10 mins though , thats more safe .

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...