재부팅 후 여러 "화면" 스크립트를 시작하는 가장 좋은 방법은 무엇입니까? (가리키다)

재부팅 후 여러 "화면" 스크립트를 시작하는 가장 좋은 방법은 무엇입니까? (가리키다)

우리는 센토스를 사용하고 있습니다. 서버가 재부팅되고 운영 체제가 완전히 로드되면 특정 사용자("foo")가 screen을 사용하여 3~4개의 스크립트를 실행하기를 원합니다.

예를 들어,

screen -d -m -S script1 forever -o script1.log -e script1.log -l script1.log -c php /path/to/script1.php

CentOS를 사용하여 이를 달성하는 가장 좋은 방법은 무엇입니까? 나는 init.d를 너무 많이 조사하는 것을 피하고 싶습니다.

systemd를 사용하여 서비스("알림")를 확인해 보았고 다음을 확인했습니다.

   Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
   Active: failed (Result: exit-code) since Sun 2016-03-20 15:08:04 EDT; 14s ago
  Process: 1690 ExecStop=/usr/bin/screen -S notify -X quit (code=exited, status=1/FAILURE)
  Process: 941 ExecStart=/usr/bin/screen -d -m -S notify forever -o notifyout.log -e notifyerr.log -l notifyforever.log -c php /path/to/script/notify.php (code=exited, status=0/SUCCESS)
 Main PID: 946 (code=exited, status=0/SUCCESS)

왜 차단되나요? 디버깅을 어떻게 시작할 수 있나요?

답변1

CentOS 7이므로 systemd 서비스를 사용하여 서비스를 시작해야 합니다. 화면 내에서 실행되도록 할 수도 있습니다. ~에서아치리눅스 위키:

파일을 생성합니다:/etc/systemd/system/[email protected]

[Unit]
Description=screen
After=network.target

[Service]
Type=simple
User=%i
ExecStart=/usr/bin/screen -DmS autoscreen
ExecStop=/usr/bin/screen -S autoscreen -X quit

[Install]
WantedBy=multi-user.target

그런 다음 활성화합니다. 어떤 사용자로도 실행하지 않으려면 활성화할 때 파일 이름의 @와 유닛 이름의 @USERNAME을 제거하고 유닛 파일에 사용자를 하드코딩할 수 있습니다.systemctl enable [email protected]

답변2

수정 /etc/rc.local해서 추가했어요

/etc/init.d/start_bg_scripts

그런 다음 다음을 추가했습니다 /etc/init.d/start_bg_scripts.

#!/bin/bash
/usr/bin/screen -d -m -S script1 forever --minUptime 1 --spinSleepTime 1 -o script1out.log -e script1err.log -l script1forever.log -c php /path/to/script.php

--minUptime 1 및 --spinSleepTime 1은 나머지 시스템 서비스(예: mysqld)를 사용할 수 있을 때까지 계속 재연결을 시도함을 의미합니다.

관련 정보