On Debian-based systems, init.d scripts in /etc/init.d/
control service lifecycles through standardized commands:
sudo /etc/init.d/scriptname start|stop|restart|status
To run a service manually while preventing automatic startup:
# Example for Apache2
sudo update-rc.d -f apache2 remove
sudo /etc/init.d/apache2 start
For persistent changes across reboots:
Method 1: Using update-rc.d
# Disable
sudo update-rc.d servicename disable
# Re-enable later if needed
sudo update-rc.d servicename enable
Method 2: Systemd Compatibility Layer
# For systems with systemd but using sysvinit scripts
sudo systemctl disable servicename.service
sudo systemctl mask servicename.service # Stronger prevention
Confirm your changes took effect:
# Check runlevel links
ls -l /etc/rc*.d/ | grep servicename
# Verify boot behavior
sudo service servicename status
Complete workflow for MySQL management:
# Remove from startup
sudo update-rc.d mysql remove
# Manual control
sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop
# Temporary auto-start (for maintenance)
sudo update-rc.d mysql defaults
In Debian-based systems, traditional SysV init scripts located in /etc/init.d/
can be controlled through various mechanisms. The challenge arises when you want to:
- Prevent automatic execution during system boot
- Maintain the ability to manually start/stop the service
The most effective method involves modifying the service's runlevel configuration:
# First check current runlevel configuration
ls -l /etc/rc*.d/*servicename*
# To disable automatic startup for all runlevels
update-rc.d -f servicename remove
# Alternative method (Debian/Ubuntu)
systemctl disable servicename
After disabling auto-start, you can still manage the service manually:
# Start service manually
/etc/init.d/servicename start
# or
service servicename start
# Stop service manually
/etc/init.d/servicename stop
# or
service servicename stop
# Check status
/etc/init.d/servicename status
Let's demonstrate with Apache web server:
# Disable automatic startup
sudo update-rc.d -f apache2 remove
# Verify it won't start at boot
ls -l /etc/rc*.d/*apache2* # Should show no links
# Manual control remains available
sudo service apache2 start
sudo service apache2 stop
For systems with chkconfig installed:
# Disable auto-start
sudo chkconfig servicename off
# Manual control
sudo service servicename start
- Some services may have dependencies that need manual handling
- Changes persist across reboots
- Always verify service status after modifications
- For systemd systems, consider using
systemctl mask
instead