github.com/koron/hk@v0.0.0-20150303213137-b8aeaa3ab34c/restart.go (about) 1 package main 2 3 import ( 4 "log" 5 "os" 6 "strings" 7 ) 8 9 var cmdRestart = &Command{ 10 Run: runRestart, 11 Usage: "restart [<type or name>]", 12 NeedsApp: true, 13 Category: "dyno", 14 Short: "restart dynos (or stop a dyno started with 'hk run')", 15 Long: ` 16 Restart all app dynos, all dynos of a specific type, or a single dyno. If used 17 on a dyno started using 'hk run' this will effectively stop it. 18 19 Examples: 20 21 $ hk restart 22 Restarted all dynos on myapp. 23 24 $ hk restart web 25 Restarted web dynos on myapp. 26 27 $ hk restart web.1 28 Restarted web.1 dyno on myapp. 29 `, 30 } 31 32 func runRestart(cmd *Command, args []string) { 33 appname := mustApp() 34 if len(args) > 1 { 35 cmd.PrintUsage() 36 os.Exit(2) 37 } 38 39 target := "all" 40 if len(args) == 1 { 41 target = args[0] 42 must(client.DynoRestart(appname, target)) 43 } else { 44 must(client.DynoRestartAll(appname)) 45 } 46 47 switch { 48 case strings.Contains(target, "."): 49 log.Printf("Restarted %s dyno for %s.", target, appname) 50 default: 51 log.Printf("Restarted %s dynos for %s.", target, appname) 52 } 53 }