Merge tag 'upstream/1.1' into debian-debian
[pksunkara-service-disable.git] / service-disable
blob4dfd3ce4240c3aeff13658cf5a3ae47ef3422ce7
1 #!/bin/sh
3 # Abort immediately if any command exists with a non-zero code.
4 set -e
6 # Do we need 'sudo'?
7 sudo=
8 if [ "$( id -u )" != 0 ]; then
9 sudo='sudo'
12 # Parse command-line options.
13 while getopts 'h' option; do
14 case "$option" in
16 cat <<-HELP
17 Usage:
18 $( basename "$0" ) [...OPTIONS] [...service]
20 Options:
21 -h Print script usage and exit.
23 Arguments:
24 service The service name, e.g., 'apache2', 'mysql', etc.
25 HELP
26 exit 1
28 esac
29 done
31 # Drop parsed options from script input.
32 shift $((OPTIND-1))
34 # Ensure we can manage services and System-V init scripts.
35 if ! which service 1>/dev/null 2>&1 || ! which update-rc.d 1>/dev/null 2>&1; then
36 echo '[WARN] You need to be running a Debian-based system with System-V support.' 1>&2
37 echo '[WARN] Aborting before any real damage is done.' 1>&2
38 exit 1
41 for service in "$@"; do
42 # Stop the service, if it's running.
43 echo -n "[STOP] '$service'... "
44 $sudo service "$service" stop 1>/dev/null 2>&1 || :
45 echo 'OK'
47 # If the legacy System-V style init script is used, purge it from the system.
48 # The file remains in /etc/init.d/, but not in any of /etc/rcN.d/ so the service won't start on boot.
49 echo -n "[DISABLE] '$service' rc.d initscript... "
50 $sudo update-rc.d -f "$service" remove 1>/dev/null
51 echo 'OK'
53 # If Upstart is used, use an override to set the service job in 'manual' mode.
54 # See http://upstart.ubuntu.com/cookbook/#manual
55 if [ -f "/etc/init/${service}.conf" ]; then
56 echo -n "[DISABLE] '$service' Upstart script... "
57 if ! grep 'manual' "/etc/init/${service}.override" 1>/dev/null 2>&1; then
58 echo 'manual' | $sudo tee -a "/etc/init/${service}.override" 1>/dev/null
60 echo 'OK'
62 done