Call app.start only if app is not running already

If I call app.start myApp while the app is already running, it seems to basically RESTART it, which is not what I want. Therefore, I’m trying to put together a command that checks first if the app is already running.

This is what I’ve cobbled together so far:
[ $(midclt call app.container_ids myApp) = "{}" ] && midclt call app.start myApp

It seems to work basically, but if the app is already running, I’m always getting a message like this:
zsh: condition expected: {"c776bc7fe454095a7a6f838f4bdb656d4da72fb7768f4128cdc557d8c5fcd601":

I guess this has more to do with my lack of skill in the shell and less with midclt, but I would appreciate any ideas.

Thank you.

If i remember well, you can call app.query and retrive all ix apps info, including the state.
Setup this call before the app.start, build your array conditionally on the app not in running state, and you should achieve this easily

2 Likes

In this example, am using it for the app I named “acme”, change that to your app name.

midclt call app.query '[["name", "=", "acme"]]' | jq -r '.[] | .state'

If the output is RUNNING, then, well, it’s running!

2 Likes

Thanks a lot @sfatula and @oxyde, the approach with app.query works perfectly:

[ $(midclt call app.query '[["name", "=", "myApp"]]' | jq -r '.[] | .state') != "RUNNING" ] && midclt call app.start myApp

1 Like