Catatan: Saya menulis artikel di Medium yang menjelaskan cara membuat layanan, dan cara menghindari masalah khusus ini: Membuat layanan Linux dengan systemd .
Pertanyaan asli:
Saya menggunakan systemd untuk membuat skrip pekerja berfungsi setiap saat:
[Unit]
Description=My worker
After=mysqld.service
[Service]
Type=simple
Restart=always
ExecStart=/path/to/script
[Install]
WantedBy=multi-user.target
Meskipun restart berfungsi dengan baik jika skrip keluar secara normal setelah beberapa menit, saya perhatikan bahwa jika itu berulang kali gagal dieksekusi pada startup, systemdhanya akan menyerah mencoba untuk memulainya:
Jun 14 11:10:31 localhost systemd[1]: test.service: Main process exited, code=exited, status=1/FAILURE
Jun 14 11:10:31 localhost systemd[1]: test.service: Unit entered failed state.
Jun 14 11:10:31 localhost systemd[1]: test.service: Failed with result 'exit-code'.
Jun 14 11:10:31 localhost systemd[1]: test.service: Service hold-off time over, scheduling restart.
Jun 14 11:10:31 localhost systemd[1]: test.service: Start request repeated too quickly.
Jun 14 11:10:31 localhost systemd[1]: Failed to start My worker.
Jun 14 11:10:31 localhost systemd[1]: test.service: Unit entered failed state.
Jun 14 11:10:31 localhost systemd[1]: test.service: Failed with result 'start-limit'.
Demikian pula, jika skrip pekerja saya gagal beberapa kali dengan status keluar dari 255, systemdmenyerah mencoba untuk me-restart itu:
Jun 14 11:25:51 localhost systemd[1]: test.service: Failed with result 'exit-code'.
Jun 14 11:25:51 localhost systemd[1]: test.service: Service hold-off time over, scheduling restart.
Jun 14 11:25:51 localhost systemd[1]: test.service: Start request repeated too quickly.
Jun 14 11:25:51 localhost systemd[1]: Failed to start My worker.
Jun 14 11:25:51 localhost systemd[1]: test.service: Unit entered failed state.
Jun 14 11:25:51 localhost systemd[1]: test.service: Failed with result 'start-limit'.
Apakah ada cara untuk memaksa systemduntuk selalu mencoba lagi setelah beberapa detik?
StartLimitIntervalSec=0dan voila.