/
nohup 를 대체하는 systemd-run 명령어 사용법
nohup 를 대체하는 systemd-run 명령어 사용법
daemon 으로 작성하지 않았지만 back group 로 돌아가야 하는 명령어. 혹은 현재 로그인 세션이 끊어져도 계속 실행해야 하는 배치 명령어등은 nohup로 실행할수 있습니다.
systemd-run 은 단기로 실행해야 하는 .service 나 .scope 유닛이나 또는 특정 커맨드를 실행할 수 있으므로 전통적인 nohup 를 대체할 수 있습니다.
실행
$ sudo systemd-run ls Running as unit: run-r1234.service
journalctl 로 실행한 서비스의 상태를 확인할 수 있습니다.
$ sudo journalctl -u run-r1234.service Running as unit: run-r1234.service
예제
env 변수 값 로깅
env 명령으로 systemd 가 서비스에 전달하는 환경 변수 값을 logging 할 수 있습니다.
$ sudo systemd-run env Running as unit: run-reb6fa83b994f4766906b30aafaf13a03.service
실행된 unit 번호를 journalctl 에 전달하면 systemd 가 service 에 전달한 환경변수를 확인할 수 있습니다.
$ sudo journalctl -u run-reb6fa83b994f4766906b30aafaf13a03.service -- Logs begin at Tue 2021-03-16 19:51:24 EDT, end at Tue 2021-04-20 10:11:31 EDT. -- Apr 20 10:11:31 kccf-dev.lesstif.com systemd[1]: Started /bin/env. Apr 20 10:11:31 kccf-dev.lesstif.com env[688817]: LANG=ko_KR.UTF-8 Apr 20 10:11:31 kccf-dev.lesstif.com env[688817]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin Apr 20 10:11:31 kccf-dev.lesstif.com env[688817]: INVOCATION_ID=fdedf2cb7d3d46e0a261a279e6ee8ab7 Apr 20 10:11:31 kccf-dev.lesstif.com env[688817]: JOURNAL_STREAM=9:15368433 Apr 20 10:11:31 kccf-dev.lesstif.com systemd[1]: run-reb6fa83b994f4766906b30aafaf13a03.service: Succeeded.
property 설정 및 실행
-p 옵션으로 실행할 서비스나 scope unit 의 프로퍼티를 설정할 수 있습니다. 다음은 updatedb 명령을 실행하면서 block I/O weight 를 10으로 제한합니다.
$ sudo systemd-run -p BlockIOWeight=10 updatedb
정해진 시간에 실행
--on-active 옵션뒤에 시간(초 단위)을 설정하면 해당 시간 뒤에 명령어를 실행합니다.
$ date; sudo systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo
같이 보기
Ref
, multiple selections available,
Related content
터미널이 끊어져도 프로세스가 실행되는 nohup 명령어
터미널이 끊어져도 프로세스가 실행되는 nohup 명령어
More like this
systemd를 관리하는 systemctl 주요 사용법
systemd를 관리하는 systemctl 주요 사용법
More like this
linux systemd(systemctl) 로 run level(target) 관리하기
linux systemd(systemctl) 로 run level(target) 관리하기
More like this
linux systemctl 명령으로 부팅 타겟(booting target) 지정하기
linux systemctl 명령으로 부팅 타겟(booting target) 지정하기
More like this
구동 프로세스 최소화
구동 프로세스 최소화
More like this
리눅스 슈퍼 바이저 데몬(Linux super visor daemon)로 프로세스 관리하기
리눅스 슈퍼 바이저 데몬(Linux super visor daemon)로 프로세스 관리하기
More like this