Thursday, 9 March 2017

Stealth launch of services on Linux.

Perhaps it is no secret that the script is run services on Linux
/etc/rc.d/init.d located in or depending on /etc/init.d
distribution. To run the script automatically when
system startup, it is necessary to create a symbolic link to the script and place
it in /etc/rc.d/rcN.d or /etc/rc.d/rcN.d directory where N & # 8211;
It corresponds to the execution of the script.

level 0 
    System stop (halt) - operation of the system must be stopped; 

level 1 
    single-user mode - the system initiates a minimum
    services and provides a single user (as a rule,
    superuser) without an authentication command line.
    Typically, this mode is used for system recovery; 

level 2 
    multiplayer mode - users can work on different
    terminals, login authentication process; 

level 3 
    multiplayer network mode - in contrast to the previous
    level network configuration is carried out, and run a variety of
    network services; 

level 4 
    It has no standard interpretation and hardly used;

level 5 
    run graphics - compared with the level 3
    produced also start X11 graphics, and entry into the
    system implemented in the graphics mode; 

level 6 
    reboot the system - when entering this mode stop
    all running programs and restart is performed. 

Most often during the startup system uses load levels 3 or 5. 
However, there are some tricks in the name of the symbolic link itself, about
which many are silent, and I want to tell. For example:
/etc/rc.d/rc0.d/K60crond and /etc/rc.d/rc3.d/S40crond, pointing to one
script /etc/init.d/crond syslog service. The script begins
with "K" corresponds to stop the service, and the "S" - Start. The numbers following
before the name of the service order is set to run scripts in a directory.
For example, /etc/rc.d/rc3.d/S34syslogd script will be launched before the script
/etc/rc.d/rc3.d/S40crond, whereas before /etc/rc.d/rc3.d/K60crond
/etc/rc.d/rc3.d/K66syslogd. It can be seen that the sum of the numbers for the same
Service is 100 - it allows you to organize all of the scripts in the order
start reverse order of completion. Create the most symbolic
links very tiring, and it is better to use a special
utility chkconfig.

The syntax for using it is very simple:

        chkconfig --list [service name]
        chkconfig --add <service name>
        chkconfig --del <service name>
        chkconfig [--level <levels>] <service name> <on | off | reset | resetpriorities>

Where the service name - the name of the executable script is in /etc/rc.d/init.d

However, there is a small trick, the fact that the script is run
must have a specific format, like this:

        #! / Bin / sh
        # Chkconfig: - 98 02
        # Description: Description of the process
        # Processname: Process Name

        # Source function library.
        if [-f /etc/init.d/functions]; then
          . /etc/init.d/functions
        elif [-f /etc/rc.d/init.d/functions]; then
          . /etc/rc.d/init.d/functions
          exit 0
        KIND = "service_name"
        start () {
                echo -n $ "Starting $ KIND services:"
                daemon / usr / local / sbin / ispolnyaemyy_fayl

        stop () {
                echo -n $ "Shutting down $ KIND services:"
                killproc ispolnyaemyy_fayl

        restart () {
                    echo -n $ "Restarting $ KIND services:"	
                       killproc ispolnyaemyy_fayl
                   daemon / usr / local / sbin / ispolnyaemyy_fayl

        case "$ 1" in
                echo $ "Usage: $ 0 {start | stop | restart}"
                exit 1
        exit $?

The main thing in this, firstly the script must have at least 3
possible start key is: start, stop, restart, because it
These basic commands used to start, stop and restart.
In addition to all this are the most cherished are written at the beginning of the file
figures responsible for the start-up sequence:

         # Chkconfig: - 98 02

Where 98 is a number in the startup sequence, and 02 is the number of
stop sequence.

That is, to put it simply, this script is run in 98mym
the sequence of queues, and will be stopped 2rym.

Now the workshop. 

So in order to add a script and add it to your startup should be
perform the following steps:

1. Create an executable script the template above are replaced
ispolnyaemyy_fayl file name which should be run.

2. Place an executable script in /etc/rc.d/init

3. Execute the command chkconfig --add ispolnyaemyy_skript

4. Run the setup command or servicevonf (depending on
you are running in GUI mode or console) and select the service that
It will be named ispolnyaemyy_skript.

Well, that probably and everything, if I have never made a mistake.

Other Resources: centrifugo.initd how-to-run-start-up-scripts-on-amazon-linux

No comments:

Post a Comment