From owner-svn-src-head@freebsd.org Wed Oct 25 15:30:36 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 632FEE4D75B; Wed, 25 Oct 2017 15:30:36 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 40362720C7; Wed, 25 Oct 2017 15:30:36 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9PFUZQh018842; Wed, 25 Oct 2017 15:30:35 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9PFUZWG018619; Wed, 25 Oct 2017 15:30:35 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201710251530.v9PFUZWG018619@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Wed, 25 Oct 2017 15:30:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324986 - head/sbin/reboot X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sbin/reboot X-SVN-Commit-Revision: 324986 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Oct 2017 15:30:36 -0000 Author: imp Date: Wed Oct 25 15:30:35 2017 New Revision: 324986 URL: https://svnweb.freebsd.org/changeset/base/324986 Log: Add power cycle support to reboot/halt as -c. When -c is specified, the system will be power cycled if the underlying hardware supports it. Otherwise the system will be halted or rebooted depending on which command was used. Sponsored by: Netflix Modified: head/sbin/reboot/reboot.8 head/sbin/reboot/reboot.c Modified: head/sbin/reboot/reboot.8 ============================================================================== --- head/sbin/reboot/reboot.8 Wed Oct 25 15:30:30 2017 (r324985) +++ head/sbin/reboot/reboot.8 Wed Oct 25 15:30:35 2017 (r324986) @@ -28,7 +28,7 @@ .\" @(#)reboot.8 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd March 19, 2017 +.Dd October 23, 2017 .Dt REBOOT 8 .Os .Sh NAME @@ -42,7 +42,7 @@ .Op Fl lNnpq .Op Fl k Ar kernel .Nm -.Op Fl dlNnpqr +.Op Fl cdlNnpqr .Op Fl k Ar kernel .Nm fasthalt .Op Fl lNnpq @@ -66,6 +66,20 @@ accounting database. .Pp The options are as follows: .Bl -tag -width indent +.It Fl c +The system will turn off the power and then turn it back on if it can. +If the power down action fails, the system +will halt or reboot normally, depending on whether +.Nm halt +or +.Nm +was called. +At the present time, only the +.Xr ipmi 4 +driver implements the power cycle functionality and only on hardware +with a BMC that supports power cycling. +Unlike power off, the amount of hardware that supports power cycling +is small. .It Fl d The system is requested to create a crash dump. This option is @@ -162,6 +176,7 @@ reboot -r .Sh SEE ALSO .Xr kenv 1 , .Xr getutxent 3 , +.Xr ipmi 4 , .Xr boot 8 , .Xr dumpon 8 , .Xr nextboot 8 , Modified: head/sbin/reboot/reboot.c ============================================================================== --- head/sbin/reboot/reboot.c Wed Oct 25 15:30:30 2017 (r324985) +++ head/sbin/reboot/reboot.c Wed Oct 25 15:30:35 2017 (r324986) @@ -77,8 +77,11 @@ main(int argc, char *argv[]) } else howto = 0; lflag = nflag = qflag = Nflag = 0; - while ((ch = getopt(argc, argv, "dk:lNnpqr")) != -1) + while ((ch = getopt(argc, argv, "cdk:lNnpqr")) != -1) switch(ch) { + case 'c': + howto |= RB_POWERCYCLE; + break; case 'd': howto |= RB_DUMP; break; @@ -116,8 +119,10 @@ main(int argc, char *argv[]) errx(1, "cannot dump (-d) when halting; must reboot instead"); if (Nflag && (howto & RB_NOSYNC) != 0) errx(1, "-N cannot be used with -n"); + if ((howto & RB_POWEROFF) && (howto & RB_POWERCYCLE)) + errx(1, "-c and -p cannot be used together"); if ((howto & RB_REROOT) != 0 && howto != RB_REROOT) - errx(1, "-r cannot be used with -d, -n, or -p"); + errx(1, "-r cannot be used with -c, -d, -n, or -p"); if (geteuid()) { errno = EPERM; err(1, NULL); @@ -151,6 +156,12 @@ main(int argc, char *argv[]) } else if (howto & RB_REROOT) { openlog("reroot", 0, LOG_AUTH | LOG_CONS); syslog(LOG_CRIT, "rerooted by %s", user); + } else if (howto & RB_POWEROFF) { + openlog("reboot", 0, LOG_AUTH | LOG_CONS); + syslog(LOG_CRIT, "powered off by %s", user); + } else if (howto & RB_POWERCYCLE) { + openlog("reboot", 0, LOG_AUTH | LOG_CONS); + syslog(LOG_CRIT, "power cycled by %s", user); } else { openlog("reboot", 0, LOG_AUTH | LOG_CONS); syslog(LOG_CRIT, "rebooted by %s", user);