====== systemd ====== * [[https://mxlinux.org/wiki/system/systemd-overview/|MX Linux systemd overview]] * [[https://lunatine.net/2014/10/21/about-systemd/|systemd 살펴보기]] * [[http://linux.systemv.pe.kr/centos-7-systemd-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0/|CentOS 7 Systemd 이해하기 - Voyager of Linux]] * [[https://wiki.archlinux.org/index.php/systemd|systemd Arch wiki]] * [[linux:arch|Arch Linux]]는 ''systemd''로 서비스/대몬 설정을 다룬다. ===== unit 모음 디렉토리 ===== * ''/etc/systemd/system'' * ''/run/systemd/system'' * ''/usr/local/lib/systemd/system'' * ''/usr/lib/systemd/system'' ===== 사용법 ===== # 지금 시작 systemctl start unit # 종료 systemctl stop unit # 재시작 systemctl restart unit # booting 시 시작하게 설정 systemctl enable unit # booting 시 시작하게 하면서, 지금 당장도 실행하게 systemctl enable --now unit ===== environment.d ===== * 세션 시작시 환경 변수를 설정하기 * script 는 안되고, ''NAME=value'' 형태만 된다. * [[https://www.freedesktop.org/software/systemd/man/environment.d.html|environment.d]] * ''/etc/environment.d/*.conf'', ''~/.config/environment.d/*.conf'' 파일에 환경변수를 ''NAME=VALUE'' 형태로 지정한다. * 스크립트를 넣을 수는 없다. # 예시 /etc/environment.d/60-foo.conf: FOO_DEBUG=force-software-gl,log-verbose PATH=/opt/foo/bin:$PATH LD_LIBRARY_PATH=/opt/foo/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} XDG_DATA_DIRS=/opt/foo/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/} ===== user 시작 프로그램 ===== * [[https://linux.systemv.pe.kr/systemd-user-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0/|systemd -user 사용하기 - Voyager of Linux]] * [[https://tanzolab.it/systemd|How to use systemd for applications start (revised on May 2019)]] * [[https://wiki.archlinux.org/title/Systemd/User|systemd/User - ArchWiki]] * [[https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/|Running Your Node.js App With Systemd - Part 1 - NodeSource]] * [[https://support.nine.ch/articles/manage-daemons-as-user-with-systemd#enable-a-service|Manage daemons as user with systemd - nine Support]] ===== systemd bootchart ===== * [[http://manpages.ubuntu.com/manpages/focal/man1/systemd-bootchart.1.html|Ubuntu Manpage: systemd-bootchart - Boot performance graphing tool]] sudo apt install systemd-bootchart systemd-analyze systemd-analyze blame * [[linux:grub|Linux Grub]] 에서 커널 설정에 ''init=/lib/systemd/systemd-bootchart'' 넣고 부팅하면 ''/run/log/bootchart-날짜-번호.svg'' 파일이 생성되고 이 이미지를 보고 부팅 성능 병목 지점을 찾을 수 있다. * [[https://www.facebook.com/groups/ubuntu.ko/permalink/3721279894576497/|systemd bootchart 설명]] ===== systemd 는 어떻게 기존 SysVInit 의 /etc/init.d/* 서비스를 인식하는가 ===== * Systemd 로 변경했음에도 기존 ''SysVInit'' 이 사용하던 ''/etc/init.d/*'' 의 서비스를 systemd 명령으로 사용가능하다. * [[https://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts/233581#233581|How does systemd use /etc/init.d scripts? - Unix & Linux Stack Exchange]] * 이는 [[https://www.freedesktop.org/software/systemd/man/systemd-sysv-generator.html|systemd-sysv-generator]] 가 ''/etc/init.d/*''의 서비스를 읽어서 동적으로 systemd unit 으로 바꿔주기 때문이다. (''/usr/lib/systemd/system-generators/systemd-sysv-generator'') * systemd unit 은 ''/run/systemd/generator.late'' 에 ''*.service''로 동적으로 생성된다. * systemd 는 ''init.d''를 자동 인식하는게 아니라, systemd unit 이라고 인식하게 되는 것이다. * ''init.d''의 서비스 파일에는 주석으로 [[https://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html|LSB Headers]]라는 값이 들어있어서 systemd 로 변환하는 정보로 사용한다. ===== 참조 ===== * [[https://www.youtube.com/playlist?list=PL6IQ3nFZzWfpKKWfZMRxiuEBwqQBwjzS1|Systemd Tutorials - youtube]] * [[https://www.debugpoint.com/2021/01/systemd-journald-clean/|A Guide to systemd journal clean up process [With Examples]]] * [[https://www.youtube.com/watch?v=5JVBpXiYMKo&t=4s|Linux Essentials - systemd: Using the systemctl command - YouTube]] * [[https://gist.github.com/oprypin/0f0c3479ab53e00988b52919e5d7c144|systemd user unit + timer example]]