3

I'm trying to spin up docker container when I run a particular configuration in intellij, which I have done successfully by adding a 'Before Launch external tool command', as described here: IntelliJ IDEA: Running a shell script as a Run/Debug Configuration

What doesn't seem obvious though is how I stop the container when the program has finished running? There doesn't seem to be any options for after.

How do I run a shell script when my run configuration finishes? (Either by reaching it's end, or being forcefully stopped).

Andy
  • 3,228
  • 8
  • 40
  • 65
  • Add a configuration to stop and use before launch configuration to run? – CrazyCoder Apr 12 '18 at 20:05
  • I'm not exactly sure what you mean there, could you elaborate? Sorry but intellij is fairly new to me. – Andy Apr 13 '18 at 09:19
  • You can add a run configuration to run the shell script which will stop the container. Then you can add the before launch step in this configuration to run the container or whatever you need. Now if you start this configuration, it will first perform the before launch step and once it's complete, it will proceed with the shutdown script. – CrazyCoder Apr 13 '18 at 09:21
  • I'm not sure how the shutdown script gets called in this scenario though? The shutdown needs to happen after the debugger, not right after the startup script. I currently have a run configuration which runs the startup script as part of the before launch, however there doesn't appear to be a hook for after? – Andy Apr 13 '18 at 09:27
  • You can have a chain of configurations, running the last one will trigger the previous one which triggers the one before, etc. – CrazyCoder Apr 13 '18 at 09:28
  • Aha that looks like a good option thanks! Up to you but if you wouldn't mind doing a quick write up of that as an answer I can give you the kudos for it/it's here for future ref. – Andy Apr 13 '18 at 09:33
  • Looking for the answer as well. – Mikhail Kopylov Mar 21 '19 at 04:36
  • I didn't really find an answer to this in the end, I just modified my container setup so that it can run all of the time, and the before step of my run config just starts it up if it's not already started. you can do something with compound run configs, but the problem is that it runs each step asynchronously. – Andy Mar 25 '19 at 17:14

0 Answers0