시작 시 IP 표시 - centos 7

시작 시 IP 표시 - centos 7

systemctl을 처음 접했기 때문에 centos를 부팅할 때 콘솔에 가상 머신 IP 주소를 표시하고 싶습니다.

서비스를 생성하고 활성화했습니다.

[root@centos-3 system]# cat show-ip-on-boot.service
[Unit]
Description=Show IP of eno interface on boot

[Service]
Type=oneshot
ExecStart=/usr/bin/show-ip-on-boot.sh

[Install]
WantedBy=multi-user.target

"show-ip-on-boot.sh" 스크립트는 다음과 같습니다.

 #!/bin/sh

 ip a | grep "inet" | grep "eno" | awk -F/ '{print $1}' | awk '{print $2}'

서비스를 수동으로 시작하면 서비스가 작동 중임을 로그에서 확인할 수 있습니다.

[root@centos-3 ~]# journalctl -u show-ip-on-boot
-- Logs begin at Thu 2016-10-06 13:59:38 CEST, end at Thu 2016-10-06 14:15:37 CEST. --
Oct 06 14:04:32 centos-3.localdomain systemd[1]: Starting Show IP of eno interface on boot...
Oct 06 14:04:32 centos-3.localdomain show-ip-on-boot.sh[2180]: 192.168.0.43
Oct 06 14:04:32 centos-3.localdomain systemd[1]: Started Show IP of eno interface on boot.

하지만 시작 시 콘솔에 표시되는 것을 어떻게 볼 수 있나요? 스크립트에 추가해야 할 것이 있나요?

또한 재부팅하면 서비스가 시작되지만 명령을 실행하지 않는다는 로그를 볼 수 있습니다.

[root@centos-3 ~]# systemctl status show-ip-on-boot.service
â show-ip-on-boot.service - Show IP of eno interface on boot
Loaded: loaded (/etc/systemd/system/show-ip-on-boot.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2016-10-06 13:33:55 CEST; 1min 52s ago
Process: 740 ExecStart=/usr/bin/show-ip-on-boot.sh (code=exited, status=0/SUCCESS)
Main PID: 740 (code=exited, status=0/SUCCESS)

Oct 06 13:33:54 centos-3.localdomain systemd[1]: Starting Show IP of eno interface on boot...
Oct 06 13:33:55 centos-3.localdomain systemd[1]: Started Show IP of eno interface on boot.

시스템 개념에서 뭔가 빠졌을 수도 있습니다. 이 문제에 대한 힌트를 주실 수 있나요? 감사해요.

답변1

systemd는 서비스의 출력을 수집하고 이를 기록합니다(대개 이것이 사용자가 원하는 것이므로 서비스의 출력은 지속적입니다).

StandardOutput다음과 같은 설정 및 옵션을 통해 StandardError특정 서비스의 동작을 변경할 수 있습니다.시스템 실행(5)매뉴얼 페이지에는 다음과 같이 나와 있습니다.

StandardOutput=

실행된 프로세스의 파일 설명자 1(STDOUT)이 연결되는 위치를 제어합니다. 상속, null, tty, 저널, syslog, kmsg, 저널+콘솔, syslog+콘솔, kmsg+콘솔 또는 소켓 중 하나를 사용하세요.

[...]

journal+console, syslog+console이는 kmsg+console위의 세 가지 옵션과 유사하게 작동하지만 출력을 시스템 콘솔에 복사하기도 합니다.

따라서 이론적으로는 다음과 같은 방법이 필요합니다.

[Service]
Type=oneshot
ExecStart=/usr/bin/show-ip-on-boot.sh
StandardOutput=journal+console

답변2

서비스가 필요하지 않습니다. /etc/issue 파일에 한 줄만 추가하면 됩니다. 내 /etc/issue 파일 아래:

\에스

커널\r은 \m에 있습니다.

내 IP 주소: \4{enp0s3} <----- 줄 추가,

VirtualBox와 함께 Centos 7을 사용합니다.

"enp03s"는 IP를 알고 싶은 네트워크 인터페이스 카드입니다.

관련 정보