Panel For Example Panel For Example Panel For Example

Linux Boot Startup Methods

Author : Adrian September 15, 2025

1. System services

If a component is installed as a system service, the default service file is xxx.service and is stored in /usr/lib/systemd/system.

There are two common ways to configure auto-start at boot.

systemctl method

systemctl enable/disable xxx # enable or disable startup at boot --Check whether a service is enabled [root@localhost system]# systemctl status chronyd.service - chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-07-28 18:39 CST; 4 months 4 days ago Docs: man:chronyd(8) man:chrony.conf(5) Main PID: 790 (chronyd) Memory: 1.0M CGroup: /system.slice/chronyd.service └─790 /usr/sbin/chronyd systemctl list-unit-files # Use list-unit-files to see service enablement status. # To list only enabled services: systemctl list-unit-files --state=enabled # or systemctl is-enabled # To list only disabled services: systemctl list-unit-files --state=disabled # or systemctl is-enabled # --state can also be used with list-units; run: systemctl --state=help

chkconfig method (more complex)

chkconfig --add xxx && chkconfig --level 3 xxx on/off # This method requires the service script to be in /etc/init.d/, # and relies on the /etc/rc.d/rc0.d ~ rc6.d directories. The service # script must include the necessary header comments, so this method is more complex. --Check whether a service is enabled chkconfig --list network Note: This output only shows SysV services and does not include native systemd services. SysV configuration data may be overridden by native systemd configuration. To list systemd services, run 'systemctl list-unit-files'. To view services enabled for a specific target, run 'systemctl list-dependencies [target]'. network 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Important: what systemctl enable actually does

systemctl enable creates a symbolic link under /etc/systemd/system/xxx.wants/ or under /etc/systemd/user/ pointing to the .service file in /usr/lib/systemd/system. These locations represent system services and user services respectively.

[root@localhost ~]# systemctl enable mysqld Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

To disable auto-start you can do one of the following:

systemctl disable xxx # or remove the corresponding symlink or service file under /etc/systemd/system/ or /etc/systemd/user/

2. Generic methods

Whether or not a component is installed as a system service, you can implement boot startup via startup scripts.

Note: For all the following operations, set the script executable permission with chmod +x.

Method A: Append the startup command to the default startup script /etc/rc.local or /etc/rc.d/rc.local (the former is usually a symlink to the latter).

Method B: Create a startup script.sh and place it in /etc/profile.d.

Method C: Create a startup script.sh and append its execution command to /etc/rc.local or /etc/rc.d/rc.local.

3. crontab method

crontab supports special @keywords that replace the five time fields (minute, hour, day of month, month, day of week). These keywords are prefixed with @.

See the official documentation for details.

Syntax: @keyword command

@reboot : Run once after reboot. (Runs earlier than /etc/rc.d/rc.local in many cases) @yearly : Run once a year, i.e. "0 0 1 1 *". @annually : Run once a year, i.e. "0 0 1 1 *". @monthly : Run once a month, i.e. "0 0 1 * *". @weekly : Run once a week, i.e. "0 0 * * 0". @daily : Run once a day, i.e. "0 0 * * *". @hourly : Run once an hour, i.e. "0 * * * *".

You can use @reboot to implement boot startup. Example:

[root@localhost daemonProcess]# crontab -e # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * command to be executed # Run at boot @reboot /usr/local/daemonProcess/somescript.sh # Run every minute (daemon check) * * * * * /usr/local/daemonProcess/somescript.sh

Notes

Whether to use both @reboot and a periodic cron entry depends on your service behavior.

If the daemon cron is set to run every minute (* * * * *), avoid also using @reboot, because both may run within the first minute after boot and cause duplicate executions. If the application tolerates duplicate starts, this may be acceptable; otherwise choose a single approach.

If the periodic interval is relatively long, using @reboot in addition to the periodic cron is recommended to ensure timely startup after reboot.

4. Recommendation for production environments

For production systems, pick one consistent method for managing boot startup across all components and services. Uniformity simplifies operations when many services are deployed.

For example, some services do not automatically install a systemd service unit upon installation, so using only the systemctl method could leave gaps. If each component uses a different startup mechanism, diagnosing startup failures or service upgrades requires identifying each service's method, increasing operational overhead and the risk of errors.

Appendix: Example boot startup script

# Option 1: Append startup command to /etc/rc.local or /etc/rc.d/rc.local # Option 2: Create startup script and place in /etc/profile.d --- chmod +x /etc/rc.d/rc.local # Boot startup script /usr/local/AutoStartOnBoot.sh chmod +x /usr/local/AutoStartOnBoot.sh # This script depends on /etc/rc.d/rc.local # rc.local runs before environment variables are loaded, so source them manually: source /etc/profile # redis /usr/local/redis/redis-5.0.13/bin/redis-server /usr/local/redis/redis-5.0.13/conf/redis.conf # zookeeper # Remove zk PID file before starting rm -f /data/zookeeper/data/zookeeper_server.pid; /usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start # kafka JMX_PORT=9999 /usr/local/kafka_2.13-2.7.1/bin/kafka-server-start.sh -daemon /usr/local/kafka_2.13-2.7.1/config/server.properties # kafka-manager # Remove pid file before starting rm -f /usr/local/kafka-manager-2.0.0.2/RUNNING_PID nohup /usr/local/kafka-manager-2.0.0.2/bin/kafka-manager -Dconfig.file=/usr/local/kafka-manager-2.0.0.2/conf/application.conf -Dhttp.port=9002 >/dev/null 2>&1 & # mysql service mysqld start