3/30/2017

systemctl 사용법 과 networkctl/timedatectl 설정 및 그외설정

1. systemctl 의 기본사용법

systemctl은 기본적으로 root권한이 필요하기 때문에 아래와 같이 실행하며, systemd의 상태를 확인 및 제어가 가능하며
이 command를 이용하여, 각각의 service를 비롯하여 다양한 분석도 가능하다.


  • 기본실행방법

$ sudo -s 
$ exit
or 
$ sudo systemctl     


systemctl - manual
  https://www.freedesktop.org/software/systemd/man/systemctl.html


  • systemd의 동작을 트리형태로 파악 
일반적으로 시스템의 서비스가 트리형태로 보여주며, 관련사항 정보를 나열해준다.

$ systemctl status // systemd 의 전체 서비스의 실행되는 구조를 쉽게 파악 
● raspberrypi
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Thu 1970-01-01 09:00:01 KST; 49 years 1 months ago
   CGroup: /
           ├─user.slice
           │ └─user-1000.slice
           │   ├─session-c3.scope
           │   │ ├─ 833 sshd: pi [priv]
           │   │ ├─ 848 sshd: pi@pts/0
           │   │ ├─ 851 -bash
           │   │ ├─1090 systemctl status
           │   │ └─1091 pager


상위에 적용되어지는 Option확인
  https://www.freedesktop.org/software/systemd/man/systemctl.html#Options

  • 개별 unit status 확인

$ systemctl status avahi-daemon.service   //설정화면으로 들어감 
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
   Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2019-02-17 01:44:46 KST; 2min 23s ago
  Process: 1169 ExecStart=/usr/sbin/avahi-daemon -s (code=exited, status=0/SUCCESS)
 Main PID: 1169 (code=exited, status=0/SUCCESS)
   Status: "avahi-daemon 0.6.32 starting up."
     ......

$ systemctl is-enabled avahi-daemon.service
enabled


  • units 의 종속성 확인 
각 Units의 종속성을 확인가능하며, 이 부분은 종속성만 확인

$ systemctl list-dependencies   //default가 default.target
default.target
● ├─acct.service
● ├─bootchart-done.service
● ├─bootchart.service
● ├─dphys-swapfile.service
● ├─lightdm.service
● ├─raspi-config.service
● ├─systemd-update-utmp-runlevel.service
● └─multi-user.target
●   ├─acct.service
●   ├─avahi-daemon.service
●   ├─bluealsa.service
●   ├─bootchart-done.service
....

$ systemctl list-dependencies --all  //모든 종속성을 확인가능 

$ systemctl list-dependencies --after  //default.target 기준으르 After (Unit 설정부분참조)

$ systemctl list-dependencies --before  //default.target 기준으르 Before

$ systemctl list-dependencies raspi-config.service  // 본인보고싶은 unit의 종속성확인 
 


1.1 systemd의 unit의 제어 

systemd의 command는 file(아래참조) 기반 과 systemd에서 생성된 unit(즉,실행되어 memory 존재),file 기반은 아래의 1,2번에 있는 unit들을 말한다.
더불어 systemd는 아래의 순서대로 찾지만 우선순위는 /etc가 높으므로, 최종제어는 /etc에서 한다
  1. /lib/systemd/system
  2. /etc/systemd/system
**/run/systemd 는 생략 (실행중인 정보들 )

  • unit 에 enable/disable 추가/제거 (file 기반)
file기반의 unit을 enable을 하므로써, 링크를 생성하여 load가 되며, 이후에는 start/stop/restart 명령진행가능

$ systemctl enable avahi-daemon.service  // /etc에 각 symbolic link 생성  
Created symlink /etc/systemd/system/dbus-org.freedesktop.Avahi.service → /lib/systemd/system/avahi-daemon.service.
Created symlink /etc/systemd/system/multi-user.target.wants/avahi-daemon.service → /lib/systemd/system/avahi-daemon.service.
Created symlink /etc/systemd/system/sockets.target.wants/avahi-daemon.socket → /lib/systemd/system/avahi-daemon.socket.

$ systemctl disable avahi-daemon.service  // /etc에 각 symbolic link 제거  
Removed /etc/systemd/system/dbus-org.freedesktop.Avahi.service.
Removed /etc/systemd/system/multi-user.target.wants/avahi-daemon.service.
Removed /etc/systemd/system/sockets.target.wants/avahi-daemon.socket.

$ systemctl is-enabled avahi-daemon.service  // 확인 
enabled

// /lib 와 /etc wants 중심으로 기능확인 
$ ls /lib/systemd/system/*wants
.....
/lib/systemd/system/multi-user.target.wants:
dbus.service                          systemd-logind.service
getty.target                          systemd-update-utmp-runlevel.service
systemd-ask-password-wall.path
....
/lib/systemd/system/sockets.target.wants:
dbus.socket                      systemd-journald.socket
systemd-initctl.socket           systemd-udevd-control.socket
systemd-journald-audit.socket    systemd-udevd-kernel.socket
systemd-journald-dev-log.socket
......

$ ls /etc/systemd/system/*wants
.....
/etc/systemd/system/multi-user.target.wants:
avahi-daemon.service      machines.target           rngd.service
busybox-klogd.service     ofono.service             systemd-networkd.service
busybox-syslog.service    power-setup.service       systemd-resolved.service
....
/etc/systemd/system/sockets.target.wants:
avahi-daemon.socket      sshd.socket
...

  • unit mask/unmask 제외 (file 기반)
mask는 disalbe 보다 더 강력한 명령으로 unit 제외 해버리겠다는 의미으로 enable 해도 소용이 없으며
만약 list-unit-files에는 검색은 되지만, enable이 제대로되지 않는다면, 이부분을 보자.

$ systemctl mask avahi-daemon.service  // /lib 에 이미 존재하지만, /etc에서 막음 
Created symlink /etc/systemd/system/avahi-daemon.service → /dev/null.

$ systemctl unmask avahi-daemon.service // /etc에서 막은 것을 제거 (etc가 우선순위가 높음) 
Removed /etc/systemd/system/avahi-daemon.service

$ systemctl list-unit-files | grep masked  // mask 상태 확인 가능 


  • 개별 unit start/stop/restart/reload 동작제어 (memory 기반)
enable이 된 상태의 avahi를 예를들면 아래와 같이 각각의 unit 명령을 실행가능하다.

$ systemctl start avahi-daemon.service

$ systemctl stop avahi-daemon.service

$ systemctl restart avahi-daemon.service



  • service enable /disable  한 후 동작확인 예 (timesyncd)

 // service stop 한 후 disable 하여 다음 부팅시에도 미동작  
$ systemctl stop systemd-timesyncd
$ systemctl disable systemd-timesyncd

// service enable 한 후 start   
$ systemctl enable systemd-timesyncd
$ systemctl start  systemd-timesyncd
$ systemctl restart  systemd-timesyncd  //문제시 다시 restart 

//이 service 의 active or disable 확인
$ systemctl is-active  systemd-timesyncd
$ systemctl is-enabled systemd-timesyncd
$ systemctl list-units --type service   


1.2 Systemd 의 전체 Units 정보확인 

일반적인 systemd의 unit 확인방법은 Memory에 있는 Unit(실행된 Unit)과 File에 존재하는 Unit로 검색이 가능하며,
세부옵션을 설정하여 다양하게 검색이 가능하다. .

  • 세부옵션 
  1. -t -type: Unit의 종류 (e.g service, target, timer, mount ...) 
  2. -a -all: 모든 Unit의 정보를 보여준다. 
  3. --state: Unit의 상태 입력 (e.g active, inactive, failed ... )
상위에 적용되어지는 Option확인
  https://www.freedesktop.org/software/systemd/man/systemctl.html#Options

  • list-units로 (in memory)
list-units의 경우 memory에 있는 unit를 기준으로 찾아주며, default로 활성화된 상태인 systemd의 unit을 확인가능하며, 이외의 옵션을 주어
다양하게 검색이 가능하다

$ systemctl list-units or systemctl // default가 활성화된 Unit를 검색 및 device 분석 
UNIT                                                                                         LOAD   ACTIVE SUB       DESCRIPTION                
proc-sys-fs-binfmt_misc.automount                                                            loaded active waiting   Arbitrary Executable File F
sys-devices-platform-soc-3f201000.serial-tty-ttyAMA0-hci0.device                             loaded active plugged   /sys/devices/platform/soc/3
sys-devices-platform-soc-3f201000.serial-tty-ttyAMA0.device                                  loaded active plugged   /sys/devices/platform/soc/3
sys-devices-platform-soc-3f202000.mmc-mmc_host-mmc0-mmc0:aaaa-block-mmcblk0-mmcblk0p1.device loaded active plugged   /sys/devices/platform/soc/3
sys-devices-platform-soc-3f202000.mmc-mmc_host-mmc0-mmc0:aaaa-block-mmcblk0-mmcblk0p2.device loaded active plugged   /sys/devices/platform/soc/3
sys-devices-platform-soc-3f202000.mmc-mmc_host-mmc0-mmc0:aaaa-block-mmcblk0.device           loaded active plugged   /sys/devices/platform/soc/3
sys-devices-platform-soc-3f300000.mmc-mmc_host-mmc1-mmc1:0001-mmc1:0001:1-net-wlan0.device   loaded active plugged   /sys/devices/platform/soc/3
sys-devices-platform-soc-3f980000.usb-usb1-1\x2d1-1\x2d1.1-1\x2d1.1:1.0-net-eth0.device      loaded active plugged   SMSC9512/9514 Fast Ethernet
sys-devices-platform-soc-soc:audio-bcm2835_alsa-sound-card0.device                           loaded active plugged   /sys/devices/platform/soc/s
sys-devices-virtual-block-ram0.device                                                        loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram1.device                                                        loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram10.device                                                       loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram11.device                                                       loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram12.device                                                       loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram13.device                                                       loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram14.device                                                       loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram15.device                                                       loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram2.device                                                        loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram3.device                                                        loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram4.device                                                        loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram5.device                                                        loaded active plugged   /sys/devices/virtual/block/
sys-devices-virtual-block-ram6.device                                                        loaded active plugged   /sys/devices/virtual/block/
....

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

// UNIT 의 device들을 보면, 실제위치는 DESCRIPTION에 /sys filesystem 기반으로 구성되며, sys-devices 는 /sys/devices 이런식변경
// 최종 /sys의 device directory에서 uevent 확인  
// 최종 /sys의 device directory에서 of_node/ 에서 각 속성확인  


$ systemctl list-units | grep mount // mount 부분분석 
  -.mount                                                                                                          loaded active mounted   Root Mount                                         
  home-root.mount                                                                                                  loaded active mounted   /home/root                                         
  sys-fs-fuse-connections.mount                                                                                    loaded active mounted   FUSE Control File System                           
  sys-kernel-config.mount                                                                                          loaded active mounted   Kernel Configuration File System                   
  sys-kernel-debug.mount                                                                                           loaded active mounted   Kernel Debug File System                           
  tmp.mount                                                                                                        loaded active mounted   Temporary Directory (/tmp)                         
  var-log.mount                                                                                                    loaded active mounted   /var/log                                           
  var-volatile.mount                                                                                               loaded active mounted   /var/volatile                                      
  systemd-remount-fs.service                                                                                       loaded active exited    Remount Root and Kernel File Systems                  
....

$ find /etc/systemd/  -name *mount* // file mount 아무것도 없음
$ find /lib/systemd/  -name *mount* // file mount 부분분석   
/lib/systemd/system/sys-fs-fuse-connections.mount
/lib/systemd/system/sys-kernel-config.mount
/lib/systemd/system/systemd-remount-fs.service
/lib/systemd/system/machines.target.wants/var-lib-machines.mount
/lib/systemd/system/sysinit.target.wants/sys-fs-fuse-connections.mount
/lib/systemd/system/sysinit.target.wants/sys-kernel-config.mount
/lib/systemd/system/sysinit.target.wants/dev-hugepages.mount
/lib/systemd/system/sysinit.target.wants/dev-mqueue.mount
/lib/systemd/system/sysinit.target.wants/sys-kernel-debug.mount
/lib/systemd/system/dev-hugepages.mount
/lib/systemd/system/umount.target
/lib/systemd/system/var-lib-machines.mount
/lib/systemd/system/remote-fs.target.wants/var-lib-machines.mount
/lib/systemd/system/dev-mqueue.mount
/lib/systemd/system/local-fs.target.wants/systemd-remount-fs.service
/lib/systemd/system/local-fs.target.wants/tmp.mount
/lib/systemd/system/tmp.mount
/lib/systemd/system/sys-kernel-debug.mount
/lib/systemd/systemd-remount-fs        // binary 파일  

// -.mount , home-root.mount , var-log.mount var-volatile.mount 는 상위에 존재하지 않음
// /lib/systemd/systemd-remount-fs 이 /etc/fstab 참조하여, 생성된 unit 이며, 이후 fsck로 filesystem 체크  

$ cat /lib/systemd/system/systemd-remount-fs.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Remount Root and Kernel File Systems
Documentation=man:systemd-remount-fs.service(8)
Documentation=https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-fsck-root.service
Before=local-fs-pre.target local-fs.target shutdown.target
Wants=local-fs-pre.target
ConditionPathExists=/etc/fstab

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/lib/systemd/systemd-remount-fs

$ fdisk -l   // 각 partition 확인
or
$ systemd-mount --list 
  https://www.freedesktop.org/software/systemd/man/systemd.html#


  • 이외 세부검색방법

$ systemctl list-units -all  // 모든 Unit 검색 (비활성화부분포함)
or
$ systemctl list-units -a   // 모든 Unit 검색 (비활성화부분포함)


$ systemctl list-units -t service // 활성화된 service unit만 검색 
or
$ systemctl  list-units -type service // 활성화된 service unit만 검색 


$ systemctl list-units -t target   // 활성화된 target unit만 검색 (Unit 11개 종류가 있으므로 각각설정)

$ systemctl list-units -t timer   // 활성화된 timer unit만 검색 (Unit 11개 종류가 있으므로 각각설정)


$ systemctl list-units -t service  --state=inactive  // 비활성화된 Unit의 Serivce만 검색 


$ systemctl list-units --state=failed    // Failed Unit 검색
or 
$ systemctl --failed   // Failed Unit 검색



  • list-sockets (in memory)
socket unit는 Network관련된 것이므로, 동작 중인 socket unit의 세부정보인 Network 정보확인가능, 즉 Server의 존재 및 동작확인가능

$ systemctl list-sockets   // SOCKET의 LISTEN (Server)를 표시 (동작확인) (NETWORK 정보확인)

$ systemctl list-units -t socket  // 상위와 같이 UNIT의 status 만 확인 

  • list-timers (in memory)
timer unit는 기존의 cron과 유사하며, 동작 중인 timer의 상태와 세부정보를 별도로 볼 수 있다.

$ systemctl list-timers   // NEXT(다음동작)  LEFT (남은시간)  LAST (마지막실행) 동작확인   

$ systemctl list-units -t timer  // 상위와 같이 UNIT의 status 만 확인 

  • list-unit-files (in file)
/lib/systemd/system or /etc/systemd/system 에 설치된 files 확인검색하며, 각 상태를 확인가능하다.

$ systemctl list-unit-files
UNIT FILE                              STATE    
proc-sys-fs-binfmt_misc.automount      static   
-.mount                                generated
boot.mount                             generated
dev-hugepages.mount                    static   
dev-mqueue.mount                       static   
proc-fs-nfsd.mount                     static   
proc-sys-fs-binfmt_misc.mount          static   
run-rpc_pipefs.mount                   static   
sys-fs-fuse-connections.mount          static   
sys-kernel-config.mount                static   
sys-kernel-debug.mount                 static   
systemd-ask-password-console.path      static   
systemd-ask-password-plymouth.path     static   
systemd-ask-password-wall.path         static   
session-c1.scope                       transient
session-c2.scope                       transient
session-c3.scope                       transient
acct.service                           generated
alsa-restore.service                   static   
alsa-state.service                     static   
alsa-utils.service                     masked   
apply_noobs_os_config.service          disabled 
apt-daily-upgrade.service              static   
apt-daily.service                      static   
auth-rpcgss-module.service             static   
autologin@.service                     enabled  
autovt@.service                        disabled 
.....



  • service unit의 설정보기 

$ systemctl show avahi-daemon.service
Type=dbus
Restart=no
NotifyAccess=main
RestartUSec=100ms
TimeoutStartUSec=1min 30s
TimeoutStopUSec=1min 30s
RuntimeMaxUSec=infinity
WatchdogUSec=0
WatchdogTimestampMonotonic=0
FailureAction=none
PermissionsStartOnly=no
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=0
ControlPID=0
BusName=org.freedesktop.Avahi
FileDescriptorStoreMax=0
NFileDescriptorStore=0
StatusText=avahi-daemon 0.6.32 starting up.
StatusErrno=0
Result=success
UID=4294967295
GID=4294967295
...



  https://wiki.archlinux.org/index.php/systemd
  https://websetnet.com/ko/manage-systemd-services-and-units/
  https://www.conory.com/note_linux/42241
  https://www.freedesktop.org/wiki/Software/systemd/
  http://linux.systemv.pe.kr/centos-7-systemd-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0/


2. systemctl 이외의 설정 


2.1 networkctl 설정 

ifconfig 처럼 각각의 network의 정보를 확인 가능한 명령

  • 물리적인 network 확인  

$ networkctl --help
networkctl [OPTIONS...]

Query and control the networking subsystem.

  -h --help             Show this help
     --version          Show package version
     --no-pager         Do not pipe output into a pager
     --no-legend        Do not show the headers and footers
  -a --all              Show status for all links

Commands:
  list [LINK...]        List links
  status [LINK...]      Show link status
  lldp [LINK...]        Show LLDP neighbors
  label                 Show current address label entries in the kernel


$ networkctl list // ifconfig 처럼 물리적인 network 연결상태확인 

$ networkctl status -a  // ifconfig 처럼 network IP 및 정보학인 

networkctl (systemd-networkd)
  https://www.freedesktop.org/software/systemd/man/networkctl.html#
  https://www.freedesktop.org/software/systemd/man/systemd-networkd.service.html#


2.2 timedatectl 설정 

시간에 관련된 설정으로 NTP를 비롯하여, Hardware 적인 시간인 RTC와 System Clock 와 지역 설정까지 가능하다.

  • timedatectl 사용법
$ timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode
     --monitor             Monitor status of systemd-timesyncd
  -p --property=NAME       Show only properties by this name
  -a --all                 Show all properties, including empty ones
     --value               When showing properties, only print the value

Commands:
  status                   Show current time settings
  show                     Show properties of systemd-timedated
  set-time TIME            Set system time
  set-timezone ZONE        Set system time zone
  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Enable or disable network time synchronization

systemd-timesyncd Commands:
  timesync-status          Show status of systemd-timesyncd
  show-timesync            Show properties of systemd-timesyncd



  • timedatectl 기본상태확인
$ timedatectl   // Time에 관련된 일반적인 상태확인 
or  
$ timedatectl status                                  
               Local time: Tue 2017-04-14 01:48:24 UTC       // UTC Time +9이지만 현재 /etc/localtime을 사용하여 제대로 동작안됨
           Universal time: Tue 2017-04-14 01:48:24 UTC       // UTC Time 
                 RTC time: Tue 2017-04-14 01:48:23           // RTC기반으로 동작 
                Time zone: n/a (UTC, +0000)                  // UTC Time에 Time zone은 /etc/localtime으로 설정되어있음 (Seoul +9)
System clock synchronized: no                                // 시간을 Sytem clock 과 동기화기능 
              NTP service: active                            // NTP Client로 timesyncd 이용
          RTC in local TZ: no                                // RTC의 Timezon 사용여부 (timedatectl set-local-rtc  0) 


  • timezone 기능확인 
$ timedatectl list-timezones   //  timezones list를 보여줌 
//만약 동작하지 않는다면, timezone의 directory 확인 (/etc/localtime -> /usr/share/zoneinfo/Asia/Seoul)

$ timedatectl set-timezone “Asia/Seoul” // 상위 /etc/localtime 링크변경 


  • timedatectl 날짜시간설정
$ timedatectl set-ntp 0
//변경시 주의사항.1 NTP설정(timedatectl set-ntp true)이면, set-time부분에서 에러발생
//변경시 주의사항.2 RTC에도 적용되므로 반드시 같이 확인
$ timedatectl set-time 2015-11-20              //날짜만 변경 
$ timedatectl set-time 15:58:30              //시간만 변경  
$ timedatectl set-time "2012-10-3018:17:16"  //날짜시간동시변경  


  • Last login 정보지우기 (NTP/RTC 미사용시 이시간사용)
// 주의: Last Login Time 정보 Linux가 시스템 Time 설정가능

// 아래 파일은 binary가 있으므로 존재여부만 확인
$ cat /var/log/lastlog        // Last Login 정보이지만, Binary이므로 깨짐 
$ cat /var/log/utmp           // last -f /var/log/utmp (picture of users logins at which terminals, logouts,) 
$ cat /var/log/wtmp           // last -f /var/log/wtmp (utmp의 history)   
$ cat /var/log/btmp           // last -f /var/log/btmp (records only failed login attempts.)

// lastlogin 정보확인
$ who                                // 명령어로 본인 및 Last Login Time 확인 
$ lastlog                            // last login 정보확인 (/var/log/lastlog 기반) 

// NTP Client Service Stop and Disable
$ systemctl stop systemd-timesyncd
$ systemctl disable systemd-timesyncd
$ systemctl status systemd-timesyncd

// 원하는 시간으로 변경
$ timedatectl set-time "2012-10-3018:17:16"

// 주의: NTP 미사용 과 RTC 미사용한 후 시간설정이 되면 외부의 Device(GPS or 외부 RTC) 혹은 Build Time 에서 설정될 가능성이 높음
// lastlogin 정보삭제
$ lastlog -u root -C               // last login user:root -C clear (lastlog가 /var/log/lastlog 기반)
$ rm /var/log/lastlog
$ rm /var/log/*tmp
$ sync
// HW Reset or Power On/Off

lastlog 정보
  https://unixserveradmin.wordpress.com/2014/08/10/how-to-read-or-view-utmp-wtmp-and-btmp-files-in-linux/

  • RTC 와 NTP 상태확인 
// 상위설정상태 확인 가능, 아래 Timezone도 나와야함 
$ timedatectl show 
LocalRTC=no                                // RTC on /off (timedatectl set-ntp 1 or 0)
CanNTP=yes                                 // NTP Client Service 존재여부 
NTP=yes                                    // NTP Service on / off (timedatectl set-ntp 1 or 0) 
NTPSynchronized=yes                        // NTP Server에 접속후 Sync 여부  
TimeUSec=Tue 2017-07-02 10:38:38 KST       // System 의 실제동작 시간 (date)
RTCTimeUSec=Tue 2017-07-02 10:38:39 KST    // RTC Time Sec (/proc/driver/rtc or /dev/rtc) 


  • NTP Server 연결상태확인
//확인시 주의사항 NTP설정(timedatectl set-ntp true)일 경우에만 확인
//NTP Server 동작확인  및 systemd-timesyncd service 설정확인 
$ timedatectl timesync-status    // NTP Packet 확인 (Network 문제로 접속못함)
       Server: (null) (time3.google.com)
Poll interval: 0 (min: 32s; max 34min 8s)
 Packet count: 0

$ timedatectl timesync-status    // NTP Packet 확인 (Network 문제로 접속한 후 주기적으로 Sync)
       Server: 216.239.35.0 (time1.google.com)
Poll interval: 32s (min: 32s; max 34min 8s)
         Leap: normal
      Version: 4
      Stratum: 1
    Reference: GOOG
    Precision: 1us (-20)
Root distance: 167us (max: 5s)
       Offset: -886.603ms
        Delay: 70.981ms
       Jitter: 0
 Packet count: 1
    Frequency: +0.000ppm
$ timedatectl show-timesync    // NTP 설정부분 확인 (systemd-timesyncd 설정확인필요) 
......


  • NTP Service 사용여부결정
//NTP 설정 부분 상위 
$ timedatectl set-ntp true
$ timedatectl set-ntp false


  • RTC 사용여부 결정
//RTC의 Local Time 적용여부 설정 
$ timedatectl set-local-rtc  1  // /dev/rtc 사용하며, Local Time 적용여부 on (timedatectl status 확인) 
//이것으로 사용
$ timedatectl set-local-rtc  0  // /dev/rtc 사용하며, Local Time 적용여부 off


  https://www.tecmint.com/set-time-timezone-and-synchronize-time-using-timedatectl-command/
  https://www.freedesktop.org/software/systemd/man/timedatectl.html#
  https://www.freedesktop.org/software/systemd/man/systemd-firstboot.html#
  http://man7.org/linux/man-pages/man1/timedatectl.1.html
  http://man7.org/linux/man-pages/man1/systemd-firstboot.1.html

  • RTC 동작확인 
$ ls  /dev/rtc*  // rtc->rtc0 link 
/dev/rtc   /dev/rtc0  

$ cat /proc/driver/rtc
rtc_time        : 16:31:36
rtc_date        : 2017-03-13
alrm_time       : 00:00:00
alrm_date       : 1970-01-01
alarm_IRQ       : no
alrm_pending    : no
update IRQ enabled      : no
periodic IRQ enabled    : no
periodic IRQ frequency  : 1
max user IRQ frequency  : 64
24hr            : yes

  • RTC 와 Linux System 시간 동기화  
timedatectl이 제대로 동작안되면 busybox의 hwclock으로 강제설정

$ hwclock -r          // RTC Time 확인 

$ hwclock -w          // system 시간 ->  /dev/rtc 시간저장

$ hwclock -s          // /dev/rtc    ->  system 시간 

AP의 경우 PMIC와 같이 사용할 경우, RTC를 PMIC와 함께 사용하는 경우가 있으므로, 반드시 관련 Kernel config와 관련 Datasheet 참조

  http://man7.org/linux/man-pages/man8/hwclock.8.html
  https://www.digi.com/resources/documentation/digidocs/90001546/reference/bsp/cc6/r_real_time_clock.htm


2.3 systemd에서 사용되어지는 ctrl 설정 

그외에도 사용되어지는 ctrl command들이 존재하지만 경우에따라 다 지원하지는 않는것 같다.

사용한다면 아래의 Manual에서 확인하자

homectl
  https://www.freedesktop.org/software/systemd/man/homectl.html#

hostnamectl

$ hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...

Query or change system hostname.

  -h --help              Show this help
     --version           Show package version
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host
  -M --machine=CONTAINER Operate on local container
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname

Commands:
  status                 Show current hostname settings
  set-hostname NAME      Set system hostname
  set-icon-name NAME     Set icon name for host
  set-chassis NAME       Set chassis type for host
  set-deployment NAME    Set deployment environment for host
  set-location NAME      Set location for host
  https://www.freedesktop.org/software/systemd/man/hostnamectl.html#

loginctl

$ loginctl --help
loginctl [OPTIONS...] {COMMAND} ...

Send control commands to or query the login manager.

  -h --help                Show this help
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-legend           Do not show the headers and footers
     --no-ask-password     Don't prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
  -p --property=NAME       Show only properties by this name
  -a --all                 Show all properties, including empty ones
     --value               When showing properties, only print the value
  -l --full                Do not ellipsize output
     --kill-who=WHO        Who to send signal to
  -s --signal=SIGNAL       Which signal to send
  -n --lines=INTEGER       Number of journal entries to show
  -o --output=STRING       Change journal output mode (short, short-precise,
                             short-iso, short-iso-precise, short-full,
                             short-monotonic, short-unix, verbose, export,
                             json, json-pretty, json-sse, cat)
Session Commands:
  list-sessions            List sessions
  session-status [ID...]   Show session status
  show-session [ID...]     Show properties of sessions or the manager
  activate [ID]            Activate a session
  lock-session [ID...]     Screen lock one or more sessions
  unlock-session [ID...]   Screen unlock one or more sessions
  lock-sessions            Screen lock all current sessions
  unlock-sessions          Screen unlock all current sessions
  terminate-session ID...  Terminate one or more sessions
  kill-session ID...       Send signal to processes of a session

User Commands:
  list-users               List users
  user-status [USER...]    Show user status
  show-user [USER...]      Show properties of users or the manager
  enable-linger [USER...]  Enable linger state of one or more users
  disable-linger [USER...] Disable linger state of one or more users
  terminate-user USER...   Terminate all sessions of one or more users
  kill-user USER...        Send signal to processes of a user

Seat Commands:
  list-seats               List seats
  seat-status [NAME...]    Show seat status
  show-seat [NAME...]      Show properties of seats or the manager
  attach NAME DEVICE...    Attach one or more devices to a seat
  flush-devices            Flush all device associations
  terminate-seat NAME...   Terminate all sessions on one or more seats
  https://www.freedesktop.org/software/systemd/man/loginctl.html#

userdbctl
  https://www.freedesktop.org/software/systemd/man/userdbctl.html#

  https://www.freedesktop.org/software/systemd/man/index.html

댓글 없음 :