Start Apache and Mysql at Boot On Kali Linux

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Start apache and mysql at boot on Kali Linux

To configure services like apache, mysql etc to start automatically at bootup just execute the following simple commands.

Apache
The following command will configure apache to start at bootup.
root@kali:~# update-rc.d apache2 enable

update-rc.d: using dependency based boot sequencing

Mysql
The following command will configure mysql to start at bootup.
root@kali:~# update-rc.d mysql enable

update-rc.d: using dependency based boot sequencing

Postgresql
Postgresql is used by metasploit for caching data. Therefore its better to get it started at bootup as well. Command is similar to the above ones.
root@kali:~# update-rc.d postgresql enable

update-rc.d: using dependency based boot sequencing

TOR
Tor, the great anonymity network is also a must for hackers. So it should always be at service when you are hacking inside Kali.
root@kali:~# update-rc.d tor enable

update-rc.d: using dependency based boot sequencing

Test configuration
The configuration is now done. Now reboot kali. After it boots up, check the status of the services by running the following commands.
root@kali:~# service apache2 status

Apache2 is running (pid 2072).

Check status of postgresql


root@kali:~# service postgresql status

Running clusters: 9.1/main

So all services should startup themselves at boot up. If there are any more services you need to startup, configure them using the update-rc.d
command, and they should work.

==
The following is an init.d script template for a hypothetical service called foobar. A typical init.d script gets executed with arguments such as
"start", "stop", "restart", "pause", etc. In order for an init.d script to be started or stopped by init during startup and shutdown, the script
needs to handle at least "start" and "stop" arguments.
$ sudo vi /etc/init.d/foobar

#! /bin/sh
# /etc/init.d/foobar

# The following part always gets executed.


echo "This part always gets executed"

# The following part carries out specific functions depending on arguments.


case "$1" in
start)
echo "Starting foobar"
echo "foobar is alive"
;;
stop)
echo "Stopping foobar"
echo "foobar is dead"
;;
*)
echo "Usage: /etc/init.d/foobar {start|stop}"
exit 1
;;
esac

exit 0

Finally, make the init.d script executable, and add the init.d script to a default runlevel, so that the script can be called at boot time (and also
during shutdown).

$ sudo chmod 755 /etc/init.d/foobar


$ sudo update-rc.d foobar defaults

Later if you decide to remove the init.d script from start-up service list, you can simply run the following.

$ sudo update-rc.d -f foobar remove

==
How to list services/daemons started at boot _and_ check their loading order

In short:
ls /etc/rc*.d
This shows you what starts at which runlevel, and within each level the order is determined by the number after the letter (K is Kill, S is start).

You can configure what starts at each runlevel with sysv-rc-conf, which is installable with apt.

e.g. on my system apache2 is symlinked in rc5.d as "S20apache2". A link in the same directory with S19 would start before it, something with S21
would start after it.

You can list all services and their status with this simple command:

service --status-all
From the manual:

service --status-all runs all init scripts, in alphabetical order, with the status command. The status is [ + ] for running services, [ - ]
for stopped services and [ ? ] for services without a 'status' command. This option only calls status for sysvinit jobs; upstart jobs can
be queried in a similar manner with initctl list.

==
Making scripts run at boot time with Debian
Posted by Steve on Mon 11 Oct 2004 at 13:01

Tags: boot, debian-specific commands, initscripts, scheduling

Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.

If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts
already present in that directory will give you an example of the kind of things that you can do.
Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always


touch /var/lock/blah

# Carry out specific functions when asked to by the system


case "$1" in
start)
echo "Starting script blah "
echo "Could do more here"
;;
stop)
echo "Stopping script blah"
echo "Could do more here"
;;
*)
echo "Usage: /etc/init.d/blah {start|stop}"
exit 1
;;
esac

exit 0

Once you've saved your file into the correct location make sure that it's executable by running " chmod 755 /etc/init.d/blah".
Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.

The simplest way of doing this is to use the Debian-specific command update-rc.d:

root@skx:~# update-rc.d blah defaults


Adding system startup for /etc/init.d/blah ...
/etc/rc0.d/K20blah -> ../init.d/blah
/etc/rc1.d/K20blah -> ../init.d/blah
/etc/rc6.d/K20blah -> ../init.d/blah
/etc/rc2.d/S20blah -> ../init.d/blah
/etc/rc3.d/S20blah -> ../init.d/blah
/etc/rc4.d/S20blah -> ../init.d/blah
/etc/rc5.d/S20blah -> ../init.d/blah

If you wish to remove the script from the startup sequence in the future run:

root@skx:/etc/rc2.d# update-rc.d -f blah remove


update-rc.d: /etc/init.d/blah exists during rc.d purge (continuing)
Removing any system startup links for /etc/init.d/blah ...
/etc/rc0.d/K20blah
/etc/rc1.d/K20blah
/etc/rc2.d/S20blah
/etc/rc3.d/S20blah
/etc/rc4.d/S20blah
/etc/rc5.d/S20blah
/etc/rc6.d/K20blah

This will leave the script itself in place, just remove the links which cause it to be executed.

You can find more details of this command by running "man update-rc.d".
Add Comment

Making scripts run at boot time with Debian


Posted by Steve on Mon 11 Oct 2004 at 13:01

Tags: boot, debian-specific commands, initscripts, scheduling

Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.

If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts
already present in that directory will give you an example of the kind of things that you can do.
Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always


touch /var/lock/blah

# Carry out specific functions when asked to by the system


case "$1" in
start)
echo "Starting script blah "
echo "Could do more here"
;;
stop)
echo "Stopping script blah"
echo "Could do more here"
;;
*)
echo "Usage: /etc/init.d/blah {start|stop}"
exit 1
;;
esac

exit 0

Once you've saved your file into the correct location make sure that it's executable by running " chmod 755 /etc/init.d/blah".
Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.

The simplest way of doing this is to use the Debian-specific command update-rc.d:

root@skx:~# update-rc.d blah defaults


Adding system startup for /etc/init.d/blah ...
/etc/rc0.d/K20blah -> ../init.d/blah
/etc/rc1.d/K20blah -> ../init.d/blah
/etc/rc6.d/K20blah -> ../init.d/blah
/etc/rc2.d/S20blah -> ../init.d/blah
/etc/rc3.d/S20blah -> ../init.d/blah
/etc/rc4.d/S20blah -> ../init.d/blah
/etc/rc5.d/S20blah -> ../init.d/blah

If you wish to remove the script from the startup sequence in the future run:

root@skx:/etc/rc2.d# update-rc.d -f blah remove


update-rc.d: /etc/init.d/blah exists during rc.d purge (continuing)
Removing any system startup links for /etc/init.d/blah ...
/etc/rc0.d/K20blah
/etc/rc1.d/K20blah
/etc/rc2.d/S20blah
/etc/rc3.d/S20blah
/etc/rc4.d/S20blah
/etc/rc5.d/S20blah
/etc/rc6.d/K20blah

This will leave the script itself in place, just remove the links which cause it to be executed.

You can find more details of this command by running "man update-rc.d".
Add Comment

==
Depending on your distro use the chkconfig or update-rc.d tool to enable/disable system services.

On a redhat/suse/mandrake style system:

sudo chkconfig apache2 off


On Debian:

sudo update-rc.d -f apache2 remove


Checkout their man pages for more info.

Why do you need -f (I assume it's force) on Debian based distros?

There are two sets of files in play here. You've got the actual init script in /etc/init.d/ and you have the links to it in your runlevel directory /etc/rcrunlevel.d/. These
guys point to the script in /etc/init.d/ If you don't use -f update-rd.d will fail UNLESS the script in /etc/init.d/ is already deleted. If you do use -f update-rc.d will
properly delete the link files regardless of whether or not the /etc/init.d/ script is deleted. jacksonh Aug 10 '10 at 20:38

Ah, that makes a lot of sense, I'd forgotten that the runlevel scripts were just links to the init scripts. Thanks for the extra explanation.

If you are dealing with a modern Ubuntu system and a few other distros you may have to deal with a combination of traditional init scripts and upstart
scripts. Managing init scripts is covered by other answers. The following is one way to stop an upstart service from starting on boot:

# mv /etc/init/servicename.conf /etc/init/servicename.conf.disabled
The problem with this method is that it does not allow you to start the service using:

# service start servicename


An alternative to this is to open the servicename.conf file in your favorite editor and comment out any lines that start with:
start on
That is, change this to

#start on ...
where the "..." is whatever was after "start on" previously. This way, when you want to re-enable it, you don't have to remember what the "start on"
parameters were.

Finally, if you have a new version of upstart you can simply add the word "manual" to the end of the configuration file. You can do this directly from the
shell:

# echo "manual" >> /etc/init/servicename.conf


This will cause upstart to ignore any "start on" phrases earlier in the file.

After vmware workstation install type:


apt-get update && apt-get upgrade
apt-get install build-essential linux-headers-uname r

You might also like