在 systemd 中禁用 init.d 腳本
我在 raspbian 安裝上將 init 系統從 sysvinit 更改為 systemd。安裝啟動正常,但現在在啟動時啟動 lightdm。我不希望它那樣做。
我注意到
lightdm.service
是在啟動時啟動的。停止服務
systemctl stop lightdm.service
工作正常。
systemctl disable lightdm.service
應該禁用它,但給了我
Failed to issue method call: No such file or directory
systemctl status lightdm.service
給我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
我假設 lightdm 是從 init.d 腳本而不是 systemd 腳本啟動的,並且
systemctl disable
如果源是 init.d 腳本則不起作用。我應該怎麼做才能從啟動時禁用 lightdm?編輯:更多資訊
輸出
$ 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
輸出
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
輸出
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
嘗試(以root身份):-
systemctl disable graphical.target
重新啟動後,您應該處於
multi-user
模式而不是graphical
.如果失敗,請檢查您的預設目標是什麼:-
ls -l /lib/systemd/system/default.target # or, depending on your distro ls -l /etc/systemd/system/default.target
請注意,路徑中的唯一區別是頂級目錄 - 要麼
/lib
要麼/etc
.上面應該是一個軟連結
multi-user.target
。如果它指向graphical.target
然後使用(作為根)更改它:-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
取決於在上一個
ls -l
命令中找到軟連結的位置。重新啟動,希望您的顯示管理器不會啟動。
要查看您有什麼目標,請執行:-
systemctl --all -t target
systemctl disable``init.d
如果源是腳本則不起作用。我應該怎麼做才能禁用lightdm
啟動時啟動?具有諷刺意味的是,到目前為止,任何答案都沒有提到這樣做的“官方”方式。因此,為了完整起見,它們是:
您“掩蓋”服務:
systemctl mask lightdm.service
或者,您創建自己的單元文件
/etc/systemd/system/lightdm.service
,然後成為適當的一流 systemd 公民,可以使用enable
anddisable
命令啟用和禁用。單元文件取代init.d
具有相同基本名稱的文件。lightdm.service
如果您願意,您可以對 Debian 人員編寫的內容進行暱稱。☺進一步閱讀
- Lennart Poettering (2011-03-02)。“關”的三個層次。 systemd 用於管理員。