0

I have binary file that I run like env SOME_VARS=some_values ./my_binary

Is there a way that when this execution ends (be it that it ends correctly or it crashes or it gets killed, whatever), it gets started again with the same environment variables?

Ivan
  • 313

2 Answers2

0

If you are manually calling a script, and if you just want to run it indefinitely even if it crashes, and if you are using a shell like sh or bash, you can just put your command in an infinite loop, like:

From:

env SOME_VARS=some_values ./my_binary

To:

while :; do
    env SOME_VARS=some_values ./my_binary
done

Doing it in one line:

while :; do env SOME_VARS=some_values ./my_binary; done

This is just a super-minimal and manual example. There are better ways to do this with systemd. But this is probably the minimal answer.

0

You didn't specify platform, I will assume Linux. In which case the Restart and Environment options of a systemd service unit could work nicely. These can be defined in user specific units so it can be run as a non privileged user.

John Mahowald
  • 36,071