mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-15 15:06:42 +00:00
Add power cycle support (-c) to shutdown.
Sponsored by: Netflix
This commit is contained in:
parent
dae8f61f5b
commit
e60baa7252
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=324985
@ -28,7 +28,7 @@
|
|||||||
.\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95
|
.\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd September 21, 2016
|
.Dd October 23, 2017
|
||||||
.Dt SHUTDOWN 8
|
.Dt SHUTDOWN 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -39,7 +39,7 @@
|
|||||||
.Nm
|
.Nm
|
||||||
.Op Fl
|
.Op Fl
|
||||||
.Oo
|
.Oo
|
||||||
.Fl h | Fl p |
|
.Fl c | Fl h | Fl p |
|
||||||
.Fl r | Fl k
|
.Fl r | Fl k
|
||||||
.Oc
|
.Oc
|
||||||
.Oo
|
.Oo
|
||||||
@ -59,12 +59,22 @@ would otherwise not bother with such niceties.
|
|||||||
.Pp
|
.Pp
|
||||||
The following options are available:
|
The following options are available:
|
||||||
.Bl -tag -width indent
|
.Bl -tag -width indent
|
||||||
|
.It Fl c
|
||||||
|
The system is power cycled (power turned off and then back on)
|
||||||
|
at the specified time.
|
||||||
|
If the hardware doesn't support power cycle, the system will be
|
||||||
|
halted.
|
||||||
|
At the present time, only systems with BMC supported by the
|
||||||
|
.Xr ipmi 4
|
||||||
|
driver that implement this functionality support this flag.
|
||||||
|
The amount of time the system is off is dependent on the device
|
||||||
|
that implements this feature.
|
||||||
.It Fl h
|
.It Fl h
|
||||||
The system is halted at the specified
|
The system is halted at the specified
|
||||||
.Ar time .
|
.Ar time .
|
||||||
.It Fl p
|
.It Fl p
|
||||||
The system is halted and the power is turned off
|
The system is halted and the power is turned off
|
||||||
(hardware support required)
|
(hardware support required, otherwise the system is halted)
|
||||||
at the specified
|
at the specified
|
||||||
.Ar time .
|
.Ar time .
|
||||||
.It Fl r
|
.It Fl r
|
||||||
@ -79,6 +89,7 @@ does not actually halt the system, but leaves the
|
|||||||
system multi-user with logins disabled (for all but super-user).
|
system multi-user with logins disabled (for all but super-user).
|
||||||
.It Fl o
|
.It Fl o
|
||||||
If one of the
|
If one of the
|
||||||
|
.Fl c ,
|
||||||
.Fl h ,
|
.Fl h ,
|
||||||
.Fl p
|
.Fl p
|
||||||
or
|
or
|
||||||
|
@ -89,7 +89,7 @@ static struct interval {
|
|||||||
#undef S
|
#undef S
|
||||||
|
|
||||||
static time_t offset, shuttime;
|
static time_t offset, shuttime;
|
||||||
static int dohalt, dopower, doreboot, killflg, mbuflen, oflag;
|
static int docycle, dohalt, dopower, doreboot, killflg, mbuflen, oflag;
|
||||||
static char mbuf[BUFSIZ];
|
static char mbuf[BUFSIZ];
|
||||||
static const char *nosync, *whom;
|
static const char *nosync, *whom;
|
||||||
|
|
||||||
@ -141,11 +141,14 @@ main(int argc, char **argv)
|
|||||||
goto poweroff;
|
goto poweroff;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "-hknopr")) != -1)
|
while ((ch = getopt(argc, argv, "-chknopr")) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '-':
|
case '-':
|
||||||
readstdin = 1;
|
readstdin = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
docycle = 1;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
dohalt = 1;
|
dohalt = 1;
|
||||||
break;
|
break;
|
||||||
@ -174,11 +177,11 @@ main(int argc, char **argv)
|
|||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage((char *)NULL);
|
usage((char *)NULL);
|
||||||
|
|
||||||
if (killflg + doreboot + dohalt + dopower > 1)
|
if (killflg + doreboot + dohalt + dopower + docycle > 1)
|
||||||
usage("incompatible switches -h, -k, -p and -r");
|
usage("incompatible switches -c, -h, -k, -p and -r");
|
||||||
|
|
||||||
if (oflag && !(dohalt || dopower || doreboot))
|
if (oflag && !(dohalt || dopower || doreboot || docycle))
|
||||||
usage("-o requires -h, -p or -r");
|
usage("-o requires -c, -h, -p or -r");
|
||||||
|
|
||||||
if (nosync != NULL && !oflag)
|
if (nosync != NULL && !oflag)
|
||||||
usage("-n requires -o");
|
usage("-n requires -o");
|
||||||
@ -356,8 +359,8 @@ die_you_gravy_sucking_pig_dog(void)
|
|||||||
char *empty_environ[] = { NULL };
|
char *empty_environ[] = { NULL };
|
||||||
|
|
||||||
syslog(LOG_NOTICE, "%s by %s: %s",
|
syslog(LOG_NOTICE, "%s by %s: %s",
|
||||||
doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" :
|
doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" :
|
||||||
"shutdown", whom, mbuf);
|
docycle ? "power-cycle" : "shutdown", whom, mbuf);
|
||||||
|
|
||||||
(void)printf("\r\nSystem shutdown time has arrived\007\007\r\n");
|
(void)printf("\r\nSystem shutdown time has arrived\007\007\r\n");
|
||||||
if (killflg) {
|
if (killflg) {
|
||||||
@ -367,6 +370,8 @@ die_you_gravy_sucking_pig_dog(void)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (doreboot)
|
if (doreboot)
|
||||||
(void)printf("reboot");
|
(void)printf("reboot");
|
||||||
|
else if (docycle)
|
||||||
|
(void)printf("power-cycle");
|
||||||
else if (dohalt)
|
else if (dohalt)
|
||||||
(void)printf("halt");
|
(void)printf("halt");
|
||||||
else if (dopower)
|
else if (dopower)
|
||||||
@ -379,6 +384,7 @@ die_you_gravy_sucking_pig_dog(void)
|
|||||||
(void)kill(1, doreboot ? SIGINT : /* reboot */
|
(void)kill(1, doreboot ? SIGINT : /* reboot */
|
||||||
dohalt ? SIGUSR1 : /* halt */
|
dohalt ? SIGUSR1 : /* halt */
|
||||||
dopower ? SIGUSR2 : /* power-down */
|
dopower ? SIGUSR2 : /* power-down */
|
||||||
|
docycle ? SIGWINCH : /* power-cycle */
|
||||||
SIGTERM); /* single-user */
|
SIGTERM); /* single-user */
|
||||||
} else {
|
} else {
|
||||||
if (doreboot) {
|
if (doreboot) {
|
||||||
@ -402,6 +408,13 @@ die_you_gravy_sucking_pig_dog(void)
|
|||||||
_PATH_HALT);
|
_PATH_HALT);
|
||||||
warn(_PATH_HALT);
|
warn(_PATH_HALT);
|
||||||
}
|
}
|
||||||
|
else if (docycle) {
|
||||||
|
execle(_PATH_HALT, "halt", "-l", "-c", nosync,
|
||||||
|
(char *)NULL, empty_environ);
|
||||||
|
syslog(LOG_ERR, "shutdown: can't exec %s: %m.",
|
||||||
|
_PATH_HALT);
|
||||||
|
warn(_PATH_HALT);
|
||||||
|
}
|
||||||
(void)kill(1, SIGTERM); /* to single-user */
|
(void)kill(1, SIGTERM); /* to single-user */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user