2006-12-10 22:29:44 +00:00
|
|
|
|
#! @shell@
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
export PATH=/empty
|
2006-12-18 16:27:56 +00:00
|
|
|
|
for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done
|
2006-12-10 22:29:44 +00:00
|
|
|
|
action="$1"
|
|
|
|
|
|
2006-12-16 21:48:12 +00:00
|
|
|
|
if ! test -e /etc/NIXOS; then
|
|
|
|
|
echo "This is not a NixOS installation (/etc/NIXOS) is missing!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2006-12-10 22:29:44 +00: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 18:11:26 +00:00
|
|
|
|
# Install or update the bootloader.
|
|
|
|
|
if [ "$action" = "switch" -o "$action" = "boot" ]; then
|
|
|
|
|
|
|
|
|
|
if [ "@bootLoader@" = "grub" ]; then
|
|
|
|
|
|
2012-03-13 13:17:43 +00:00
|
|
|
|
if [ -n "@grubDevices@" ]; 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 21:51:37 +00:00
|
|
|
|
mkdir -m 0700 -p /boot/grub
|
|
|
|
|
@menuBuilder@ @out@
|
2009-12-16 18:11:26 +00:00
|
|
|
|
|
2012-03-13 13:17:43 +00:00
|
|
|
|
# If the GRUB version has changed, then force a reinstall.
|
|
|
|
|
oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)"
|
|
|
|
|
newGrubVersion="@grubVersion@"
|
2010-07-22 14:40:29 +00:00
|
|
|
|
|
2012-03-13 13:17:43 +00:00
|
|
|
|
if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then
|
|
|
|
|
for dev in @grubDevices@; do
|
|
|
|
|
if [ "$dev" != nodev ]; then
|
|
|
|
|
echo "installing the GRUB bootloader on $dev..."
|
|
|
|
|
@grub@/sbin/grub-install "$(readlink -f "$dev")" --no-floppy
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
echo "$newGrubVersion" > /boot/grub/version
|
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 21:51:37 +00:00
|
|
|
|
fi
|
2009-12-16 18:11:26 +00: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 21:51:37 +00:00
|
|
|
|
else
|
2011-06-22 18:22:58 +00: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 21:51:37 +00:00
|
|
|
|
fi
|
2009-12-16 18:11:26 +00:00
|
|
|
|
|
|
|
|
|
elif [ "@bootLoader@" = "generationsDir" ]; then
|
2009-12-17 12:35:58 +00:00
|
|
|
|
@menuBuilder@ @out@
|
2012-03-13 19:27:59 +00:00
|
|
|
|
elif [ "@bootLoader@" = "efiBootStub" ]; then
|
|
|
|
|
@menuBuilder@ @out@
|
2006-12-10 22:29:44 +00:00
|
|
|
|
else
|
2009-12-17 12:35:58 +00:00
|
|
|
|
echo "Warning: don't know how to make this configuration bootable; please enable a boot loader." 1>&2
|
2006-12-10 22:29:44 +00:00
|
|
|
|
fi
|
2009-12-17 06:04:36 +00:00
|
|
|
|
|
2009-12-17 12:35:58 +00:00
|
|
|
|
if [ -n "@initScriptBuilder@" ]; then
|
|
|
|
|
@initScriptBuilder@ @out@
|
|
|
|
|
fi
|
2006-12-10 22:29:44 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2009-12-16 18:11:26 +00:00
|
|
|
|
# Activate the new configuration.
|
2012-03-18 01:53:35 +00:00
|
|
|
|
if [ "$action" != switch -a "$action" != test ]; then exit 0; fi
|
2006-12-18 16:27:56 +00:00
|
|
|
|
|
2012-03-18 01:53:35 +00: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)
|
2009-04-28 13:38:22 +00:00
|
|
|
|
|
2012-03-18 01:53:35 +00:00
|
|
|
|
if test "$oldVersion" -ne "$newVersion"; then
|
2009-04-28 13:38:22 +00:00
|
|
|
|
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
|
2012-03-18 01:53:35 +00:00
|
|
|
|
fi
|
2009-04-28 13:38:22 +00:00
|
|
|
|
|
2012-03-18 01:53:35 +00:00
|
|
|
|
newJobs=$(readlink -f @out@/etc/init)
|
2006-12-18 16:27:56 +00:00
|
|
|
|
|
2012-03-18 01:53:35 +00:00
|
|
|
|
# Stop all currently running jobs that are not in the new Upstart
|
|
|
|
|
# configuration. (Here "running" means all jobs that are not in the
|
|
|
|
|
# stop/waiting state.)
|
|
|
|
|
for job in $(initctl list | sed -e '/ stop\/waiting/ d; /^[^a-z]/ d; s/^\([^ ]\+\).*/\1/' | sort); do
|
|
|
|
|
if ! [ -e "$newJobs/$job.conf" ] ; then
|
|
|
|
|
echo "stopping obsolete job ‘$job’..."
|
2009-11-07 01:17:56 +00:00
|
|
|
|
initctl stop "$job" || true
|
2012-03-18 01:53:35 +00:00
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Activate the new configuration (i.e., update /etc, make accounts,
|
|
|
|
|
# and so on).
|
|
|
|
|
echo "activating the configuration..."
|
|
|
|
|
@out@/activate @out@
|
|
|
|
|
|
|
|
|
|
# Make Upstart reload its jobs.
|
|
|
|
|
initctl reload-configuration
|
|
|
|
|
|
|
|
|
|
# Allow Upstart jobs to react intelligently to a config change.
|
|
|
|
|
initctl emit config-changed
|
|
|
|
|
|
|
|
|
|
# Restart all running jobs that have changed. (Here "running" means
|
|
|
|
|
# all jobs that don't have a "stop" goal.) We use the symlinks in
|
|
|
|
|
# /var/run/upstart-jobs (created by each job's pre-start script) to
|
|
|
|
|
# determine if a job has changed.
|
|
|
|
|
for job in $(cd $newJobs && ls *.conf); do
|
|
|
|
|
job=$(basename $job .conf)
|
|
|
|
|
status=$(status "$job")
|
|
|
|
|
if ! [[ "$status" =~ start/ ]]; then continue; fi
|
|
|
|
|
if [ "$(readlink -f "$newJobs/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ]; then continue; fi
|
2012-03-18 02:10:39 +00:00
|
|
|
|
if ! grep -q "^# RESTART-IF-CHANGED" "$newJobs/$job.conf"; then
|
2012-03-18 01:53:35 +00:00
|
|
|
|
echo "not restarting changed service ‘$job’"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
echo "restarting changed service ‘$job’..."
|
|
|
|
|
# Note: can't use "restart" here, since that only restarts the
|
|
|
|
|
# job's main process.
|
|
|
|
|
stop "$job" || true
|
|
|
|
|
start "$job" || true
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Start all jobs that are not running but should be. The "should be"
|
|
|
|
|
# criterion is tricky: the intended semantics is that we end up with
|
|
|
|
|
# the same jobs as after a reboot. If it's a task, restart it if it
|
|
|
|
|
# differs from the previous instance of the same task; if it wasn't
|
|
|
|
|
# previously run, don't run it. If it's a service, only start it if
|
|
|
|
|
# it has a "start on" condition.
|
|
|
|
|
for job in $(cd $newJobs && ls *.conf); do
|
|
|
|
|
job=$(basename $job .conf)
|
|
|
|
|
status=$(status "$job")
|
|
|
|
|
if ! [[ "$status" =~ stop/ ]]; then continue; fi
|
|
|
|
|
|
|
|
|
|
if grep -q '^task$' "$newJobs/$job.conf"; then
|
|
|
|
|
if [ ! -e "/var/run/upstart-jobs/$job" -o \
|
|
|
|
|
"$(readlink -f "$newJobs/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ];
|
|
|
|
|
then continue; fi
|
|
|
|
|
echo "starting task ‘$job’..."
|
|
|
|
|
start "$job" || true
|
|
|
|
|
else
|
|
|
|
|
if ! grep -q "^start on" "$newJobs/$job.conf"; then continue; fi
|
|
|
|
|
echo "starting service ‘$job’..."
|
|
|
|
|
start "$job" || true
|
|
|
|
|
fi
|
2010-07-23 10:52:51 +00:00
|
|
|
|
|
2012-03-18 01:53:35 +00:00
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# 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"
|