Systemctl.v7

From Access Information
Jump to: navigation, search


Installing New Server Mrepo smartd RAID Hardening YUM Crontabs LogWatch systemctl firewalld CentOS 7
Packages
Apache Bind Cacti DHCP mariadb Samba Sarg Sendmail Smokeping Rsync Work Apps
Problems VPN VPN Win Extras Bash MailScanner Horde Google CE Wake Up KVM
Other Computer Lab ISO2USB aiContact Google CE Android USB Live SRS XML


https://fedoraproject.org/w/index.php?title=SysVinit_to_Systemd_Cheatsheet

systemctl

http://www.servermom.org/systemctl-centos-7/1712/

systemctl is a command to control system daemons. This command is available on recent (modern) distros including Fedora 18 or above, RHEL 7, and of course CentOS 7. This systemctl command is available because the Developers behind CentOS 7 replaced upstart with systemd as the default init system. It means now systemd becomes default system management daemon which is different from the old default init system in many aspects that is too long to explain here.

So how to use it? If you are used to the old init scripts, then the new syntax can be slightly confusing. For example:

Old init scripts to restart httpd:

/etc/init.d/httpd restart

or,..

service httpd restart

then the new command will be:

systemctl restart httpd.service

You can also start and stop the service with similar syntax:

systemctl start httpd.service
systemctl stop httpd.service
systemctl status httpd.service
systemctl enable httpd.service

You do not need to use the .service in the command

Services

Note that all recent versions of systemctl assume the '.service' if left off. So, 'systemctl start frobozz.service' is the same as 'systemctl start frobozz'

Booting to CLI

Stop the boot

Choose the Kernel

Press e

Modify "ro" to “rw init=/sysroot/bin/sh”.

Once done, press “Ctrl+x"

Then

chroot /sysroot

Setting GUI

CLI

systemctl set-default multi-user.target

GUI

systemctl set-default graphical.target

Setting up automatic services

systemctl enable smb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service

systemctl stop firewalld
systemctl mask firewalld
systemctl enable iptables
systemctl start iptables


Network

emacs etc/sysconfig/network-scripts/ifcfg-enp2s0

change

ONBOOT=no

to

ONBOOT=yes

or use

nmtui
    ┌─┤ NetworkManager TUI ├──┐
    │                         │
    │ Please select an option │
    │                         │
    │ Edit a connection       │
    │ Activate a connection   │
    │ Set system hostname     │
    │                         │
    │ Quit                    │
    │                         │
    │                    <OK> │
    │                         │
    └─────────────────────────┘

Then Edit a connection

   ┌───────────────────────────┐
   │                           │
   │ ┌─────────────┐           │
   │ │ Ethernet  ↑ │ <Add>     │
   │ │   enp2s0  ▒ │           │
   │ │           ▒ │ <Edit...> │
   │ │           ▒ │           │
   │ │           ▒ │ <Delete>  │
   │ │           ▮ │           │
   │ │           ↓ │ <Quit>    │
   │ └─────────────┘           │
   │                           │
   └───────────────────────────┘

And

   ┌───────────────────────────┤ Edit connection ├───────────────────────────┐
   │                                                                         │
   │         Profile name enp2s0__________________________________           │
   │               Device 74:D4:35:BB:63:C6 (enp2s0)______________           │
   │                                                                         │
   │ ═ ETHERNET                                                    <Show>    │
   │                                                                         │
   │ ═ IPv4 CONFIGURATION <Automatic>                              <Show>    │
   │ ═ IPv6 CONFIGURATION <Automatic>                              <Show>    │
   │                                                                         │
   │ [X] Automatically connect                                               │
   │ [X] Available to all users                                              │
   │                                                                         │
   │                                                           <Cancel> <OK> │
   └─────────────────────────────────────────────────────────────────────────┘

Set Automatically connect

Services Syntax

Sysvinit Command Systemd Command Notes
service frobozz start systemctl start frobozz.service Used to start a service (not reboot persistent)
service frobozz stop systemctl stop frobozz.service Used to stop a service (not reboot persistent)
service frobozz restart systemctl restart frobozz.service Used to stop and then start a service
service frobozz reload systemctl reload frobozz.service When supported, reloads the config file without interrupting pending operations.
service frobozz condrestart systemctl condrestart frobozz.service Restarts if the service is already running.
service frobozz status systemctl status frobozz.service Tells whether a service is currently running.
ls /etc/rc.d/init.d/ systemctl (by itself)
systemctl list-unit-files --type=service (preferred)
ls /lib/systemd/system/*.service /etc/systemd/system/*.service
Used to list the services that can be started or stopped
Used to list all the services and other units
chkconfig frobozz on systemctl enable frobozz.service Turn the service on, for start at next boot, or other trigger.
chkconfig frobozz off systemctl disable frobozz.service Turn the service off for the next reboot, or any other trigger.
chkconfig frobozz systemctl is-enabled frobozz.service Used to check whether a service is configured to start or not in the current environment.
chkconfig --list systemctl list-unit-files --type=service(preferred)
ls /etc/systemd/system/*.wants/
Print a table of services that lists which runlevels each is configured on or off
chkconfig frobozz --list ls /etc/systemd/system/*.wants/frobozz.service Used to list what levels this service is configured on or off
chkconfig frobozz --add systemctl daemon-reload Used when you create a new service file or modify any configuration

Note that all /sbin/service and /sbin/chkconfig lines listed above continue to work on systemd, and will be translated to native equivalents as necessary. The only exception is chkconfig --list.

Template:Admon/warning

Runlevels/targets

Systemd has a concept of targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common sysvinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command. The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd target. Unfortunately, there's no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd target as /etc/systemd/system/$YOURTARGET that takes one of the existing runlevels as a base (you can look at /lib/systemd/system/graphical.target as an example), make a directory /etc/systemd/system/$YOURTARGET.wants, and then symlink the additional services that you want to enable into that directory. (The service unit files that you symlink live in /lib/systemd/system).

Sysvinit Runlevel Systemd Target Notes
0 runlevel0.target, poweroff.target Halt the system.
1, s, single runlevel1.target, rescue.target Single user mode.
2, 4 runlevel2.target, runlevel4.target, multi-user.target User-defined/Site-specific runlevels. By default, identical to 3.
3 runlevel3.target, multi-user.target Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.
5 runlevel5.target, graphical.target Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
6 runlevel6.target, reboot.target Reboot
emergency emergency.target Emergency shell

Changing runlevels:

Sysvinit Command Systemd Command Notes
telinit 3 systemctl isolate multi-user.target (OR systemctl isolate runlevel3.target OR telinit 3) Change to multi-user run level.
sed s/^id:.*:initdefault:/id:3:initdefault:/ ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target Set to use multi-user runlevel on next reboot.

Kernel Options:

The above systemd targets can be used when booting. At the GRUB menu, edit the selection to add "systemd.unit=target" (without the double-quotation marks) as a kernel option where target is one of the above. (For example, "rescue.target".)

Tip: the ".target" extention is optional. The "systemd.unit=rescue" kernel option works the same as "systemd.unit=rescue.target".

  • Did you find this page useful?
  • Do you have an issue that you have not yet fixed?

We can do this for you.

I am available for technical support. Please follow this link. Tech Support Request.
+64-6-880-0000 : ++1-808-498-7146 : help@ai.net.nz
Getting us to help you