Tuesday, February 26, 2013

Preventing upstart service from starting on every boot - Things I learned today

Being a curious linux user I have installed a lot of things, server on my system. Apache, tor, ssh, mysql, postgresql are all installed. Due to this reason there were so many ports open on my system that many of them I could't understand. This situation has serious security concerns. Take for example ssh, given the laptop password, anybody on the web can login and access my data without any notification to me. (I am looking for a software which notifies me of any incoming ssh connection. Leave that for some other time.) Today, I found a way to prevent so many daemon to start with the boot up.
PS: I hate installing even a small software for doing the same job as a simple terminal command.

To stop upstart jobs from initialization during boot, one need to override the starting configuration file store in /etc/init/ . In this folder , the specific run level at which these jobs are to be started is specified in their respective ****.conf files. To override any of these jobs , simply create a file with content "manual"  and give it an extension .override.

Example : To prevent mysql server to start :

cd /etc/init       #go to the folder containing start scripts
$ ls - l             # take time to look into the folder
$ sudo echo "manual" > mysql.override  #create a file mysql.override with content "manual"

Done !!

Restart the system and do a quick nmap/nc/telnet to find if the mysql port (3306) is running.
Now, to start the stopped service manually use the service command :

sudo service mysql start       #the service command to start mysql manually

Rollback : If you have disabled your upstart job, but now want to roll back simply delete the file .override (e.g. apache2.override) from the folder /etc/init/ .

System information : The above instructions are tested upon Ubuntu 12.10 but shall be valid for most of the linux distros. If this does not work on your system, mention your system info in the comments as it shall help others.