Search code examples
pythonbashubuntuhigh-availabilitykeepalived

When a Python Script Runs and Ends With sys.exit(0) Gives Error: exited with status 2


I am trying to make keepalived configurations and a script which I use and ends directly with sys.exit(0) gives that error:

/usr/bin/script.py exited with status 2

What can I do to correct that?

My Script's code:

import sys
sys.exit(0)

My Keepalived conf file:

vrrp_script chk_myscript {
    script       "/usr/bin/script.py"
    interval 2
    fall 2
    rise 2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 20
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.121
    }
    track_script {
       myscript
    }
}

Solution

  • You're missing the shebang, so the script currently doesn't get interpreted as a python script. Add #!/usr/bin/env python to the top of the script to fix that.