github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/jujud/reboot/reboot_windows.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Copyright 2014 Cloudbase Solutions SRL
     3  // Licensed under the AGPLv3, see LICENCE file for details.
     4  
     5  package reboot
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/juju/juju/apiserver/params"
    11  )
    12  
    13  // scheduleAction will do a reboot or shutdown after given number of seconds
    14  // this function executes the operating system's reboot binary with apropriate
    15  // parameters to schedule the reboot
    16  // If action is params.ShouldDoNothing, it will return immediately.
    17  // NOTE: On Windows the shutdown command is async
    18  func scheduleAction(action params.RebootAction, after int) error {
    19  	if action == params.ShouldDoNothing {
    20  		return nil
    21  	}
    22  	args := []string{"shutdown.exe", "-f"}
    23  	switch action {
    24  	case params.ShouldReboot:
    25  		args = append(args, "-r")
    26  	case params.ShouldShutdown:
    27  		args = append(args, "-s")
    28  	}
    29  	args = append(args, "-t", fmt.Sprintf("%d", after))
    30  
    31  	return runCommand(args)
    32  }