3 # Abort immediately if any command exists with a non-zero code.
8 if [ "$( id -u )" != 0 ]; then
12 # Parse command-line options.
13 while getopts 'h' option
; do
18 $( basename "$0" ) [...OPTIONS] [...service]
21 -h Print script usage and exit.
24 service The service name, e.g., 'apache2', 'mysql', etc.
31 # Drop parsed options from script input.
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
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 ||
:
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
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