system ctl 명령어
기본 타겟 확인
$ systemctl get-default
multi-user.target |
타겟 목록 출력
$ systemctl list-units --type target
UNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System cryptsetup.target loaded active active Encrypted Volumes 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 System network-online.target loaded active active Network is Online network.target loaded active active Network paths.target loaded active active Paths remote-fs.target loaded active active Remote File Systems slices.target loaded active active Slices 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 timers.target loaded active active Timers
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 |
활성화되지 않은 타겟(rescue, emergency 등) 목록도 출력하려면 --all 옵션 추가
$ systemctl list-units --type target --all |
기본 타겟 변경
$ systemctl set-default name.target |
설치시 기본 타겟은 multi-user.target 이며 부팅시 X-Windows 로 로그인하려면 graphical.target 으로 설정
$ sudo systemctl set-default graphical.target |
single user mode
시스템 복구등의 이유로 single user mode 로 진입할 필요가 있을 경우 rescue 명령어 사용
$ sudo systemctl rescue |
systemctl emergency
파일 시스템이 깨졌거나 등의 이유로 single mode 로 진입할 수 없을 때 emergency 로 들어가면 부팅시 최소의 기능으로만 부팅(root 파일 시스템은 read only 로 마운트하고 다른 파일 시스템은 마운트를 안 하는 등) 하므로 응급 복구 가능
$ sudo systemctl emergency |
기존 명령어와 비교
service
servicesystemctl설명
service name start |
systemctl start name.service |
서비스 시작 |
service name stop |
systemctl stop name.service |
서비스 중지 |
service name restart |
systemctl restart name.service |
서비스 재시작 |
service name condrestart |
systemctl try-restart name.service |
서비스가 구동중이었을 경우에만 재시작 |
service name reload |
systemctl reload name.service |
설정 재구동 |
service name status |
systemctl status name.service |
서비스 구동 여부 확인 |
service --status-all |
systemctl list-units --type service --all |
모든 서비스의 상태 표시 |
service 명령어와 systemctl 비교
chkconfig
servicesystemctl설명
chkconfig name on |
systemctl enable name.service |
서비스 활성화(부팅시 자동 구동) |
chkconfig name off |
systemctl disable name.service |
서비스 비활성화 |
chkconfig --list name |
systemctl status name.service |
서비스의 활성화 여부 표시 |
chkconfig --list |
systemctl list-unit-files --type service |
모든 서비스의 현재 활성화 여부 표시 |
chkconfig --list |
systemctl list-dependencies --after |
지정한 target 이후에 시작하는 서비스를 표시 |
chkconfig --list |
systemctl list-dependencies --before |
지정한 target 이전에 시작하는 서비스를 표시 |
chkconfig 명령어와 systemctl 비교
서비스 관리
서비스 상태 확인
systemctl status 서비스명 |
Ex
systemctl status php-fpm.service |
서비스 구동
systemctl start mariadb.service |
서비스 자동 시작
systemctl start mariadb.service |
서비스 목록 보기
list-units 명령어 사용
$ sudo systemctl list-units |
설치된 모든 unit 파일을 보려면 list-unit-files 사용
$ sudo systemctl list-unit-files |
조건에 따라 서비스 보기
구동에 실패한 서비스
$ sudo systemctl list-units --state=failed |
모든 active 목록
$ sudo systemctl list-units --state=active |
상태가 inactive 인 목록
$ sudo systemctl list-units --all --state=inactive |
서비스중에 상태가 running 인 목록
$ sudo systemctl list-units --type=service --state=running |
특정 서비스가 active 상태인지 조회
서비스가 현재 active 상태인지 조회할 경우 is-active 구문 사용
$ sudo systemctl is-active nginx
failed |
서비스가 부팅때 구동되도록 설정 여부
서비스가 현재 active 상태인지 조회할 경우 is-eabled 구문 사용
$ sudo systemctl is-enabled nginx disabled |
journalctl
Query the systemd journal log.
자세한 systemctl 에러 로그 보기
journalctl -xn |
Pager 없이 보기
-e(pager end) 옵션으로 마지막 에러 메시지 라인 보기
journalctl -xe |
짤리는 페이지 개행하기
journalctl -xn --no-pager | less |