disable init.d script in systemd

Mar*_*ijn 13 debian systemd init.d raspbian

I changed the init system from sysvinit to systemd on a raspbian installation. The install boots fine, but now starts lightdm on boot. I don't want it to do that.

I noticed lightdm.service is started on boot. Stopping the service with

systemctl stop lightdm.service

works fine.

systemctl disable lightdm.service should disable it, but gives me

Failed to issue method call: No such file or directory

systemctl status lightdm.service gives me

lightdm.service - LSB: Light Display Manager
      Loaded: loaded (/etc/init.d/lightdm)
      Active: inactive (dead) since Thu, 03 Jul 2014 09:33:00 +0000; 22min ago
     Process: 762 ExecStop=/etc/init.d/lightdm stop (code=exited, status=0/SUCCESS)
     Process: 411 ExecStart=/etc/init.d/lightdm start (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/lightdm.service
Run Code Online (Sandbox Code Playgroud)

I'm assuming that lightdm is started from an init.d script rather than a systemd script, and systemctl disable doesn't work if the source is an init.d script. What should I do instead to disable lightdm starting at boot?

edit: More info

output of $ ls -l /etc/systemd/system:

total 20
lrwxrwxrwx 1 root root   42 Jul  3 09:04 dbus-fi.epitest.hostap.WPASupplicant.service -> /lib/systemd/system/wpa_supplicant.service
lrwxrwxrwx 1 root root   37 Jul  3 13:03 default.target -> /lib/systemd/system/multi-user.target
drwxr-xr-x 2 root root 4096 Jul  3 09:00 getty.target.wants
drwxr-xr-x 2 root root 4096 Jul  3 09:04 graphical.target.wants
drwxr-xr-x 2 root root 4096 Oct 11  2013 local-fs.target.wants
drwxr-xr-x 2 root root 4096 Jul  3 09:04 multi-user.target.wants
drwxr-xr-x 2 root root 4096 Oct 11  2013 sysinit.target.wants
lrwxrwxrwx 1 root root   35 Mar 20  2013 syslog.service -> /lib/systemd/system/rsyslog.service
Run Code Online (Sandbox Code Playgroud)

output of systemctl --all -t target:

UNIT                LOAD   ACTIVE   SUB    JOB DESCRIPTION
all.target          error  inactive dead       all.target
basic.target        loaded active   active     Basic System
cryptsetup.target   loaded active   active     Encrypted Volumes
emergency.target    loaded inactive dead       Emergency Mode
final.target        loaded inactive dead       Final Step
getty.target        loaded active   active     Login Prompts
local-fs-pre.target loaded active   active     Local File Systems (Pre)
local-fs.target     loaded active   active     Local File Systems
multi-user.target   loaded active   active     Multi-User
network.target      loaded inactive dead       Network
nss-lookup.target   loaded inactive dead       Name Lookups
remote-fs.target    loaded active   active     Remote File Systems
rescue.target       loaded inactive dead       Rescue Mode
shutdown.target     loaded inactive dead       Shutdown
sockets.target      loaded active   active     Sockets
sound.target        loaded active   active     Sound Card
swap.target         loaded active   active     Swap
sysinit.target      loaded active   active     System Initialization
syslog.target       loaded active   active     Syslog
time-sync.target    loaded inactive dead       System Time Synchronized
umount.target       loaded inactive dead       Unmount All Filesystems
Run Code Online (Sandbox Code Playgroud)

output of ls -l /etc/systemd/system/multi-user.target.wants/:

total 8
drwxr-xr-x 2 root root 4096 Jul  3 09:04 .
drwxr-xr-x 7 root root 4096 Jul  3 13:03 ..
lrwxrwxrwx 1 root root   36 Oct 11  2013 remote-fs.target -> /lib/systemd/system/remote-fs.target
lrwxrwxrwx 1 root root   33 Jul  3 09:04 rsync.service -> /lib/systemd/system/rsync.service
lrwxrwxrwx 1 root root   35 Mar 20  2013 rsyslog.service -> /lib/systemd/system/rsyslog.service
lrwxrwxrwx 1 root root   32 Jul  3 09:04 sudo.service -> /lib/systemd/system/sudo.service
lrwxrwxrwx 1 root root   42 Jul  3 09:04 wpa_supplicant.service -> /lib/systemd/system/wpa_supplicant.service
Run Code Online (Sandbox Code Playgroud)

Jde*_*eBP 9

systemctl disable如果源是init.d脚本,则不起作用。我应该怎么做才能禁用lightdm启动时启动?

具有讽刺意味的是,到目前为止,在任何答案中都没有提到这样做的“官方”方法。因此,为了完整起见,它们是:

你“屏蔽”了服务:

systemctl mask lightdm.service
Run Code Online (Sandbox Code Playgroud)

或者你创建一个你自己的单元文件/etc/systemd/system/lightdm.service,然后它就成为一个合适的一流 systemd 公民,可以用enable和disable命令启用和禁用。单元文件取代init.d具有相同基名的文件。lightdm.service如果您愿意,您可以删除由 Debian 人员编写的程序。☺

进一步阅读

  • Lennart Poettering (2011-03-02)。“关”的三个层次。 systemd 供管理员使用。


gar*_*Red 5

尝试(以root身份):-

systemctl disable graphical.target
Run Code Online (Sandbox Code Playgroud)

重新启动后,您应该处于multi-usermode 而不是graphical。

如果失败,请检查您的默认目标是什么:-

ls -l /lib/systemd/system/default.target
# or, depending on your distro
ls -l /etc/systemd/system/default.target
Run Code Online (Sandbox Code Playgroud)

请注意,路径的唯一区别是顶级目录 -/lib或/etc.

上面应该是软链接multi-user.target。如果它指向graphical.target然后使用(作为root)更改它:-

ln -sf /lib/systemd/system/multi-user.target /lib/systemd/system/default.target
# or
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
Run Code Online (Sandbox Code Playgroud)

取决于在上一个ls -l命令中找到软链接的位置。

重新启动,希望您的显示管理器不会启动。

要查看您有哪些目标,请运行:-

systemctl --all -t target
Run Code Online (Sandbox Code Playgroud)