Debian 10 настраивает сценарий автозапуска загрузки

1. Окружающая среда:

Операционная система: Debian GNU/Linux 10.

2. Способ 1: ~/.bashrc

Вы можете добавить скрипт для выполнения в конце ~/.bashrc.

3. Способ 2:/etc/profile

Сценарии можно добавлять для выполнения в конце /etc/profile.

4. Способ 3: rc.local

1. Проверьте, существует ли файл rc-local.service.Путь
: /lib/systemd/system/rc-local.serviceСодержимое
:

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

注:这里面就指出了可执行文件是 /etc/rc.local 。

2. Состояние по умолчанию

root@npi:/lib/systemd/system# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset:
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: inactive (dead)
     Docs: man:systemd-rc-local-generator(8)

注:因为没有 /etc/rc.local 这个文件,或者这个文件没有权限。

3. Создайте /etc/rc.local
(1) Напишите содержимое

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
  
exit 0

Примечание. Если существует какой-либо сценарий для включения запуска, его можно вставить перед выходом 0.

(2) Предоставьте разрешения на исполняемый файл

chmod +x /etc/rc.local

3. Запустите службу rc.local.

systemctl start rc.local

注:重启后服务会自动启动

4. Запросить статус после перезапуска.

root@npi:~# systemctl status rc.local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: active (exited) since Tue 2022-01-04 16:06:09 CST; 3min 51s ago
     Docs: man:systemd-rc-local-generator(8)
  Process: 367 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Jan 04 16:06:09 npi systemd[1]: Starting /etc/rc.local Compatibility...
Jan 04 16:06:09 npi systemd[1]: Started /etc/rc.local Compatibility.

注:验证确实有执行rc.local内的内容

おすすめ

転載: blog.csdn.net/weixin_38090079/article/details/131676944