systemd 장치가 하나가 아닌 여러 인스턴스를 시작했습니다.

systemd 장치가 하나가 아닌 여러 인스턴스를 시작했습니다.

실패할 경우 bash 스크립트를 다시 시작해야 하는 systemd 장치를 설정하려고 합니다.

[Unit]
Description=Bash script Service

[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/bin/bash -c '/simple/bash/script.sh'

하지만 systemctl status the_bash_script.service여러 인스턴스로 시작하는 것처럼 보입니다.

● the_bash_script.service - Bash script Service
   Loaded: loaded (/etc/systemd/system/the_bash_script.service; static; vendor preset: enabled)
   Active: active (running) since Thu 2016-11-03 18:16:53 CET; 3 years 6 months ago
 Main PID: 1766 (bash)
   CGroup: /system.slice/the_bash_script.service
           ├─1766 /bin/bash -c '/bin/bash -c '/simple/bash/script.sh'
           └─1778 /bin/bash -c '/bin/bash -c '/simple/bash/script.sh'

왜 pid 1766과 1778이 2개 있나요? 한 번에 하나의 인스턴스만 허용할 수 있나요?

이것이 the_bash_script.service의 내용이라면 동시에 실행되는 여러 인스턴스가 필요하지 않습니다.

#!/bin/bash


while [ true ]; do
    cat /dev/virtual  | nc -v 192.168.1.1 5005    
    sleep 5s
done

exit

답변1

귀하의 ExecStart=/bin/bash -c '/simple/bash/script.sh'include /bin/bash -c 명령은 bash 쉘을 시작한 /simple/bash/script.sh다음 스크립트가 실행을 시작하면 /simple/bash/script.sh다른 bash 쉘을 시작한다고 생각합니다.

서비스 파일에서 다음을 시도해 보세요.

ExecStart=/simple/bash/script.sh

또한 다음 줄을 추가하고 시도해 보세요.

ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

관련 정보