1

We have a need for restarting a service frequently in certain special scenarios. So when it fails with start-limit, the suggested solution is to call "reset-failed". What we found is that, even after calling reset-failed, the immediate subsequent start do fail with start limit. The only work around is to introduce a pause of 6 seconds (sleep 6) before calling start, if previous has failed.

For test purpose, I made a overkill of calling reset-failed, before every start. Still it fails with start limit.

admin@vlab-03:~/tmp$ cat t.py 
#! /usr/bin/env python3

import os
import sys


def _service_restart(svc_name):
    rc_stop = os.system(f"sudo systemctl stop {svc_name}")
    rc_reset = os.system(f"sudo systemctl reset-failed {svc_name}")
    rc_start = os.system(f"sudo systemctl start {svc_name}")
    print(f"rc_stop={rc_stop} rc_reset={rc_reset} rc_start={rc_start}")

    if rc_start != 0:
        print("Exiting ...")
        sys.exit(-1)


def main():
    for i in range(10):
        print(f"-------------------i = {i} ---------------")
        _service_restart("rsyslog-config")

    print("done")


if __name__ == "__main__":
    main()

admin@vlab-03:~/tmp$ 


o/p:
admin@vlab-03:~/tmp$ ./t.py 
-------------------i = 0 ---------------
rc_stop=0 rc_reset=0 rc_start=0
-------------------i = 1 ---------------
rc_stop=0 rc_reset=0 rc_start=0
-------------------i = 2 ---------------
rc_stop=0 rc_reset=0 rc_start=0
-------------------i = 3 ---------------
rc_stop=0 rc_reset=0 rc_start=0
-------------------i = 4 ---------------
rc_stop=0 rc_reset=0 rc_start=0
-------------------i = 5 ---------------
Job for rsyslog-config.service failed because the control process exited with error code.
See "systemctl status rsyslog-config.service" and "journalctl -xe" for details.
rc_stop=0 rc_reset=0 rc_start=256
Exiting ...

Any tips would be very helpful.

admin@vlab-03:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
admin@vlab-03:~$ uname -a
Linux vlab-03 5.10.0-8-2-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux

0 Answers0