Home > Software design >  Trap docker signal and stop process in bash not working
Trap docker signal and stop process in bash not working

Time:01-21

I have already read and try this

  • TOP-Command

    This is the GitHub branch where I'm doing the testing: fix-exit

    First thanks to everyone that try to help me and second I just don't want to copy and paste a code, I want to understand why isn't working, because that's the issue I have, I'm clueless and that's why I'm unable to fix it, even documentation it's appreciated.

    CodePudding user response:

    The problem was that I wasn't running the script asynchronous, and bash was waiting to end the tail command at the end of install.sh (which was "endless"), here is the part of the code that was changed:

    # Change user to sdtdserver
    su-exec sdtdserver bash /home/sdtdserver/install.sh &
    # If bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes.
    # When bash is waiting for an asynchronous command via the wait builtin,
    # the reception of a signal for which a trap has been set will cause the 'wait' builtin to return immediately with an exit status greater than 128,
    # immediately after which the trap is executed.
    wait $!
    

    Also, this man had the same problem, but I didn't know that the tail was the problem.

    SIGTERM signal not caught when the last process is tail

  •  Tags:  
  • Related