设置Debian不自动启动新安装的服务

设置方法

  • root用户
1
2
echo exit 101 > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
  • 其他有sudo权限的用户
1
2
echo exit 101 | sudo tee /usr/sbin/policy-rc.d
sudo chmod +x /usr/sbin/policy-rc.d
  • 以安装vsftpd为例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
root@myLaptop:~# echo exit 101 > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
root@myLaptop:~# apt install vsftpd

将要安装:
vsftpd

摘要:
升级:0,安装:1,卸载:0,不升级:9
下载大小:142 kB
所需的空间:352 kB / 131 GB 可用

获取:1 https://mirrors.tuna.tsinghua.edu.cn/debian sid/main amd64 vsftpd amd64 3.0.3-13.1 [142 kB]
已下载 142 kB,耗时 0秒 (289 kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 vsftpd。
(正在读取数据库 ... 系统当前共安装有 799342 个文件和目录。)
准备解压 .../vsftpd_3.0.3-13.1_amd64.deb ...
正在解压 vsftpd (3.0.3-13.1) ...
正在设置 vsftpd (3.0.3-13.1) ...
Created symlink '/etc/systemd/system/multi-user.target.wants/vsftpd.service''
/usr/lib/systemd/system/vsftpd.service'.
/usr/lib/tmpfiles.d/vsftpd.conf:1: Line references path below legacy directory /
var/run/, updating /var/run/vsftpd/empty → /run/vsftpd/empty; please update the
tmpfiles.d/ drop-in file accordingly.
invoke-rc.d: policy-rc.d denied execution of start.
正在处理用于 man-db (2.13.0-1) 的触发器 ...
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

Restarting services...
Service restarts being deferred:
systemctl restart sddm.service

No containers need to be restarted.

User sessions running outdated binaries:
duzhuo @ session #3: cinnamon-launch[6978]

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@myLaptop:~# systemctl status vsftpd
○ vsftpd.service - vsftpd FTP server
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; preset: e>
Active: inactive (dead)

相关阅读

~jpetazzo/Use policy-rc.d to prevent services from starting automatically

debian-policy/starting-system-services