mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
* Updated poweroff/reboot/maintenance mode for Upstart 0.6. Upstart
no longer emits specific events for those. Instead it emits a "runlevel" event. The "runlevel" task starts the "shutdown" task to perform the desired action. * Upstart 0.6 no longer has a "shutdown" event, so "stop on shutdown" no longer works. Therefore the shutdown task explicitly stops all running Upstart jobs, before sending a TERM/KILL signal to all remaining processes. * Do a "chvt 1" at the start of the shutdown task to switch to the console. * Use /dev/console instead of /dev/tty1, since if somebody is logged in on tty1, bad things will happen. svn path=/nixos/branches/upstart-0.6/; revision=18224
This commit is contained in:
parent
676da4d87d
commit
82c3e2aa50
|
@ -126,8 +126,8 @@
|
|||
./system/boot/stage-2.nix
|
||||
./system/etc/etc.nix
|
||||
./system/upstart-events/control-alt-delete.nix
|
||||
./system/upstart-events/halt.nix
|
||||
./system/upstart-events/maintenance-shell.nix
|
||||
./system/upstart-events/runlevel.nix
|
||||
./system/upstart-events/shutdown.nix
|
||||
./system/upstart/upstart.nix
|
||||
./tasks/filesystems.nix
|
||||
./tasks/kbd.nix
|
||||
|
|
|
@ -141,9 +141,6 @@ export MODULE_DIR=@kernel@/lib/modules/
|
|||
# For debugging Upstart.
|
||||
#@shell@ --login < /dev/console > /dev/console 2>&1 &
|
||||
|
||||
# Start Upstart's init. We start it through the
|
||||
# /var/run/current-system symlink indirection so that we can upgrade
|
||||
# init in a running system by changing the symlink and sending init a
|
||||
# HUP signal.
|
||||
# Start Upstart's init.
|
||||
echo "starting Upstart..."
|
||||
exec /var/run/current-system/upstart/sbin/init -v
|
||||
PATH=/var/run/current-system/upstart/sbin exec init
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
###### implementation
|
||||
|
||||
{
|
||||
jobs.maintenance_shell =
|
||||
{ name = "maintenance-shell";
|
||||
|
||||
startOn = [ "maintenance" "stalled" ];
|
||||
|
||||
task = true;
|
||||
|
||||
script =
|
||||
''
|
||||
exec < /dev/tty1 > /dev/tty1 2>&1
|
||||
echo \
|
||||
echo "<<< MAINTENANCE SHELL >>>"
|
||||
echo ""
|
||||
exec ${pkgs.bash}/bin/sh
|
||||
'';
|
||||
};
|
||||
}
|
25
modules/system/upstart-events/runlevel.nix
Normal file
25
modules/system/upstart-events/runlevel.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
{
|
||||
|
||||
jobs.runlevel =
|
||||
{ name = "runlevel";
|
||||
|
||||
startOn = "runlevel [0123456S]";
|
||||
|
||||
task = true;
|
||||
|
||||
script =
|
||||
''
|
||||
case "$RUNLEVEL" in
|
||||
0) initctl start shutdown MODE=poweroff;;
|
||||
1) initctl start shutdown MODE=maintenance;;
|
||||
6) initctl start shutdown MODE=reboot;;
|
||||
*) echo "Unsupported runlevel: $RUNLEVEL";;
|
||||
esac
|
||||
'';
|
||||
};
|
||||
|
||||
}
|
|
@ -2,29 +2,29 @@
|
|||
|
||||
with pkgs.lib;
|
||||
|
||||
###### implementation
|
||||
{
|
||||
|
||||
let
|
||||
|
||||
inherit (pkgs) bash utillinux;
|
||||
|
||||
jobFun = event:
|
||||
{ startOn = event;
|
||||
jobs.shutdown =
|
||||
{ name = "shutdown";
|
||||
|
||||
task = true;
|
||||
|
||||
environment = { MODE = "poweroff"; };
|
||||
|
||||
script =
|
||||
''
|
||||
set +e # continue in case of errors
|
||||
|
||||
${pkgs.kbd}/bin/chvt 1
|
||||
|
||||
exec < /dev/tty1 > /dev/tty1 2>&1
|
||||
exec < /dev/console > /dev/console 2>&1
|
||||
echo ""
|
||||
echo "<<< SYSTEM SHUTDOWN >>>"
|
||||
echo ""
|
||||
|
||||
export PATH=${utillinux}/bin:${utillinux}/sbin:$PATH
|
||||
|
||||
export PATH=${pkgs.utillinux}/bin:${pkgs.utillinux}/sbin:$PATH
|
||||
|
||||
|
||||
# Set the hardware clock to the system time.
|
||||
echo "setting the hardware clock..."
|
||||
hwclock --systohc --utc
|
||||
|
@ -32,6 +32,15 @@ let
|
|||
|
||||
# Do an initial sync just in case.
|
||||
sync
|
||||
|
||||
|
||||
# Stop all Upstart jobs.
|
||||
initctl list | while read jobName rest; do
|
||||
if test "$jobName" != shutdown; then
|
||||
echo "stopping $jobName..."
|
||||
stop "$jobName"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Kill all remaining processes except init and this one.
|
||||
|
@ -42,7 +51,20 @@ let
|
|||
|
||||
echo "sending the KILL signal to all processes..."
|
||||
kill -KILL -1
|
||||
|
||||
|
||||
|
||||
# If maintenance mode is requested, start a root shell, and
|
||||
# afterwards emit the "startup" event to bring everything
|
||||
# back up.
|
||||
if test "$MODE" = maintenance; then
|
||||
echo ""
|
||||
echo "<<< MAINTENANCE SHELL >>>"
|
||||
echo ""
|
||||
while ! ${pkgs.bash}/bin/bash --login; do true; done
|
||||
initctl emit startup
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# Unmount helper functions.
|
||||
getMountPoints() {
|
||||
|
@ -101,7 +123,7 @@ let
|
|||
|
||||
# Either reboot or power-off the system. Note that the "halt"
|
||||
# event also does a power-off.
|
||||
if test ${event} = reboot; then
|
||||
if test "$MODE" = reboot; then
|
||||
echo "rebooting..."
|
||||
sleep 1
|
||||
exec reboot -f
|
||||
|
@ -113,9 +135,4 @@ let
|
|||
'';
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
jobs = listToAttrs (map (n: nameValuePair "sys-${n}" (jobFun n))
|
||||
[ "reboot" "halt" "system-halt" "power-off" ] );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue