Source: http://unix.stackexchange.com/a/164028/120177 ,http://www.freedesktop.org/software/systemd/man/systemctl.html
Open a terminal and (as root) run:
systemctl set-default multi-user.target
or with --force
systemctl set-default -f multi-user.target
to overwrite any existing conflicting symlinks1.
Double-check with:
systemctl get-default
Another way is to add the following parameter to your kernel boot line:
systemd.unit=multi-user.target
rc3.d /etc/inittab with systemd_________________________________________________________________________________
source bellow http://www.dynacont.net/documentation/linux/Useful_SystemD_commands/
List all running services
# systemctl
Start/stop or enable/disable services
Activates a service immediately:
# systemctl start foo.service
Deactivates a service immediately:
# systemctl stop foo.service
Restarts a service:
# systemctl restart foo.service
Shows status of a service including whether it is running or not:
# systemctl status foo.service
Enables a service to be started on bootup:
# systemctl enable foo.service
Disables a service to not start during bootup:
# systemctl disable foo.service
Check whether a service is already enabled or not:
# systemctl is-enabled foo.service; echo $?
0 indicates that it is enabled. 1 indicates that it is disabled
How do I change the runlevel?
systemd has the concept of targets which is a more flexible replacement for runlevels in sysvinit.
Run level 3 is emulated by multi-user.target. Run level 5 is emulated by graphical.target. runlevel3.target is a symbolic link to multi-user.target and runlevel5.target is a symbolic link to graphical.target.
You can switch to ‘runlevel 3′ by running
# systemctl isolate multi-user.target (or) systemctl isolate runlevel3.target
You can switch to ‘runlevel 5′ by running
# systemctl isolate graphical.target (or) systemctl isolate runlevel5.target
How do I change the default runlevel?
systemd uses symlinks to point to the default runlevel. You have to delete the existing symlink first before creating a new one
# rm /etc/systemd/system/default.target
Switch to runlevel 3 by default
# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
Switch to runlevel 5 by default
# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
systemd does not use /etc/inittab file.
List the current run level
runlevel command still works with systemd. You can continue using that however runlevels is a legacy concept in systemd and is emulated via ‘targets’ and multiple targets can be active at the same time. So the equivalent in systemd terms is
# systemctl list-units --type=target
Powering off the machine
You can use
# poweroff
Some more possibilities are:
halt -p
, init 0
, shutdown -P now
Note that
halt
used to work the same as poweroff
in previous Fedora releases, but systemd distinguishes between the two, so halt
without parameters now does exactly what it says – it merely stops the system without turning it off.Service vs. systemd
# service NetworkManager stop
(or)
# systemctl stop NetworkManager.service
Chkconfig vs. systemd
# chkconfig NetworkManager off
(or)
# systemctl disable NetworkManager.service
Readahead
systemd has a built-in readahead implementation is not enabled on upgrades. It should improve bootup speed but your mileage may vary depending on your hardware. To enable it:
# systemctl enable systemd-readahead-collect.service # systemctl enable systemd-readahead-replay.service
SystemD cheatsheet
service foobar start | systemctl start foobar.service | Used to start a service (not reboot persistent) |
service foobar stop | systemctl stop foobar.service | Used to stop a service (not reboot persistent) |
service foobar restart | systemctl restart foobar.service | Used to stop and then start a service |
service foobar reload | systemctl reload foobar.service | When supported, reloads the config file without interrupting pending operations. |
service foobar condrestart | systemctl condrestart foobar.service | Restarts if the service is already running. |
service foobar status | systemctl status foobar.service | Tells whether a service is currently running. |
ls /etc/rc.d/init.d/ | ls /lib/systemd/system/*.service /etc/systemd/system/*.service | Used to list the services that can be started or stopped |
chkconfig foobar on | systemctl enable foobar.service | Turn the service on, for start at next boot, or other trigger. |
chkconfig foobar off | systemctl disable foobar.service | Turn the service off for the next reboot, or any other trigger. |
chkconfig foobar | systemctl is-enabled foobar.service | Used to check whether a service is configured to start or not in the current environment. |
chkconfig foobar –list | ls /etc/systemd/system/*.wants/foobar.service | Used to list what levels this service is configured on or off |
chkconfig foobar –add | Not needed, no equivalent. |
References
END
_______________________________________________________________________________
Software/systemd/TipsAndTricks
Up
Edit
View
Diffs
Info
Subscribe
Raw
Tips & Tricks
Also check out the Frequently Asked Questions!
Listing running services
$ systemctl
UNIT LOAD ACTIVE SUB JOB DESCRIPTION
messagebus.service loaded active running messagebus.service
basic.target loaded active active Basic System
sysinit.target loaded active active Systemd Initialization
local-fs.target loaded active active Local File Systems
swap.target loaded active active Swap
sockets.target loaded active active Sockets
...
Showing runtime status
$ systemctl status udisks.service
udisks.service - udisks Disk Manager
Loaded: loaded (/etc/systemd/system/multi-user.target.wants/../udisks.service)
Active: active (running)
Process: 999 (udisks-daemon)
CGroup: name=systemd:/systemd-1/udisks.service
│
├ 999 /usr/libexec/udisks-daemon
├ 1018 udisks-daemon: polling /dev/sr0
└ 1132 /usr/libexec/udisks-daemon
cgroup tree
The tree tool is very handy to list the tree of control groups:
$ tree -d /cgroup/systemd/
/cgroup/systemd/
├── systemd-1
│ ├── abrtd.service
│ ├── accounts-daemon.service
│ ├── acpid.service
...
│ ├── crond.service
│ ├── cups.service
│ ├── getty@.service
│ │ ├── tty1
│ │ ├── tty3
│ │ ├── tty4
│ │ ├── tty5
│ │ └── tty6
│ ├── haldaemon.service
│ ├── mdmonitor.service
│ ├── messagebus.service
...
│ ├── udisks.service
│ ├── upowerd.service
│ └── wpa_supplicant.service
└── user
└── lennart
├── 1
└── 2
38 directories
ps with cgroups
$ alias psc='ps xawf -eo pid,user,cgroup,args'
$ psc
PID USER CGROUP COMMAND
...
1 root name=systemd:/systemd-1 /bin/systemd systemd.log_target=kmsg systemd.log_level=debug selinux=0
415 root name=systemd:/systemd-1/sysinit.service /sbin/udevd -d
928 root name=systemd:/systemd-1/atd.service /usr/sbin/atd -f
930 root name=systemd:/systemd-1/ntpd.service /usr/sbin/ntpd -n
932 root name=systemd:/systemd-1/crond.service /usr/sbin/crond -n
935 root name=systemd:/systemd-1/auditd.service /sbin/auditd -n
943 root name=systemd:/systemd-1/auditd.service \_ /sbin/audispd
964 root name=systemd:/systemd-1/auditd.service \_ /usr/sbin/sedispatch
937 root name=systemd:/systemd-1/acpid.service /usr/sbin/acpid -f
941 rpc name=systemd:/systemd-1/rpcbind.service /sbin/rpcbind -f
944 root name=systemd:/systemd-1/rsyslog.service /sbin/rsyslogd -n -c 4
947 root name=systemd:/systemd-1/systemd-logger.service /lib/systemd/systemd-logger
950 root name=systemd:/systemd-1/cups.service /usr/sbin/cupsd -f
955 dbus name=systemd:/systemd-1/messagebus.service /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation
969 root name=systemd:/systemd-1/getty@.service/tty6 /sbin/mingetty tty6
970 root name=systemd:/systemd-1/getty@.service/tty5 /sbin/mingetty tty5
971 root name=systemd:/systemd-1/getty@.service/tty1 /sbin/mingetty tty1
973 root name=systemd:/systemd-1/getty@.service/tty4 /sbin/mingetty tty4
974 root name=systemd:/user/lennart/2 login -- lennart
1824 lennart name=systemd:/user/lennart/2 \_ -bash
975 root name=systemd:/systemd-1/getty@.service/tty3 /sbin/mingetty tty3
988 root name=systemd:/systemd-1/polkitd.service /usr/libexec/polkit-1/polkitd
994 rtkit name=systemd:/systemd-1/rtkit-daemon.service /usr/libexec/rtkit-daemon
...
Changing the Default Boot Target
$ ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
This line makes the multi user target (i.e. full system, but no graphical UI) the default target to boot into. This is kinda equivalent to setting runlevel 3 as the default runlevel on Fedora/sysvinit systems.
$ ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
This line makes the graphical target (i.e. full system, including graphical UI) the default target to boot into. Kinda equivalent to runlevel 5 on fedora/sysvinit systems. This is how things are shipped by default.
cgroup tree
$ systemd-cgls
├ 2 [kthreadd]
[...]
├ 29167 [flush-253:0]
├ user
│ └ lennart
│ ├ 39
│ │ ├ 29075 sshd: lennart [priv]
│ │ ├ 29079 sshd: lennart@pts/0
│ │ ├ 29080 -bash
│ │ └ 29168 systemd-cgls
│ └ 1
│ ├ 1141 login -- lennart
│ ├ 1532 -bash
│ ├ 1615 ssh-agent
│ └ 1641 gpg-agent --daemon --write-env-file
└ systemd-1
├ 1 /bin/systemd systemd.log_target=kmsg systemd.log_level=debug selinux=0
├ sshd@.service
│ └ 4
├ prefdm.service
│ └ 1272 /usr/sbin/gdm-binary -nodaemon
├ systemd-logger.service
│ └ 1162 /lib/systemd/systemd-logger
├ getty@.service
│ ├ tty3
│ │ └ 1148 /sbin/mingetty tty3
│ ├ tty2
│ ├ tty4
│ │ └ 1136 /sbin/mingetty tty4
│ ├ tty5
│ │ └ 1132 /sbin/mingetty tty5
│ └ tty6
│ └ 1125 /sbin/mingetty tty6
├ mdmonitor.service
│ └ 1194 mdadm --monitor --scan -f --pid-file=/var/run/mdadm/mdadm.pid
├ irqbalance.service
│ └ 1171 irqbalance
├ sendmail.service
│ ├ 1430 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
│ └ 1434 sendmail: accepting connections
├ accounts-daemon.service
│ └ 994 /usr/libexec/accounts-daemon
├ polkitd.service
│ └ 986 /usr/libexec/polkit-1/polkitd
├ wpa_supplicant.service
│ └ 981 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u
├ bluetooth.service
│ └ 980 /usr/sbin/bluetoothd -n
├ udisks.service
│ ├ 978 /usr/libexec/udisks-daemon
│ └ 993 udisks-daemon: polling /dev/sr0
├ dbus.service
│ └ 1010 /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation
├ auditd.service
│ ├ 975 /sbin/auditd -n
│ ├ 988 /sbin/audispd
│ └ 997 /usr/sbin/sedispatch
├ console-kit-daemon.service
│ └ 971 /usr/sbin/console-kit-daemon --no-daemon
├ rsyslog.service
│ └ 969 /sbin/rsyslogd -n -c 4
├ rtkit-daemon.service
│ └ 968 /usr/libexec/rtkit-daemon
├ haldaemon.service
│ ├ 967 /usr/sbin/hald --daemon=no --use-syslog
│ ├ 1014 hald-runner
│ ├ 1275 hald-addon-input: Listening on /dev/input/event3 /dev/input/event7 /dev/input/event6 /dev/input/event1 /dev/input/event4 /dev/input/event2 /dev/input/event0 /dev/input/event9
│ ├ 1281 /usr/libexec/hald-addon-rfkill-killswitch
│ ├ 1299 /usr/libexec/hald-addon-leds
│ ├ 1301 /usr/libexec/hald-addon-generic-backlight
│ └ 1308 /usr/libexec/hald-addon-acpi
├ upowerd.service
│ └ 966 /usr/libexec/upowerd
├ abrtd.service
│ └ 963 /usr/sbin/abrtd -d -s
├ rpcbind.service
│ └ 961 /sbin/rpcbind -f
├ cups.service
│ └ 1005 /usr/sbin/cupsd -f
├ modem-manager.service
│ └ 955 /usr/sbin/modem-manager
├ crond.service
│ └ 951 /usr/sbin/crond -n
├ atd.service
│ └ 950 /usr/sbin/atd -f
├ acpid.service
│ └ 949 /usr/sbin/acpid -f
├ NetworkManager.service
│ ├ 946 /usr/sbin/NetworkManager --no-daemon
│ └ 1319 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth0.pid -lf /var/lib/dhclient/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease -cf /var/run/nm-dhclient-eth0.conf eth0
├ avahi-daemon.service
│ ├ 944 avahi-daemon: running [lambda.local]
│ └ 957 avahi-daemon: chroot helper
├ hdapsd@.service
│ └ sda
│ └ 940 /usr/sbin/hdapsd -d sda
├ dev-mqueue.mount
├ dev-hugepages.mount
└ sysinit.service
├ 414 /sbin/udevd -d
├ 468 /sbin/udevd -d
└ 469 /sbin/udevd -d
What other units does a unit depend on?
For example, if you want to figure out which services a target like multi-user.target pulls in, use something like this:
$ systemctl show -p "Wants" multi-user.target
Wants=rc-local.service avahi-daemon.service rpcbind.service NetworkManager.service acpid.service dbus.service atd.service crond.service auditd.service ntpd.service udisks.service bluetooth.service cups.service wpa_supplicant.service getty.target modem-manager.service portreserve.service abrtd.service yum-updatesd.service upowerd.service test-first.service pcscd.service rsyslog.service haldaemon.service remote-fs.target plymouth-quit.service systemd-update-utmp-runlevel.service sendmail.service lvm2-monitor.service cpuspeed.service udev-post.service mdmonitor.service iscsid.service livesys.service livesys-late.service irqbalance.service iscsi.service netfs.service
Instead of "Wants" you might also try "WantedBy", "Requires", "RequiredBy", "Conflicts", "ConflictedBy", "Before", "After" for the respective types of dependencies and their inverse.
What would get started if I booted into a specific target?
If you want systemd to calculate the "initial" transaction it would execute on boot, try something like this:
$ systemd --test --system --unit=foobar.target
for a boot target foobar.target. Note that this is mostly a debugging tool that actually does a lot more than just calculate the initial transaction, so don't build scripts based on this.
Nenhum comentário:
Postar um comentário