systemd 服务管理

systemd 服务管理

列出所有的服务:

[root@localhost ~]# systemctl list-units --all --type=service 
  UNIT                                LOAD      ACTIVE   SUB     DESCRIPTION
  auditd.service                      loaded    active   running Security Auditing Service
  brandbot.service                    loaded    inactive dead    Flexible Branding Service
  cpupower.service                    loaded    inactive dead    Configure CPU power related setti
  crond.service                       loaded    active   running Command Scheduler
  dbus.service                        loaded    active   running D-Bus System Message Bus
● display-manager.service             not-found inactive dead    display-manager.service
  dm-event.service                    loaded    inactive dead    Device-mapper event daemon
  dracut-shutdown.service             loaded    inactive dead    Restore /run/initramfs
  ebtables.service                    loaded    inactive dead    Ethernet Bridge Filtering tables
  emergency.service                   loaded    inactive dead    Emergency Shell
● exim.service                        not-found inactive dead    exim.service

  ......

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

87 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

服务开机启动

[root@localhost ~]# systemctl enable crond.service   
Created symlink from /etc/systemd/system/multi-user.target.wants/crond.service to /usr/lib/systemd/system/crond.service.

服务开机不启动

[root@localhost ~]# systemctl disable crond.service  
Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.

查看服务状态

[root@localhost ~]# systemctl status crond.service 
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; disabled; vendor preset: enabled)
   Active: active (running) since 二 2017-12-05 08:33:57 CST; 1h 9min ago
 Main PID: 690 (crond)
   CGroup: /system.slice/crond.service
           └─690 /usr/sbin/crond -n

1205 08:33:57 localhost.localdomain systemd[1]: Started Command Scheduler.
1205 08:33:57 localhost.localdomain systemd[1]: Starting Command Scheduler...
1205 08:33:57 localhost.localdomain crond[690]: (CRON) INFO (RANDOM_DELAY will be scaled ....)
1205 08:33:57 localhost.localdomain crond[690]: (CRON) INFO (running with inotify support)
Hint: Some lines were ellipsized, use -l to show in full.

停止/开启/重启服务

[root@localhost ~]# systemctl stop crond.service
[root@localhost ~]# systemctl start crond.service
[root@localhost ~]# systemctl restart crond.service

检测服务是否开机启动

[root@localhost ~]# systemctl is-enabled crond.service
enabled
[root@localhost ~]# systemctl disable crond.service
Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.
[root@localhost ~]# systemctl is-enabled crond.service
disabled

你可能感兴趣的:(笔记)