Tag Info

Hot answers tagged

76

Anyone can execute shutdown, but triggering a system shutdown requires root privileges. But shutdown is not setuid, and so only root can successfully execute it. The shutdown program is nice enough to check your privileges and let you know if there is a problem, but even if it naively tried a system shutdown, nothing would happen. GLENDOWER: I can call ...


40

Generally, one uses the shutdown command. It allows a time delay and warning message before shutdown or reboot, which is important for system administration of multiuser shell servers; it can provide the users with advance notice of the downtime. As such, the shutdown command has to be used like this to halt/switch off the computer immediately (on Linux and ...


39

You can do this directly from the shutdown command, see man shutdown: SYNOPSIS /sbin/shutdown [-akrhPHfFnc] [-t sec] time [warning message] [...] time When to shutdown. So, for example: shutdown -g 21:45 That will run shutdown -h at 21:45. For commands that don't offer this functionality, you can try one of: A. Using at The at daemon ...


35

And now, the systemd answer. You're using, per the tag on your question, Red Hat Enterprise Linux. Since version 7, that has used systemd. None of the other answers are correct for the world of systemd; nor even are some of the assumptions in your question. Forget about runlevels; they exist, but only as compatibility shims. The systemd documentation ...


32

There is no difference in them. Internally they do exactly the same thing: reboot uses the shutdown command (with the -r switch). The shutdown command used to kill all the running processes, unmount all the file systems and finally tells the kernel to issue the ACPI power command. The source can be found here. In older distros the reboot command was ...


27

It doesn't get much faster than using the System Request (SysRq) functionality and then triggering an immediate reboot. This is a key combination understood by the kernel. Enable SysRq: echo 1 > /proc/sys/kernel/sysrq Now, send it into reboot. echo b > /proc/sysrq-trigger b - Immediately reboot the system, without unmounting or syncing ...


24

Try the following commands: Display list of last reboot entries: last reboot | less Display list of last shutdown entries: last -x | less or more precisely: last -x | grep shutdown | less You won't know who did it however. If you want to know who did it, you will need to add a bit of code which means you'll know next time. I've found this resource ...


22

The hardware power button triggers an ACPI event that acpid (the ACPI daemon) notices and reacts to; in this case by shutting down the system, although you could have it do whatever you want. The ACPI daemon runs as root, so it has permission to shutdown the system. Desktop environments (e.g. gdm for Gnome) typically run as root as well, so I suspect they ...


20

Linux Mint is based on Ubuntu, so I'm guesing the runlevel system is probably the same. On Ubuntu, scripts for the different runlevels are executed according to their presence in the /etc/rc[0-6].d directories. Runlevel 0 corresponds to shutdown, and 6 to reboot. Typically the script itself is stored in /etc/init.d, and then symlinks are placed in the ...


19

It's a bit historical. halt was used before ACPI (which today will turn off the power for you)*. It would halt the system and then print a message to the effect of "it's ok to power off now". Back then there were physical on/off switches, rather than the combo ACPI controlled power button of modern computers. poweroff, naturally will halt the system and ...


18

It depends you started task. If it is some command line tool you could simply run halt or shutdown -h now: wget http://..../somelargefile; halt - halt will be executed after wget wget http://..../somelargefile && halt - halt will be executed if wget return no errors wget http://..../somelargefile || halt - halt will be executed if wget return ...


17

halt instructs the hardware to stop all CPU functions, but leaves it in a powered-on state. This usually means someone has to reboot or shut the machine down manually by pressing the power button afterwards. The specific way to achieve this is architecture specific, but for instance the x86 instruction set provides the HLT instructions which halts the ...


15

We don't necessarily need them both, but we have them both because of the history of Unix, and its multiplicity of versions. From their respective man pages: The shutdown utility appeared in 4.0BSD. A reboot utility appeared in Version 6 AT&T UNIX. shutdown is more general-purpose, and more powerful, while reboot is friendlier and easier to ...


15

The binary shutdown itself checks if your UID is 0. See the strace output of: strace /sbin/shutdown -r -h now ... ... geteuid() = 10001 setuid(10001) = 0 getuid() = 10001 write(2, "shutdown: Need to be root\n", 26shutdown: Need to be root ) = 26 exit_group(1) ...


13

Depending on your distro use the chkconfig or update-rc.d tool to enable/disable system services. On a redhat/suse/mandrake style system: sudo chkconfig apache2 off On Debian: sudo update-rc.d -f apache2 remove Checkout their man pages for more info.


12

On most Linux systems, the Ctrl+Alt+Del key sequence action is configured in either /etc/inittab or /etc/init/control-alt-delete.conf. Usually, this will reboot the system, but you could modify the command to halt the system instead. In /etc/inittab: ca::ctrlaltdel:/sbin/shutdown -t3 -h now Or /etc/init/control-alt-delete.conf: start on ...


11

You can run shutdown -c to cancel an already running shutdown.


11

Try Molly guard: $ sudo apt-get install molly-guard This package will prevent unintended shutdown/reboot/suspend/hibernate by interactively prompting you to enter the hostname of the system. However, it's trivial to configure molly-guard to completely disable shutdown/reboot/suspend/hibernate. Simply create an executable file at ...


11

You can suspend or hibernate your system and then automatically wake it up with rtcwake command. For example to suspend (to ram) and resume in 60 seconds do rtcwake -s 60 -m mem To hibernate (suspend to disk) in one hour from now and resume in two hours: sleep 3600; rtcwake -s 3600 -m disk You can also wakeup the system at given time with -t option ...


10

Only root privileged programs can gracefully shutdown a system. So when a system shuts down in a normal way, it is either a user with root privileges or an acpi script. In both cases you can find out by checking the logs. An acpi shutdown can be caused by power button press, overheating or low battery (laptop). I forgot the third reason, UPS software when ...


10

If you are fast enough you can issue an init 2 (or whatever runlevel you want) and that will likely stop the shutdown. Anything involving killing the shutdown command will fail as the command runs too quickly I tried this with the script below and and even it's not fast enough to stop the shutdown #!/bin/bash shutdown -h now shutdown -c "Aborting ...


10

If you can still access a text mode console, or if you can log in remotely: You can use ps or other process listing tools and kill to try killing some processes. A few programs will save your work (at least to a recovery file) if they receive a kill -HUP or plain kill. They might not have time to do it if you go straight for rebooting. Run sudo kill ...


10

There seems to be no way to log this data to a file. For the boot process, there is the bootlogd package which creates the file /var/log/boot, but nothing for the shutdown/reboot process. As far as I can see there is no way to log with rsyslog either, and even if there was, there are messages printed after rsyslog is stopped. Part of my shutdown/reboot ...


9

If your system uses PAM, the login denial when /etc/nologin exists is triggered by the pam_nologin module. You can skip the pam_nologin invocation for users matching certain criteria with pam_succeed_if. For example, if you want to allow users in the adm group to log in on a text console even if /etc/nologin exists, add the following line to ...


9

The suggested solution is to run the service unit as a normal service - have a look at the [Install] section. So everything has to be thought reverse, dependencies too. Because the shutdown order is the reverse startup order. That's why the script has to be placed in ExecStop. The following solution is working for me: [Unit] Description=... [Service] ...


9

You should be able to do this with a mains timer between the mains outlet and the power supply. Shut down the Raspberry at 4 A.M using a cron job, then set the timer to cut the mains a bit later and to restore power at 5 A.M.


8

You should always use shutdown. You can add this to your ~/.bashrc file: PROMPT_COMMAND='history -a' This will append the in-memory history to your history file after each command is completed.


8

I suspect this is somewhat dependant on which version of UNIX/Linux you are using. On Centos (and I expec other modern Linux) halt calls shutdown (providing you're not at runlevel 0 or 6) so your system will be shutdown cleanly. On Solaris 10 halt is more brutal, it just flushes the disk caches and powers off the system - no attempt is made to run any ...


8

Not really (at least, to my knowledge). If you've got SystemV style init scripts, you could create something along the lines of /etc/rc6.K00scriptname and /etc/rc0.d/K00scriptname, which should get executed prior to any of the other scripts in there.


8

They're not the same thing, just very closely related. In practice, unless you want to specify a particular time to shutdown or to force an immediate unclean reboot/halt/poweroff, it really doesn't matter whether you run shutdown -h or halt... or shutdown -r vs reboot. Things weren't so nicely convenient in the past, but this is the way it works now (a lot ...



Only top voted, non community-wiki answers of a minimum length are eligible