关于systemd 和debian8上的samba服务

debian8
systemctl start smbd 后, systemctl list-units --all --type=service |grep smbd 搜索到 smbd.service
systemctl stop smbd 后,systemctl list-unit-files --all --type=service |grep smbd 搜索不到 smbd.service

哪个大神知道是什么原因?

[quote=“poloshiao”]摘要 只能當補充說明
請把 原始完整指令 及 終端機回應文字
全部複製 貼上來[/quote]

执行以下指令将结果全部复制贴上来,不要节选

systemctl start smbd
systemctl list-units --all --type=service | grep smbd
systemctl list-unit-files --all --type=service | grep smbd

systemctl stop smbd
systemctl list-units --all --type=service | grep smbd
systemctl list-unit-files --all --type=service | grep smbd

czj@debian:~$ sudo systemctl start smbd czj@debian:~$ systemctl list-units --all --type=service | grep smbd smbd.service loaded active running LSB: start Samba SMB/CIFS daemon (smbd) czj@debian:~$ systemctl list-unit-files --all --type=service | grep smbd czj@debian:~$ sudo systemctl stop smbd czj@debian:~$ systemctl list-units --all --type=service | grep smbd czj@debian:~$ systemctl list-unit-files --all --type=service | grep smbd czj@debian:~$ czj@debian:~$ czj@debian:~$ czj@debian:~$
systemctl list-units --all --type=service 列出系统当前活动的服务,所以 systemctl start smbd 后systemctl list-units --all --type=service | grep smbd 有结
果 ,stop 服务后 systemctl list-units --all --type=service | grep smbd 没结果。正常。

但systemctl list-unit-files --all --type=service 是列出所有安装的服务,不管有无活动,所以即使服务没有active 也应该检索到。

在redhat7 上 不管smb有无启动 systemctl list-unit-files --all --type=service | grep smbd 都有结果

在redhat7上 所有所有服务都在 /usr/lib/systemd/system

[root@web ~]# systemctl start smb [root@web ~]# systemctl status smb smb.service - Samba SMB Daemon Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled)

debian8/usr/lib/systemd/目录下没有system目录
smbd服务还是通过 /etc/init.d/smbd 启动的

所以可能systemctl list-unit-files 检索的是/usr/lib/systemd/system目录。

Debian 对应的目录为 /lib/systemd/system

Debian 的 systemd 检索单元文件的位置为

`pkg-config systemd --variable=systemdsystemunitdir` /usr/local/lib/systemd/system /lib/systemd/system

Debian 8 的 samba (2:4.2.10+dfsg-0+deb8u3) 未提供 systemd 单元文件。
将由 systemd-sysv-generator 生成的单元文件作为 “generated” 类型列出是 systemd 230 新添加的功能。Debian 8 的 systemd 215 无此功能。

类似的,apache2 亦不提供 systemd 单元文件。在 Debian stretch/sid 中可获如下输出:

[code]$ systemd --version
systemd 231
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

$ systemctl list-unit-files | grep apache2
apache2.service generated

$ systemctl status apache2
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; generated; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─forking.conf
Active: active (running) since Thu 2016-09-01 16:31:24 HKT; 1 weeks 6 days ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/apache2.service
├─14514 /usr/sbin/apache2 -k start
├─30198 /usr/sbin/apache2 -k start
└─30199 /usr/sbin/apache2 -k start

$ systemctl list-unit-files | grep generat
-.mount generated
boot-efi.mount generated
home.mount generated
media-usb0.mount generated
media-usb1.mount generated
apache-htcacheclean.service generated
apache2.service generated
atop.service generated
exim4.service generated
hddtemp.service generated
hostapd.service generated
irqbalance.service generated
minidlna.service generated
speech-dispatcher.service generated
sysfsconf.service generated
sysfsutils.service generated
vboxdrv.service generated
virtualbox.service generated
dev-disk-by\x2duuid-75c…x2d9d1c\x2d48d2\x2d8bae\x2de54fc8a296ac.swap generated
dev-sda5.swap generated
[/code]

参考
github.com/systemd/systemd/blob/master/NEWS#L509
freedesktop.org/software/systemd/man/systemd-sysv-generator.html

多谢指教!