transient process는 1회용 서비스로 systemd-run 을 사용하여 실행
systemd-run --unit=name --scope --slice=slice_name command
옵션 | 설명 |
---|---|
--unit | 유닛 이름 설정. 생략시 자동으로 생성 |
--scope | foreground에서 작동. 생략시 daemon으로 작동 |
--slice | slice는 프로세스의 묶음. 어떤 슬라이스에 등록할 것인지 |
--on-active time | 일정 시간 후 자동 실행 |
-p | property 설정 |
root@jsg-ubuntu:~# systemd-run --unit=my_every5s --scope --slice=my_slice \ /home/jsg/every_5sec.sh Running scope as unit my_every5s.scope. 2021. 01. 03. (일) 05:45:06 KST 2021. 01. 03. (일) 05:45:11 KST 2021. 01. 03. (일) 05:45:16 KST ^C
root@jsg-ubuntu:~# systemd-run --unit=my_every5s --slice=my_slice \ /home/jsg/every_5sec.sh Running as unit my_every5s.service. root@jsg-ubuntu:~# systemctl status my_every5s.service ● my_every5s.service - /home/jsg/every_5sec.sh Loaded: loaded Transient: yes Drop-In: /run/systemd/system/my_every5s.service.d └─50-Description.conf, 50-ExecStart.conf, 50-Slice.conf Active: active (running) since 일 2021-01-03 05:48:54 KST; 21s ago Main PID: 103822 (every_5sec.sh) CGroup: /my_slice.slice/my_every5s.service ├─103822 /bin/bash /home/jsg/every_5sec.sh └─103838 sleep 5
root@jsg-ubuntu:~# systemctl stop my_every5s.service root@jsg-ubuntu:~# systemctl status my_every5s ● my_every5s.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)
root@jsg-ubuntu:~# systemctl start my_every5s Failed to start my_every5s.service: Unit my_every5s.service not found.
systemctl -t slice
로 확인 가능root@jsg-ubuntu:~# systemctl -t slice UNIT LOAD ACTIVE SUB DESCRIPTION -.slice loaded active active Root Slice my_slice.slice loaded active active my_slice.slice system-getty.slice loaded active active system-getty.slice system-systemd\x2dfsck.slice loaded active active system-systemd\x2dfsck.slice system.slice loaded active active System Slice test_slice.slice loaded active active test_slice.slice user-1000.slice loaded active active User Slice of jsg user.slice loaded active active User and Session Slice
옵션 | 설명 |
---|---|
CPUWeight=200 | 가중치를 200으로 설정, default: 100 |
CPUQuota=20% | CPU 할당을 20퍼만 받을수 있음 |
MemoryLimit=value | 메모리제한, infinity 면 제한 없음 |
MemoryMin=10M | 10M 는 release되지 않고 보호 됨 |
MemoryHigh=value | 느슨한 상한, 넘을수는 있지만 되도록 안넘도록 조정된다 |
MemoryLow=value | 느슨한 하한 |
IOWeight=value | IO 가중치, default : 100 |
root@jsg-ubuntu:~# systemd-run -p CPUQuota=20% --unit=my_every5s --slice=my_slice \ /home/jsg/every_5sec.sh Running as unit my_every5s.service. root@jsg-ubuntu:~# systemctl status my_every5s.service ● my_every5s.service - /home/jsg/every_5sec.sh Loaded: loaded Transient: yes Drop-In: /run/systemd/system/my_every5s.service.d └─50-CPUQuota.conf, 50-Description.conf, 50-ExecStart.conf, 50-Slice. Active: active (running) since 일 2021-01-03 06:53:54 KST; 11s ago Main PID: 104477 (every_5sec.sh) CPU: 6ms # 요 값이 추가됨을 볼 수 있음 CGroup: /my_slice.slice/my_every5s.service ├─104477 /bin/bash /home/jsg/every_5sec.sh └─104487 sleep 5
root@jsg-ubuntu:~# journalctl -f -u my_every5s -- Logs begin at 목 2020-12-31 00:20:01 KST. -- 1월 03 06:54:44 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:54:44 KST 1월 03 06:54:49 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:54:49 KST 1월 03 06:54:54 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:54:54 KST 1월 03 06:54:59 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:54:59 KST 1월 03 06:55:04 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:55:04 KST 1월 03 06:55:09 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:55:09 KST 1월 03 06:55:14 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:55:14 KST 1월 03 06:55:19 jsg-ubuntu every_5sec.sh[104477]: 2021. 01. 03. (일) 06:55:19 KST 1월 03 06:55:22 jsg-ubuntu systemd[1]: Stopping /home/jsg/every_5sec.sh... 1월 03 06:55:22 jsg-ubuntu systemd[1]: Stopped /home/jsg/every_5sec.sh.