Skip to main content
95 votes

How to find out from the logs what caused system shutdown?

TLDR Use these 2 commands and keep reading for more information. last -x | head | tac grep -iv ': starting\|kernel: .*: Power Button\|watching system buttons\|Stopped Cleaning Up\|Started Crash ...
ndemou's user avatar
  • 2,829
70 votes

How do I shut down a Linux server after running for 60 minutes?

There are a several options. Provide time directly to shutdown -P: shutdown -P +60 Note that shutdown man page also points out: If the time argument is used, 5 minutes before the system goes ...
sebasth's user avatar
  • 15.1k
56 votes

A stop job is running for Session c2 of user

A workaround to this problem is to reduce this timeout in /etc/systemd/system.conf down from 90s to for example 10s: DefaultTimeoutStopSec=10s and run the following command in terminal after making ...
MightyPork's user avatar
  • 1,222
48 votes
Accepted

What is the difference between shutdown 18:00 and at 18:00 shutdown?

at 18:00 shutdown now creates an "at" job, which is performed at the specified time by the at daemon or perhaps the cron daemon, depending on your system. shutdown 18:00 starts a process in your ...
wurtel's user avatar
  • 16.2k
43 votes

A stop job is running for Session c2 of user

This problem can have many causes, so specific answers don't work too well. Try this for troubleshooting: wait for the "A stop job is running for Session c2 ..." message to appear on shutdown and ...
mzuther is on OpenAI strike's user avatar
43 votes
Accepted

What exactly is "a stop job", as in "A stop job is running..."?

systemd operates internally in terms of a queue of "jobs". Each job (simplifying a little bit) is an action to take: stop, check, start, or restart a particular unit. When (for example) you ...
JdeBP's user avatar
  • 69.3k
35 votes
Accepted

How can I prevent the second command in a chain while keeping the first one running?

As you clarified in comments it's still running in foreground on an interactive shell, you should just be able to press Ctrl+Z. That will suspend the ./command job. Unless ./command actually ...
Stéphane Chazelas's user avatar
33 votes

How do I shut down a Linux server after running for 60 minutes?

This looks like an XY problem. My tasks take usually no more than 15 minutes. I would like to implement a mechanism to shutdown it automatically after 60 minutes. If you shut down after 60 minutes,...
Lie Ryan's user avatar
  • 1,238
25 votes

How to run a script with systemd right before shutdown?

To run a service right before starting any of reboot/shutdown/halt/kexec services (i.e. in the last moment before root filesystem becomes remounted read-only) use this service config: [Unit] ...
Piotr Jurkiewicz's user avatar
25 votes
Accepted

How to halt a script at a specific time until it is started again by cron?

You can run it with the timeout command, timeout - run a command with a time limit Synopsis timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]... timeout [OPTION] Description Start COMMAND, and kill it ...
Rabin's user avatar
  • 3,893
24 votes

What is the difference between shutdown 18:00 and at 18:00 shutdown?

And now, the systemd answer. If you have CentOS 7, you have a systemd operating system and the answer is different. at 18:00 shutdown now still schedules via the at subsystem, but that shutdown ...
JdeBP's user avatar
  • 69.3k
22 votes
Accepted

How do I shut down a Linux server after running for 60 minutes?

If you execute your tasks as the same user every time, you can simply add the shutdown command, optionally with the option -P, to your profile. The number stands for the amount of minutes the shutdown ...
Dirk Krijgsman's user avatar
20 votes

systemd: How to check scheduled time of a delayed shutdown?

# cat /run/systemd/shutdown/scheduled USEC=1537242600000000 WARN_WALL=1 MODE=poweroff The USEC is a unix epoch timestamp with microsecond precision, so: if [ -f /run/systemd/shutdown/scheduled ]; ...
Delian Krustev's user avatar
19 votes

Execute a command before shutdown

Now that the Ubuntu variants and Mint have moved to systemd I found my old solutions based on the above to be less satisfactory. I searched around the web to find out how to do it with systemd and ...
John 9631's user avatar
  • 306
19 votes
Accepted

Find last shutdown time

According to your output: shutdown system down 3.14-1-amd64 Mon Jul 21 08:43 - 22:19 (13:36) You shutdown your system on July 21 at 08:43 and then after 13 hours and 36 minutes on July 21 at ...
Sajjad Hoviegar's user avatar
18 votes

What is the difference between reboot , init 6 and shutdown -r now?

Shutdown is preferable because it allows you to specify the reason for the drastic action -- something you should always do. The message will be recorded in the log(s) for posterity. For example: ...
Mikhail T.'s user avatar
18 votes
Accepted

shutdown, but still allow new logins

You could simply not use shutdown with a time specification, but echo shutdown -h now | at now + 5 minutes or similar; a simple sleep $((60*5)) ; shutdown -h now would do, too. However, using at has ...
Marcus Müller's user avatar
16 votes
Accepted

systemd: How to check scheduled time of a delayed shutdown?

Most simple: (and working on Debian/Ubuntu and RedHat) date --date @$(head -1 /run/systemd/shutdown/scheduled |cut -c6-15)
jamacoe's user avatar
  • 448
16 votes
Accepted

What signal is sent to running programs / scripts on shutdown?

While on shutdown the running processes are first told to stop by init(from sendsigs on old implementations, according to @JdeBP)/systemd. The remaining processes, if any, are sent a SIGTERM. The ...
Rui F Ribeiro's user avatar
13 votes

Why do I get the error "failed unmounting /var" during shutdown?

The problem is journald Or rather how it is still logging to /var while systemd is trying to unmount it. Solutions According to this thread, there are two ways to go about it: Make journald log to a ...
Thibault Lemaire's user avatar
13 votes

shutdown at specific date

The at command is for scheduling one off future executions. e.g. % at 8pm Aug 31 at> echo hello at> <EOT> job 161 at Sat Aug 31 20:00:00 2019 (the "<EOT>" was produced by pressing ...
Stephen Harris's user avatar
12 votes
Accepted

Is it possible to remotely cancel a scheduled shutdown when /run/nologin exists?

Beside of using "root" account to make a new ssh connection, we can actually use PAM to allow specific user or groups logging in. PAM configurations of sshd are located at: /etc/pam.d/sshd which are ...
Ravexina's user avatar
  • 2,658
11 votes

How to simulate unplugged network cable or down server?

When using the top voted answer on a machine you are connecting via SSH, you will bring down the network and have no means of bringing it back up. The following is a way to bring it down and bring it ...
Mocking's user avatar
  • 317
11 votes

Unexpected shutdown with a "Power key pressed." log

The most obvious answer is, of course, that someone pushed the power button. Possibly accidentally — e.g., if the power button is unfortunately sensitive and someone bumped it slightly while walking ...
derobert's user avatar
  • 110k
10 votes

Poweroff or Reboot as normal User

You can also create a new file under /etc/sudoers.d name it as you wish(I named it 'shutdown'), and put the following lines inside: # Allows me to shutdown the system without a password yourUserName ...
Guanaco Devs's user avatar
10 votes
Accepted

Systemd : How to execute script at shutdown only (not at reboot)

I've finally found how to do that. It's a bit hackish thought, but it works. I've used some part of this thread : https://stackoverflow.com/questions/25166085/how-can-a-systemd-controlled-service-...
benoit2600's user avatar
9 votes

How to halt a script at a specific time until it is started again by cron?

If your sync can easily continue after 17 hours of hibernation, try 0 0 * * * killall -CONT -g sync.sh || /usr/local/bin/sync.sh 7 0 * * * killall -STOP -g sync.sh If your sync prefers to restart ...
Roman Czyborra's user avatar
9 votes
Accepted

Is there a POSIX way to shutdown a UNIX machine?

No, POSIX does not care about the shutting down or rebooting of a Unix system, nor about how services are started at boot. The following areas are outside of the scope of POSIX.1-2017: Graphics ...
Kusalananda's user avatar
  • 338k
9 votes

How can I prevent the second command in a chain while keeping the first one running?

You could just rename /sbin/poweroff temporarily.
Bib's user avatar
  • 2,430
9 votes

Docker 20.10.x keeps system waiting for several minutes before shutdown or reboot

If you're using live-restore, then this is a known issue of containerd shim v2. Fixed in containerd ≥ 1.6.0-rc.2. Backported to containerd 1.5.10. Fixed in Docker Engine 20.10.13. https://github.com/...
youfu's user avatar
  • 261

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