2006-12-10 23:29:44 +01:00
|
|
|
#! @shell@
|
|
|
|
|
|
|
|
set -e
|
|
|
|
export PATH=/empty
|
2006-12-18 17:27:56 +01:00
|
|
|
for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done
|
2006-12-10 23:29:44 +01:00
|
|
|
action="$1"
|
|
|
|
|
2006-12-16 22:48:12 +01:00
|
|
|
if ! test -e /etc/NIXOS; then
|
|
|
|
echo "This is not a NixOS installation (/etc/NIXOS) is missing!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-12-10 23:29:44 +01:00
|
|
|
if test -z "$action"; then
|
|
|
|
cat <<EOF
|
|
|
|
Usage: $0 [switch|boot|test]
|
|
|
|
|
|
|
|
switch: make the configuration the boot default and activate now
|
|
|
|
boot: make the configuration the boot default
|
|
|
|
test: activate the configuration, but don't make it the boot default
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-12-16 19:11:26 +01:00
|
|
|
# Install or update the bootloader.
|
|
|
|
if [ "$action" = "switch" -o "$action" = "boot" ]; then
|
|
|
|
|
|
|
|
if [ "@bootLoader@" = "grub" ]; then
|
|
|
|
|
|
|
|
if [ -n "@grubDevice@" ]; then
|
Making modular my previous changes for armv5tel. I updated the way to use
grub. Its options are no more inside 'boot', but inside 'boot.loader.grub'.
I added a new bootloader configuration for nixos, generationsDir. It creates
/boot/default/{init,initrd,kernel,system} symlinks, and the same for the generations
in /boot/system-$gen/{init,initrd,kernel,system}.
I can program the u-boot loader to load /boot/default files always, and have
a minimal nixos boot loader installer functionality. Additionally, I can refer
to the other system generations easily, with a simple 'ls' in /boot.
svn path=/nixos/trunk/; revision=17460
2009-09-27 23:51:37 +02:00
|
|
|
mkdir -m 0700 -p /boot/grub
|
|
|
|
@menuBuilder@ @out@
|
2009-12-16 19:11:26 +01:00
|
|
|
|
2010-07-22 16:40:29 +02:00
|
|
|
if [ "@grubDevice@" != nodev ]; then
|
|
|
|
|
|
|
|
# If the GRUB version has changed, then force a reinstall.
|
|
|
|
oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)"
|
|
|
|
newGrubVersion="@grubVersion@"
|
|
|
|
|
|
|
|
if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then
|
|
|
|
echo "installing the GRUB bootloader..."
|
2011-06-22 20:22:58 +02:00
|
|
|
@grub@/sbin/grub-install "$(readlink -f "@grubDevice@")" --no-floppy
|
2010-07-22 16:40:29 +02:00
|
|
|
echo "$newGrubVersion" > /boot/grub/version
|
|
|
|
fi
|
Making modular my previous changes for armv5tel. I updated the way to use
grub. Its options are no more inside 'boot', but inside 'boot.loader.grub'.
I added a new bootloader configuration for nixos, generationsDir. It creates
/boot/default/{init,initrd,kernel,system} symlinks, and the same for the generations
in /boot/system-$gen/{init,initrd,kernel,system}.
I can program the u-boot loader to load /boot/default files always, and have
a minimal nixos boot loader installer functionality. Additionally, I can refer
to the other system generations easily, with a simple 'ls' in /boot.
svn path=/nixos/trunk/; revision=17460
2009-09-27 23:51:37 +02:00
|
|
|
fi
|
2009-12-16 19:11:26 +01:00
|
|
|
|
Making modular my previous changes for armv5tel. I updated the way to use
grub. Its options are no more inside 'boot', but inside 'boot.loader.grub'.
I added a new bootloader configuration for nixos, generationsDir. It creates
/boot/default/{init,initrd,kernel,system} symlinks, and the same for the generations
in /boot/system-$gen/{init,initrd,kernel,system}.
I can program the u-boot loader to load /boot/default files always, and have
a minimal nixos boot loader installer functionality. Additionally, I can refer
to the other system generations easily, with a simple 'ls' in /boot.
svn path=/nixos/trunk/; revision=17460
2009-09-27 23:51:37 +02:00
|
|
|
else
|
2011-06-22 20:22:58 +02:00
|
|
|
echo "Warning: don't know how to make this configuration bootable; please set \`boot.loader.grub.device'." 1>&2
|
Making modular my previous changes for armv5tel. I updated the way to use
grub. Its options are no more inside 'boot', but inside 'boot.loader.grub'.
I added a new bootloader configuration for nixos, generationsDir. It creates
/boot/default/{init,initrd,kernel,system} symlinks, and the same for the generations
in /boot/system-$gen/{init,initrd,kernel,system}.
I can program the u-boot loader to load /boot/default files always, and have
a minimal nixos boot loader installer functionality. Additionally, I can refer
to the other system generations easily, with a simple 'ls' in /boot.
svn path=/nixos/trunk/; revision=17460
2009-09-27 23:51:37 +02:00
|
|
|
fi
|
2009-12-16 19:11:26 +01:00
|
|
|
|
|
|
|
elif [ "@bootLoader@" = "generationsDir" ]; then
|
2009-12-17 13:35:58 +01:00
|
|
|
@menuBuilder@ @out@
|
2006-12-10 23:29:44 +01:00
|
|
|
else
|
2009-12-17 13:35:58 +01:00
|
|
|
echo "Warning: don't know how to make this configuration bootable; please enable a boot loader." 1>&2
|
2006-12-10 23:29:44 +01:00
|
|
|
fi
|
2009-12-17 07:04:36 +01:00
|
|
|
|
2009-12-17 13:35:58 +01:00
|
|
|
if [ -n "@initScriptBuilder@" ]; then
|
|
|
|
@initScriptBuilder@ @out@
|
|
|
|
fi
|
2006-12-10 23:29:44 +01:00
|
|
|
fi
|
|
|
|
|
2009-12-16 19:11:26 +01:00
|
|
|
# Activate the new configuration.
|
|
|
|
if [ "$action" = "switch" -o "$action" = "test" ]; then
|
2006-12-18 17:27:56 +01:00
|
|
|
|
2009-04-28 15:38:22 +02:00
|
|
|
oldVersion=$(cat /var/run/current-system/upstart-interface-version 2> /dev/null || echo 0)
|
|
|
|
newVersion=$(cat @out@/upstart-interface-version 2> /dev/null || echo 0)
|
|
|
|
|
|
|
|
if test "$oldVersion" -ne "$newVersion"; then
|
|
|
|
cat <<EOF
|
|
|
|
Warning: the new NixOS configuration has an Upstart version that is
|
|
|
|
incompatible with the current version. The new configuration won't
|
|
|
|
take effect until you reboot the system.
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-11-07 02:17:56 +01:00
|
|
|
oldJobs=$(readlink -f /etc/static/init)
|
|
|
|
newJobs=$(readlink -f @out@/etc/init)
|
2006-12-18 17:27:56 +01:00
|
|
|
|
2006-12-19 02:34:09 +01:00
|
|
|
stopJob() {
|
|
|
|
local job=$1
|
2009-11-07 02:17:56 +01:00
|
|
|
initctl stop "$job" || true
|
2006-12-19 02:34:09 +01:00
|
|
|
}
|
|
|
|
|
2006-12-18 17:27:56 +01:00
|
|
|
# Stop all services that are not in the new Upstart
|
|
|
|
# configuration.
|
2009-11-07 02:17:56 +01:00
|
|
|
for job in $(cd $oldJobs && ls *.conf); do
|
|
|
|
job=$(basename $job .conf)
|
|
|
|
if ! test -e "$newJobs/$job.conf"; then
|
|
|
|
echo "stopping $job..."
|
|
|
|
stopJob $job
|
2006-12-18 17:27:56 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Activate the new configuration (i.e., update /etc, make
|
|
|
|
# accounts, and so on).
|
2009-05-18 14:01:31 +02:00
|
|
|
echo "activating the configuration..."
|
2007-03-20 14:01:53 +01:00
|
|
|
@out@/activate @out@
|
2006-12-18 17:27:56 +01:00
|
|
|
|
2009-11-07 02:17:56 +01:00
|
|
|
# Make Upstart reload its jobs.
|
|
|
|
initctl reload-configuration
|
2006-12-18 17:27:56 +01:00
|
|
|
|
|
|
|
# Start all new services and restart all changed services.
|
2009-11-07 02:17:56 +01:00
|
|
|
for job in $(cd $newJobs && ls *.conf); do
|
2006-12-21 19:08:29 +01:00
|
|
|
|
2009-11-07 02:17:56 +01:00
|
|
|
job=$(basename $job .conf)
|
|
|
|
|
|
|
|
# Hack: skip the shutdown and control-alt-delete jobs.
|
2007-03-04 00:18:56 +01:00
|
|
|
# Another hack: don't restart the X server (that would kill all the clients).
|
2009-09-26 23:00:47 +02:00
|
|
|
# And don't restart dbus, since that causes ConsoleKit to
|
|
|
|
# forget about current sessions.
|
2010-07-15 14:31:18 +02:00
|
|
|
# Idem for the emergeny-shell, because its `console owner'
|
|
|
|
# line screws up the X server.
|
2010-10-06 18:07:16 +02:00
|
|
|
# Idem for xendomains because we don't want to save/restore
|
|
|
|
# Xen domains unless we have to.
|
|
|
|
# TODO: Jobs should be able to declare that they should not be
|
|
|
|
# auto-restarted.
|
2011-11-03 03:14:57 +01:00
|
|
|
if echo "$job" | grep -q "^shutdown$\|^control-alt-delete$\|^xserver$\|^dbus$\|^disnix$\|^emergency-shell$\|^xendomains$\|^udevtrigger$\|^drbd-down$"; then continue; fi
|
2009-11-07 02:17:56 +01:00
|
|
|
|
|
|
|
if ! test -e "$oldJobs/$job.conf"; then
|
|
|
|
echo "starting $job..."
|
|
|
|
initctl start "$job" || true
|
|
|
|
elif test "$(readlink "$oldJobs/$job.conf")" != "$(readlink "$newJobs/$job.conf")"; then
|
|
|
|
echo "restarting $job..."
|
|
|
|
stopJob $job
|
|
|
|
initctl start "$job" || true
|
2006-12-18 17:27:56 +01:00
|
|
|
fi
|
|
|
|
done
|
2010-07-23 12:52:51 +02:00
|
|
|
|
|
|
|
# Signal dbus to reload its configuration.
|
|
|
|
dbusPid=$(initctl status dbus 2> /dev/null | sed -e 's/.*process \([0-9]\+\)/\1/;t;d')
|
|
|
|
[ -n "$dbusPid" ] && kill -HUP "$dbusPid"
|
|
|
|
|
2006-12-10 23:29:44 +01:00
|
|
|
fi
|