* Use Upstart 0.6. Jobs are now in /etc/init instead of /etc/event.d.

svn path=/nixos/branches/upstart-0.6/; revision=18192
This commit is contained in:
Eelco Dolstra 2009-11-06 10:43:38 +00:00
parent b581a56d79
commit 7011a9315f
5 changed files with 39 additions and 62 deletions

View File

@ -55,7 +55,7 @@ with pkgs.lib;
# Generate a separate job for each tty. # Generate a separate job for each tty.
jobs = listToAttrs (map (tty: nameValuePair tty { jobs = listToAttrs (map (tty: nameValuePair tty {
startOn = "udev"; startOn = "started udev";
exec = "${pkgs.mingetty}/sbin/mingetty --loginprog=${pkgs.pam_login}/bin/login --noclear ${tty}"; exec = "${pkgs.mingetty}/sbin/mingetty --loginprog=${pkgs.pam_login}/bin/login --noclear ${tty}";

View File

@ -106,9 +106,11 @@ if test -n "$safeMode"; then
fi fi
# Create the minimal device nodes needed before we run udev. # Create the minimal device nodes needed for the activation scripts
# and Upstart.
mknod -m 0666 /dev/null c 1 3 mknod -m 0666 /dev/null c 1 3
mknod -m 0644 /dev/urandom c 1 9 # needed for passwd mknod -m 0644 /dev/urandom c 1 9 # needed for passwd
mknod -m 0644 /dev/console c 5 1
# Clear the resume device. # Clear the resume device.
@ -136,12 +138,12 @@ export MODULE_DIR=@kernel@/lib/modules/
# Run any user-specified commands. # Run any user-specified commands.
@shell@ @postBootCommands@ @shell@ @postBootCommands@
echo "starting Upstart..." # For debugging Upstart.
#@shell@ --login < /dev/console > /dev/console 2>&1 &
# Start Upstart's init. We start it through the # Start Upstart's init. We start it through the
# /var/run/current-system symlink indirection so that we can upgrade # /var/run/current-system symlink indirection so that we can upgrade
# init in a running system by changing the symlink and sending init a # init in a running system by changing the symlink and sending init a
# HUP signal. # HUP signal.
export UPSTART_CFG_DIR=/etc/event.d echo "starting Upstart..."
setPath "@upstartPath@" exec /var/run/current-system/upstart/sbin/init -v
exec /var/run/current-system/upstart/sbin/init

View File

@ -18,26 +18,16 @@ let
inherit (pkgs) substituteAll writeText coreutils utillinux udev; inherit (pkgs) substituteAll writeText coreutils utillinux udev;
kernel = config.boot.kernelPackages.kernel; kernel = config.boot.kernelPackages.kernel;
activateConfiguration = config.system.activationScripts.script; activateConfiguration = config.system.activationScripts.script;
upstart = config.system.build.upstart;
# Path for Upstart jobs. Should be quite minimal.
upstartPath =
[ pkgs.coreutils
pkgs.findutils
pkgs.gnugrep
pkgs.gnused
upstart
];
bootStage2 = substituteAll { bootStage2 = substituteAll {
src = ./stage-2-init.sh; src = ./stage-2-init.sh;
isExecutable = true; isExecutable = true;
inherit kernel upstart activateConfiguration upstartPath; inherit kernel activateConfiguration;
upstart = config.system.build.upstart;
path = path =
[ coreutils [ coreutils
utillinux utillinux
udev udev
upstart
]; ];
postBootCommands = writeText "local-cmds" config.boot.postBootCommands; postBootCommands = writeText "local-cmds" config.boot.postBootCommands;
}; };

View File

@ -4,9 +4,19 @@ with pkgs.lib;
let let
upstart = pkgs.upstart; upstart = pkgs.upstart06;
# Path for Upstart jobs. Should be quite minimal.
upstartPath =
[ pkgs.coreutils
pkgs.findutils
pkgs.gnugrep
pkgs.gnused
upstart
];
# From a job description, generate an Upstart job file. # From a job description, generate an Upstart job file.
makeJob = job: makeJob = job:
@ -18,6 +28,8 @@ let
description "${job.description}" description "${job.description}"
console output
${if isList job.startOn then ${if isList job.startOn then
# This is a hack to support or-dependencies on Upstart 0.3. # This is a hack to support or-dependencies on Upstart 0.3.
concatMapStrings (x: "start on ${x}\n") job.startOn concatMapStrings (x: "start on ${x}\n") job.startOn
@ -28,10 +40,11 @@ let
${if job.stopOn != "" then "stop on ${job.stopOn}" else ""} ${if job.stopOn != "" then "stop on ${job.stopOn}" else ""}
env PATH=${makeSearchPath "bin" upstartPath}:${makeSearchPath "sbin" upstartPath}
${concatMapStrings (n: "env ${n}=${getAttr n job.environment}\n") (attrNames job.environment)} ${concatMapStrings (n: "env ${n}=${getAttr n job.environment}\n") (attrNames job.environment)}
${if job.preStart != "" then '' ${if job.preStart != "" then ''
start script pre-start script
${job.preStart} ${job.preStart}
end script end script
'' else ""} '' else ""}
@ -48,18 +61,13 @@ let
'' ''
exec ${job.exec} exec ${job.exec}
'' ''
else else ""
# Simulate jobs without a main process (which Upstart 0.3
# doesn't support) using a semi-infinite sleep.
''
exec sleep 1e100
''
} }
${if job.respawn && !job.task then "respawn" else ""} ${if job.respawn && !job.task then "respawn" else ""}
${if job.postStop != "" then '' ${if job.postStop != "" then ''
stop script post-stop script
${job.postStop} ${job.postStop}
end script end script
'' else ""} '' else ""}
@ -68,37 +76,14 @@ let
''; '';
in in
pkgs.runCommand ("upstart-" + job.name) pkgs.runCommand ("upstart-" + job.name + ".conf")
{ inherit (job) buildHook; inherit jobText; } { inherit (job) buildHook; inherit jobText; }
'' ''
eval "$buildHook" eval "$buildHook"
ensureDir $out/etc/event.d echo "$jobText" > $out
echo "$jobText" > $out/etc/event.d/${job.name}
''; '';
jobs =
[ upstart ] # for the built-in logd job
++ map (job: job.upstartPkg) (attrValues config.jobs);
# Create an etc/event.d directory containing symlinks to the
# specified list of Upstart job files.
jobsDir = pkgs.runCommand "upstart-jobs" {inherit jobs;}
''
ensureDir $out/etc/event.d
for i in $jobs; do
if ln -s $i . ; then
if test -d $i; then
ln -s $i/etc/event.d/* $out/etc/event.d/
fi
else
echo Duplicate entry: $i;
fi;
done
''; # */
jobOptions = { jobOptions = {
name = mkOption { name = mkOption {
@ -227,13 +212,12 @@ let
upstartJob = {name, config, ...}: { upstartJob = {name, config, ...}: {
options = { options = {
upstartPkg = mkOption { jobDrv = mkOption {
default = makeJob config; default = makeJob config;
type = types.uniq types.package; type = types.uniq types.package;
description = '' description = ''
Upstart package which contains upstart events inside Derivation that builds the Upstart job file. The default
<filename>/etc/event.d/</filename>. The default value is value is generated from other options.
generated from other options.
''; '';
}; };
}; };
@ -284,18 +268,19 @@ in
system.build.upstart = upstart; system.build.upstart = upstart;
environment.etc = environment.etc =
[ { # The Upstart events defined above. flip map (attrValues config.jobs) (job:
source = "${jobsDir}/etc/event.d"; { source = job.jobDrv;
target = "event.d"; target = "init/${job.name}.conf";
} } );
];
# !!! fix this # !!! fix this
/*
tests.upstartJobs = { recurseForDerivations = true; } // tests.upstartJobs = { recurseForDerivations = true; } //
builtins.listToAttrs (map (job: { builtins.listToAttrs (map (job: {
name = removePrefix "upstart-" job.name; name = removePrefix "upstart-" job.name;
value = job; value = job;
}) jobs); }) jobs);
*/
}; };

View File

@ -105,7 +105,7 @@ in
jobs.ttyBackgrounds = jobs.ttyBackgrounds =
{ name = "tty-backgrounds"; { name = "tty-backgrounds";
startOn = "udev"; startOn = "started udev";
preStart = preStart =
'' ''