Linux Enabling / Disabling a init.d service

Enabling / Disabling a service

To toggle a service from starting or stopping permanently you would need to:

echo manual | sudo tee /etc/init/SERVICE.override

where the stanza manual will stop Upstart from automatically loading the service on next boot. Any service with the .override ending will take precedence over the original service file. You will only be able to start the service manually afterwards. If you do not want this then simply delete the .override. For example:

echo manual | sudo tee /etc/init/mysql.override

Will put the MySQL service into manual mode. If you do not want this, afterwards you can simply do

sudo rm /etc/init/mysql.override

and Reboot for the service to start automatically again. Of course to enable a service, the most common way is by installing it. If you install Apache, Nginx, MySQL or others, they automatically start upon finishing installation and will start every time the computer boots. Disabling, as mentioned above, will make use of the service manual.

Temporary enabling/disabling services

To stop and start services temporarily (Does not enable / disable them for future boots), you can type service SERVICE_NAME. For example:

  • sudo service apache2 stop (Will STOP the Apache service until Reboot or until you start it again).
  • sudo service apache2 start (Will START the Apache service assuming it was stopped before.).
  • service apache2 status (Will tell you the STATUS of the service, if it is either enabled/running of disabled/NOT running.).
  • sudo service apache2 restart (Will RESTART the service. This is most commonly used when you have changed, a config file. In this case, if you changed either a PHP configuration or an Apache configuration. Restart will save you from having to stop/start with 2 command lines)
  • service apache2 (In this case, since you did not mention the ACTION to execute for the service, it will show you all options available for that specific service.) This aspect varies depending on the service, for example, with MySQL it would only mention that it is missing a parameter. For other services like networking service it would mention the small list of all options available.

Posted on

How can I find all file extensions types in a folder or subfolder hierarchy

It work as following:

  • Find all files from current folder
  • Prints extension of files if any
  • Make a unique sorted list
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

Or by using awk

find . -type f | awk -F. '!a[$NF]++{print $NF}'

You can also use git as follow

git ls-tree -r HEAD --name-only | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

This is should be better than naive find, because:

  • it excludes untracked (gitignored) files
  • it excludes .git directory which contains usually hundreds/thousands of files and hence slows down the search

If you still haven’t upgraded to Linux from Shitdows, then the powershell command looks like this (powershell not cmd (Command promt)):

dir -recurse | select-object extension -unique

Posted on