In this tutorial we will learn, how to prevent starting service after package installation on Ubuntu / Debian . In simple way, we will use the policy.rc.d to control the behavior of
invoke-rc.d for every initscript id and action .

We will create a executable script called policy.rc.d and write the exit code 101 in it.

If you are wondering what is exit 101 , so here is the answer.
Exit status code 101 means action forbidden by policy.

Why want to prevent starting of service after its package installation ?
The reason is – for eg. if we install apache2 in system, it will automatically get started after installation. But we do not want to start apache2 after installation. Similarly there are other services which should not not start when we install their related packages.

How to prevent starting service after package installation

1. Create policy.rc.d executable file.

vi /usr/sbin/policy-rc.d 

Write the below given exit status in policy.rc.d file

#!/bin/sh
exit 101

Save and exit.

2. Make the file /usr/sbin/policy-rc.d executable.

chmod +x /usr/sbin/policy-rc.d

yes, that’s it. We have completed our task.

Now try installing any one of the package like, apache2,nginx,mysql,mariadb etc. After installation , their services will not start.

Given below is reference from our system when we install apache2 package. We are sharing only tail output of apt-get install apache2 php5-fpm command.
In below given output, you can read that policy.rc.d denied execution of restart.

invoke-rc.d: policy-rc.d denied execution of restart.
apache2_invoke: Enable module php5
invoke-rc.d: policy-rc.d denied execution of restart.
Processing triggers for libc-bin (2.19-0ubuntu6.4) ...
Processing triggers for php5-fpm (5.5.9+dfsg-1ubuntu4.6) ...
invoke-rc.d: policy-rc.d denied execution of restart.
invoke-rc.d: policy-rc.d denied execution of start.

Reference : Read more about policy.rc.d

Read Some More Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.