Systemd
systemd is a suite of basic building blocks for a Linux system.
Categories
Unit configuration
- systemd의 기본적인 용어 설명
- [추천] systemctl - PGWiki 1
- CentOS 7 Systemd 이해하기
- [추천] systemd unit 등록 관련 옵션 정리
- [추천] Systemd Target 사용
[Unit]
Requires= # 다른 unit들과 dependency를 정의하는 부분.
# 다른 unit이 activation이 실패하면 같이 실패 됨.
Wants= # Requires와 같은 기능을 하지만 다른 unit이 activation 실패해도
# 영향을 받지 않음. 따라서 다른 unit이 start-up할 때 hooking 하여
# 같이 실행 될 때 사용함.
Before= # dependency 있는 unit들을 ordering하는 속성.
After= # 만약 foo.service unit에 Before=bar.service를 설정하면
# foo.service가 다 strat-up 될 때 까지 bar.service unit은 delay 됨.
# 죽, 내 before=로 설정한 unit 전에 실행 시키라는 속성.
[Install] # systemd의 runtime에 interpret되는 것이 아니라 unit을 설치하는
# systemd enable/disable command에 의해 영향을 받는 section
WantedBy= # 이 option을 설정하면 systemlctl enable시 .wants/ .requires/
RequiredBy= # 폴더에 symbolic link를 생성해줌
# 여러 줄로 명령을 주고 싶다면 "\"을 준다:
ExecStart=java -server -Xms124M -Xmx1024M -XX:+HeapDumpOnOutOfMemoryError \
-classpath /usr/local/plcGateway/lib/* \
com.mseo.main.main /usr/local/plcGateway/cfg
Network Targets
- systemd 서비스 unit파일 작성에서 했던 실수
-
freedesktop.org - NetworkTarget-> Running Services After the Network Is Up
Network Configuration Synchronization Points
-
network.target
- 네트워크 서비스가 Active 상태인지 확인한다. -
network-online.target
- 네트워크 인터페이스가 UP 상태인지 확인한다.
multi-user.target
run-level-3이 시작됨을 알려준다.
서비스 파일 등록
systemd는 기본적으로 루트 권한으로 실행된다. 해당 디렉토리는/etc/systemd/system/
이다. 이 곳에 서비스이름.service
파일을 추가하고 다음 명령으로 활성화 할 수 있다.
--user
옵션을 사용하는 일반 사용자 서비는 $HOME/.config/systemd/user
이다.
노트북 화면 꺼짐 조정 (?)
Edit /etc/systemd/logind.conf
and make sure you have:
그리고 아래 명령을 날린다:
Power management 항목 및 ArchWiki 참조.
또다른 방법 (?)
You can use this to temporarily disable lid-switch events:
키워드
Hibernate, lid, Power management, acpi, 등 으로 검색...
임베디드 리눅스에서 systemd가 문제가 되는 이유
주로 자원을 많이 사용하느 이슈 등
- systemd는 많은 문제를 해결하며, 커뮤니티도 매우 응답성이 좋고 도움이 됨
- 가끔 이상한 문제가 있지만 항상 해결책이 존재함
- 메모리 사용은 중요하지 않으며, 대부분의 임베디드 Linux 장치는 1GB 이상의 RAM을 가짐
- 작은 장치에서는 Zypher나 FreeRTOS를 사용함
- core 기능을 제공하며, 다양한 플랫폼에 systemd와 유사한 서비스 관리자를 제공할 수 있음
- systemd는 다양한 시스템 유틸리티를 하나의 큰 빌드로 제공함
- systemd는 초기에는 작았으나, 현재는 웹 기반으로 비디오 회의도 가능함
- BusyBox에 내장되어 있으며 매우 가벼움
- 설정이 매우 간단하며, 로깅 기능도 포함됨
- Unix 철학을 거의 완벽하게 구현함
- 고정된 주변 장치와 커널 모듈을 사용하는 경우 가능함
- 많은 소프트웨어가 이 세그먼트를 염두에 두고 작성되지 않음
- systemd의 gnulibc와 gcc 확장 사용이 문제임
- 64M RAM과 128M NAND 플래시를 가진 장치에서는 5M의 systemd가 비효율적임
- mainstream 배포판을 고려하지 않는 시스템에서는 큰 문제가 아님
- 최소한의 경우에도 init 스크립트를 실행하기 위해 셀이 필요함
Example
Docker example
[Unit]
Description=apache2
After=mysql.service
Requires=mysql.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill apache2-server
ExecStartPre=-/usr/bin/docker rm apache2-server
ExecStart=/usr/bin/docker run -p 60004:80 --volumes-from apache2-volume --volumes-from mysql-volume -v /etc/localtime:/etc/localtime:ro --name apache2-server apache2-server
ExecStop=/usr/bin/docker kill apache2-server
[Install]
WantedBy=multi-user.target
JupyterNotebook service
[Unit]
Description=Jupyter Notebook Server
[Service]
Type=simple
User=<username>
ExecStart=/home/<username>/.local/bin/jupyter-notebook
WorkingDirectory=/your/working/dir
[Install]
WantedBy=multi-user.target
ANSWER
[Unit]
Description=The ANSWER, No-code development platform
[Service]
Environment=RECC_VERBOSE=2
Environment=RECC_DEVELOPER=true
Environment=PYTHONPATH="/home/yourname/Project/answer/core"
ExecStart="/home/yourname/.pyenv/versions/opy-yourname-3.8.9/bin/python" -m recc core --storage-root "/home/yourname/Project/answer/core/storage"
User=root
Group=root
[Install]
WantedBy=multi-user.target
한번만 실행
[Unit]
Description=Set DNS for Nebula Interface
After=nebula.service
[Service]
ExecStart=/usr/local/bin/set-nebula-dns.sh
Type=oneshot
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
vs chkconfig
What about chkconfig? That changed too? Yes, now you want to use systemctl for the chkconfig commands also..
-
systemctl enable httpd
-
chkconfig service on
-
systemctl disable httpd
-
chkconfig service off
-
systemctl is-enabled httpd
-
chkconfig service
(is it set up to start?)
-
systemctl list-unit-files --type=service
-
chkconfig –list
(shows what is and isn’t enabled)
LogNamespace
Journalctl#LogNamespace 항목 참조.
Troubleshooting
systemctl restart
등을 사용하여 서비스 실행에 실패했을 경우 journalctl -xe
를 사용하면 로그를 확인할 수 있다.
See also
- linux
- chkconfig
- upstart
- journalctl
- Runlevel
- Shepherd - 셰퍼드는 서비스 관리자로, 서비스의 상태와 의존성을 관리하며 필요에 따라 시작, 종료 및 재시작할 수 있는 기능을 제공합니다.
Favorite site
- systemd System and Service Manager
- systemd.exec
- 새로운 PID 1, systemd 어떻게 생각 하세요?.md
- Understanding Systemd Units and Unit Files
References
-
Systemctl_-_PGWiki.pdf ↩