Master Linux Autostart: Manage Runlevels, Add & Remove Services Easily
This guide explains Linux autostart services, the runlevel system, how to add or remove services via init scripts, rc.d directories, rc.local, and chkconfig, and details the purpose of each of the seven runlevels for effective system management.
Autostart services are crucial for Linux systems, whether you need to add a service manually, remove an unwanted one, or eliminate malicious entries.
The runlevel mechanism is implemented through the directories /etc/rc.d/rc0.d … /etc/rc.d/rc6.d, each representing one of the seven Linux runlevels defined in /etc/inittab. When the system enters a runlevel, it processes the scripts in the corresponding rcN.d directory in lexical order.
Each entry in rcN.d is a symbolic link to a script in /etc/init.d. The naming convention uses a leading K (kill) or S (start) followed by a two‑digit order number and the service name, e.g., K20network or S99apache.
The seven runlevels are:
0 – Halt
1 – Single‑user mode (root only, no remote login)
2 – Multi‑user without NFS
3 – Standard multi‑user, command‑line
4 – Reserved
5 – Multi‑user with graphical interface
6 – Reboot
Servers typically run at level 3.
Adding an autostart program
1. Create a script in /etc/init.d. Example for SVN:
#!/bin/bash
svnserve -d -r /svn仓库路径2. Make it executable: chmod 755 /etc/init.d/svn 3. Link it into the desired runlevel directory, e.g., level 3: ln -s /etc/init.d/svn /etc/rc.d/rc3.d/S101svn The S prefix indicates the script should be started, and the number (101) defines the execution order; values greater than 60 ensure basic services start first.
2. Alternatively, add commands to /etc/rc.local, which runs after all runlevel scripts.
3. The chkconfig command can also manage services.
Disabling an autostart program
Delete the corresponding link in /etc/rc.d/rcN.d.
Remove entries from /etc/rc.local.
Use chkconfig --list to view services and chkconfig --del <service_name> to disable them.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
