Projectile is great for this. I use C-c P u to run projectile-run-project and it runs my run command. I use it for golang mostly. If you run it while it's already running it will ask if you want to kill it first. I'm sure there's a way to automate that.