1

On (Debian) Linux I want to:

  • Execute a command.
  • If the command doesn't complete in 10 seconds, kill it and try another command.

The use-case is:

I have a daemon service which I would like to shut down gracefully. It can be stopped by sending a TCP command. If the TCP command does not return, kill the process using Posix HUP.

start-stop-daemon doesn't seem to do this, anyone got any hints ?

1 Answers1

0

I also didn't give a medal for the debian people implemented start-stop-daemon.

I think, you want to make a workaround about some daemon. There is a tool named timeout in the GNU CoreUtils package, which could you help to do this:

timeout --kill-after=15 --signal=9 this_is_my_command || this_will_run_on_fail

It will run this_is_my_command, and if it timeouts, it will kill this with signal 9 (hard kill), and run the command this_will_run_on_fail.

I get this information partially from this question.

peterh
  • 4,914
  • 13
  • 29
  • 44