Set the program to start automatically in the Ubuntu environment

This article introduces the method of booting self-starting in the Ubuntu environment, which is mainly divided into self-starting of non-GUI programs and self-starting of GUI programs.

1. Self-starting of non-GUI programs

Here we mainly introduce the method of adding system services

sudo touch /lib/systemd/system/your_service_name.service
sudo vi your_service_name.service

Add in your_service_name.service:

[Unit]
; After=network.target
Description="your_service_description"
[Service]
ExecStart=your_script_name.sh
User=your_user_name
[Install]
WantedBy=multi-user.target

The main explanation is as follows:

After: Indicates that it needs to run after a certain service, if not, you can delete this line.

Description: A description of the service.

ExecStart: The name of the script that needs to be executed, and the absolute path needs to be given here.

User: Username, the user needs to have permission to execute scripts.

After modification, increase execution permission:

sudo chmod u+x your_service_name.service

After the above command is executed, you need to reload the service, execute:

sudo systemctl daemon-reload

To start your own service, execute:

sudo systemctl start your_service_name

At this point, you can see the execution result of the service.

To end your own service, execute:

sudo systemctl stop your_service_name

To view the current status of the service, execute:

sudo systemctl status your_service_name

After the test is completed and can run normally, you need to enable execution every time you start:

sudo systemctl enable your_service_name

If you don't want to execute it every time you start it, you can run:

sudo systemctl disable your_service_name

2. Self-starting of GUI program

There are mainly two methods to make the GUI program start automatically at boot.

1) Method 1

Method 1 is the easiest method. After booting up and entering the interface, execute:

a) Press Alt+F2

The "Enter a Command" command box pops up, enter "gnome-session-properties", and press Enter.

b) Increase the program that needs to be started automatically after booting

Click "Add" and enter the interface program or script that we need to start automatically after booting.

2) Method 2

Method 2 is the command line method, and the setting is relatively simple.

cd ~
vi .xsessionrc

Add the program or script we need to start automatically at the end of ".xsessionrc" (or .xinitrc), and save it.

Guess you like

Origin blog.csdn.net/propor/article/details/130871521