systemd - 원샷이 완료된 후 비활성화하고 다시 시작합니다.

systemd - 원샷이 완료된 후 비활성화하고 다시 시작합니다.

스크립트가 완료된 후 컴퓨터를 다시 시작하고 싶습니다. oneshot다음 다시 시작할 때 현재 서비스가 시작되지 않아야 합니다. 다음 시스템 단위 파일을 만들었습니다.

가상 서비스

[Unit]
Description=Custom Unit File Automation
Wants=multi-user.target
After=multi-user.target
SuccessAction=reboot

[Service]
User=veeru
Type=oneshot
RemainAfterExit=no
ExecStart=/bin/bash -c "<command> <args>"
StandardOutput=/var/log/command_out.log
StandardError=/var/log/command_err.log
ExecStartPost=/bin/bash -c "/usr/bin/sudo /usr/bin/systemctl disable /etc/systemd/system/playbook_2.service"


[Install]
WantedBy=multi-user.target

서비스를 비활성화할 수 있었습니다 systemctl. 하지만 컴퓨터를 다시 시작할 수 없습니다 status.

Jun 28 01:45:55 hyddrogen systemd[1]: [/etc/systemd/system/dummy.service:5] Unknown lvalue 'SuccessAction' in section 'Unit'

서비스를 비활성화하고 컴퓨터를 다시 시작하는 적절한 옵션이 있습니까? 삽입할 수 있지만 reboot삽입 ExecStartPost하고 싶지 않음

고쳐 쓰다

SuccessAction한테 선택권이 생겼어문서

답변1

약간의 파고 끝에 나는 이것을 할 수 있는 방법을 찾았습니다. 이것은 내 유닛 파일입니다

[Unit]
Description=Custom Unit File Automation
After=default.target
DefaultDependencies=no
Before=shutdown.target

[Service]
User=veeru
Type=oneshot
RemainAfterExit=no
ExecStart=/bin/bash -c "<command> <args>"
StandardOutput=file:/var/log/command_out.log
StandardError=file:/var/log/command_err.log
ExecStartPost=/usr/bin/sudo /usr/bin/systemctl disable /etc/systemd/system/dummy.service
ExecStop=/usr/bin/sudo /usr/sbin/reboot

[Install]
WantedBy=default.target

~에서systemd "oneshot" 서비스가 종료를 트리거합니다., 다시 시작하기 전에 데몬을 중지하는 더 좋은 방법 DefaultDependencies=no인 및 를 추가했습니다 .Before=shutdown.target

답변2

이 솔루션은 약간 구식인 것 같습니다. 재시작을 호출하는 일회성 서비스가 왜 필요한지 이해할 수 없습니다. 왜 스크립트를 사용하지 않습니까?

어쨌든, 정말로 이 작업을 시스템 단위로 수행하고 싶다면 간단히 한 번에 파일을 터치한 다음 조건을 사용하여 해당 파일을 확인할 수 있습니다.

예를 들어:

[Unit]
ConditionPathExists=/var/Custom_command.data

관련 정보