Linux setup program starts automatically at boot

In Linux, there are several ways to set applications to start automatically at boot time. Here are some commonly used methods:

Startup script (init.d/rc.d):

In the traditional SysV init system, you can create startup scripts under the /etc/init.d/ directory and use the chkconfig or update-rc.d commands to add them to the runlevel. These scripts are responsible for starting, stopping and managing services. For example, to add an application named myapp to the boot startup, run the following command:

sudo cp /path/to/myapp /etc/init.d/
sudo chmod +x /etc/init.d/myapp
sudo update-rc.d myapp defaults

Systemd unit file:

In modern Linux distributions, Systemd is the main init system. You create a Systemd unit file (usually with a .service extension) that describes how your application starts and its dependencies. Place the unit file in the /etc/systemd/system/ directory, then use the systemctl command to enable and start the service. For example:

sudo systemctl enable myapp.service
sudo systemctl start myapp.service

User-level autostart:

If you want an application to start automatically when the user logs in, you can add the start command to the user's profile, such as ~/.bashrc, ~/.bash_profile, or ~/.profile. Note that this will only start the application after the user logs in, not when the system is powered on.

cron job:

You can also use the cron scheduler to automatically run applications after system boot . Edit the user's crontab file, add a @reboot job, and specify the command to execute in it. For example:

@reboot /path/to/myapp

GUI tools:

Some Linux distributions provide GUI tools that can be used to manage startup applications. For example, there is a "Startup Applications Preferences" tool in Ubuntu, which can add and configure automatic startup applications.

Note that the correct boot method depends on the Linux distribution and init system you are using . It is recommended to consult your distribution documentation for detailed instructions. Whichever method you use, make sure you have sufficient privileges to modify the system configuration, and proceed with caution to avoid system problems.

Guess you like

Origin blog.csdn.net/fuhanghang/article/details/132694090