Час від часу бувають ситуації, коли підвисає дискова підсистема і нормальними (reboot/shutdown) засобами сервер не перевантажиться, бо перед перевантаженням ОС повинна зробити sync на диски, а цього вона зробити не може, бо “висить”. Це називається cold reboot, так би мовити “reboot по живленню”.
IPMItools
Якщо на сервері присутній iDRAC/IPMI/ILO/… то можна спробувати перевантажити сервер через ipmitools:
# ipmitool chassis powercycle
або, якщо це робити віддалено (будь-який з варіантів)
ssh user@X.X.X.X /usr/bin/sudo -S <<< "sudo password" /usr/sbin/ipmitool power cycle
echo "sudo password" | ssh -tt user@X.X.X.X "sudo /usr/sbin/ipmitool power cycle"
SysRq
Це магічна клавіша на клавіатурі (знаходиться разом з клавішою print screen) для low level керування ОС. І вона працює тільки під Linux (можливо і під іншими ОС, але мені про це невідомо). За її допомогою можна виконувати багато чого. Щоб дізнатися чи увімкнена дана можливість, треба перевірити значення /proc/sys/kernel/sysrq: якщо 0 – відключено, 1 – включено.
Вмикаємо можливість:
# echo "1" > /proc/sys/kernel/sysrq
Ось що можна робити через SysRq:
| Command | Function |
|---|---|
b | Will immediately reboot the system without syncing or unmounting your disks. |
c | Will perform a system crash and a crashdump will be taken if configured. |
d | Shows all locks that are held. |
e | Send a SIGTERM to all processes, except for init. |
f | Will call the oom killer to kill a memory hog process, but do not panic if nothing can be killed. |
g | Used by kgdb (kernel debugger) |
h | Will display help (actually any other key than those listed here will display help. but h is easy to remember 🙂 |
i | Send a SIGKILL to all processes, except for init. |
j | Forcibly “Just thaw it” – filesystems frozen by the FIFREEZE ioctl. |
k | Secure Access Key (SAK) Kills all programs on the current virtual console. NOTE: See important comments below in SAK section. |
l | Shows a stack backtrace for all active CPUs. |
m | Will dump current memory info to your console. |
n | Used to make RT tasks nice-able |
o | Will shut your system off (if configured and supported). |
p | Will dump the current registers and flags to your console. |
q | Will dump per CPU lists of all armed hrtimers (but NOT regular timer_list timers) and detailed information about all clockevent devices. |
r | Turns off keyboard raw mode and sets it to XLATE. |
s | Will attempt to sync all mounted filesystems. |
t | Will dump a list of current tasks and their information to your console. |
u | Will attempt to remount all mounted filesystems read-only. |
v | Forcefully restores framebuffer console |
v | Causes ETM buffer dump [ARM-specific] |
w | Dumps tasks that are in uninterruptible (blocked) state. |
x | Used by xmon interface on ppc/powerpc platforms. Show global PMU Registers on sparc64. Dump all TLB entries on MIPS. |
y | Show global CPU Registers [SPARC-64 specific] |
z | Dump the ftrace buffer |
0–9 | Sets the console log level, controlling which kernel messages will be printed to your console. (0, for example would make it so that only emergency messages like PANICs or OOPSes would make it to your console.) |
R | Replay the kernel log messages on consoles. |
Для виконання можна або натиснути відповідну комбінацію Alt+SysRq+<command_key> або
# echo <command_key> > /proc/sysrq-trigger
Якщо треба ввести декілька команд, то додаємо символ підкреслювання і далі ключі:
# echo _reisub > /proc/sysrq-trigger
Додатково скажу, що у кожної <command_key> є відповідний числовий ідентифікатор зі степенню 2-ки:
0 - disable every SysRq function.
1 - enable every SysRq function.
2 - enable control of console logging level
4 - enable control of keyboard (SAK, unraw)
8 - enable debugging dumps of processes etc.
16 - enable sync command
32 - enable remount read-only
64 - enable signalling of processes (term, kill, oom-kill)
128 - allow reboot/poweroff
256 - allow nicing of all RT tasks
і тому для комбінації декількох значень просто передаємо суму (176=16+32+128):
# echo 176 > /proc/sysrq-trigger
FreeBSD
Тут, нажаль, немає такого зручного інструменту і єдиний варіант – викликати паніку ядра:
# sysctl debug.kdb.panic=1