* Get rid of some grep hackery on the Upstart jobs.
svn path=/nixos/trunk/; revision=33240
This commit is contained in:
parent
9ba5f09e44
commit
8ca2aff772
@ -76,13 +76,13 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
newJobs=$(readlink -f @out@/etc/init)
|
jobsDir=$(readlink -f @out@/etc/init)
|
||||||
|
|
||||||
# Stop all currently running jobs that are not in the new Upstart
|
# Stop all currently running jobs that are not in the new Upstart
|
||||||
# configuration. (Here "running" means all jobs that are not in the
|
# configuration. (Here "running" means all jobs that are not in the
|
||||||
# stop/waiting state.)
|
# stop/waiting state.)
|
||||||
for job in $(initctl list | sed -e '/ stop\/waiting/ d; /^[^a-z]/ d; s/^\([^ ]\+\).*/\1/' | sort); do
|
for job in $(initctl list | sed -e '/ stop\/waiting/ d; /^[^a-z]/ d; s/^\([^ ]\+\).*/\1/' | sort); do
|
||||||
if ! [ -e "$newJobs/$job.conf" ] ; then
|
if ! [ -e "$jobsDir/$job.conf" ] ; then
|
||||||
echo "stopping obsolete job ‘$job’..."
|
echo "stopping obsolete job ‘$job’..."
|
||||||
stop --quiet "$job" || true
|
stop --quiet "$job" || true
|
||||||
fi
|
fi
|
||||||
@ -99,16 +99,19 @@ initctl reload-configuration
|
|||||||
# Allow Upstart jobs to react intelligently to a config change.
|
# Allow Upstart jobs to react intelligently to a config change.
|
||||||
initctl emit config-changed
|
initctl emit config-changed
|
||||||
|
|
||||||
|
declare -A tasks=(@tasks@)
|
||||||
|
declare -A noRestartIfChanged=(@noRestartIfChanged@)
|
||||||
|
|
||||||
# Restart all running jobs that have changed. (Here "running" means
|
# Restart all running jobs that have changed. (Here "running" means
|
||||||
# all jobs that don't have a "stop" goal.) We use the symlinks in
|
# 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
|
# /var/run/upstart-jobs (created by each job's pre-start script) to
|
||||||
# determine if a job has changed.
|
# determine if a job has changed.
|
||||||
for job in $(cd $newJobs && ls *.conf); do
|
for job in $(cd $jobsDir && ls *.conf); do
|
||||||
job=$(basename $job .conf)
|
job=$(basename $job .conf)
|
||||||
status=$(status "$job")
|
status=$(status "$job")
|
||||||
if ! [[ "$status" =~ start/ ]]; then continue; fi
|
if ! [[ "$status" =~ start/ ]]; then continue; fi
|
||||||
if [ "$(readlink -f "$newJobs/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ]; then continue; fi
|
if [ "$(readlink -f "$jobsDir/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ]; then continue; fi
|
||||||
if ! grep -q "^# RESTART-IF-CHANGED" "$newJobs/$job.conf"; then
|
if [ -n "${noRestartIfChanged[$job]}" ]; then
|
||||||
echo "not restarting changed service ‘$job’"
|
echo "not restarting changed service ‘$job’"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@ -125,20 +128,20 @@ done
|
|||||||
# differs from the previous instance of the same task; if it wasn't
|
# 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
|
# previously run, don't run it. If it's a service, only start it if
|
||||||
# it has a "start on" condition.
|
# it has a "start on" condition.
|
||||||
for job in $(cd $newJobs && ls *.conf); do
|
for job in $(cd $jobsDir && ls *.conf); do
|
||||||
job=$(basename $job .conf)
|
job=$(basename $job .conf)
|
||||||
status=$(status "$job")
|
status=$(status "$job")
|
||||||
if ! [[ "$status" =~ stop/ ]]; then continue; fi
|
if ! [[ "$status" =~ stop/ ]]; then continue; fi
|
||||||
|
|
||||||
if grep -q '^task$' "$newJobs/$job.conf"; then
|
if [ -n "${tasks[$job]}" ]; then
|
||||||
if [ ! -e "/var/run/upstart-jobs/$job" -o \
|
if [ ! -e "/var/run/upstart-jobs/$job" -o \
|
||||||
"$(readlink -f "$newJobs/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ];
|
"$(readlink -f "$jobsDir/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ];
|
||||||
then continue; fi
|
then continue; fi
|
||||||
if ! grep -q "^# RESTART-IF-CHANGED" "$newJobs/$job.conf"; then continue; fi
|
if [ -n "${noRestartIfChanged[$job]}" ]; then continue; fi
|
||||||
echo "starting task ‘$job’..."
|
echo "starting task ‘$job’..."
|
||||||
start --quiet "$job" || true
|
start --quiet "$job" || true
|
||||||
else
|
else
|
||||||
if ! grep -q "^start on" "$newJobs/$job.conf"; then continue; fi
|
if ! grep -q "^start on" "$jobsDir/$job.conf"; then continue; fi
|
||||||
echo "starting service ‘$job’..."
|
echo "starting service ‘$job’..."
|
||||||
start --quiet "$job" || true
|
start --quiet "$job" || true
|
||||||
fi
|
fi
|
||||||
|
@ -1,24 +1,26 @@
|
|||||||
{pkgs, config, modules, baseModules, ...}:
|
{ config, pkgs, modules, baseModules, ... }:
|
||||||
|
|
||||||
|
with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
system.build = pkgs.lib.mkOption {
|
system.build = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
description = ''
|
description = ''
|
||||||
Attribute set of derivations used to setup the system.
|
Attribute set of derivations used to setup the system.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
nesting.children = pkgs.lib.mkOption {
|
nesting.children = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
Additional configurations to build.
|
Additional configurations to build.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
nesting.clone = pkgs.lib.mkOption {
|
nesting.clone = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
Additional configurations to build based on the current
|
Additional configurations to build based on the current
|
||||||
@ -26,21 +28,21 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
system.boot.loader.id = pkgs.lib.mkOption {
|
system.boot.loader.id = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Id string of the used bootloader.
|
Id string of the used bootloader.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
system.boot.loader.kernelFile = pkgs.lib.mkOption {
|
system.boot.loader.kernelFile = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Name of the kernel file to be passed to the bootloader.
|
Name of the kernel file to be passed to the bootloader.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
system.copySystemConfiguration = pkgs.lib.mkOption {
|
system.copySystemConfiguration = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
If enabled, copies the NixOS configuration file
|
If enabled, copies the NixOS configuration file
|
||||||
@ -50,10 +52,10 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
system.extraSystemBuilderCmds = pkgs.lib.mkOption {
|
system.extraSystemBuilderCmds = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
internal = true;
|
internal = true;
|
||||||
merge = pkgs.lib.concatStringsSep "\n";
|
merge = concatStringsSep "\n";
|
||||||
description = ''
|
description = ''
|
||||||
This code will be added to the builder creating the system store path.
|
This code will be added to the builder creating the system store path.
|
||||||
'';
|
'';
|
||||||
@ -89,7 +91,7 @@ let
|
|||||||
kernelPath = "${config.boot.kernelPackages.kernel}/" +
|
kernelPath = "${config.boot.kernelPackages.kernel}/" +
|
||||||
"${config.system.boot.loader.kernelFile}";
|
"${config.system.boot.loader.kernelFile}";
|
||||||
in ''
|
in ''
|
||||||
ensureDir $out
|
mkdir $out
|
||||||
|
|
||||||
if [ ! -f ${kernelPath} ]; then
|
if [ ! -f ${kernelPath} ]; then
|
||||||
echo "The bootloader cannot find the proper kernel image."
|
echo "The bootloader cannot find the proper kernel image."
|
||||||
@ -123,13 +125,13 @@ let
|
|||||||
echo "${toString config.system.build.upstart.interfaceVersion}" > $out/upstart-interface-version
|
echo "${toString config.system.build.upstart.interfaceVersion}" > $out/upstart-interface-version
|
||||||
|
|
||||||
mkdir $out/fine-tune
|
mkdir $out/fine-tune
|
||||||
childCount=0;
|
childCount=0
|
||||||
for i in $children; do
|
for i in $children; do
|
||||||
childCount=$(( childCount + 1 ));
|
childCount=$(( childCount + 1 ))
|
||||||
ln -s $i $out/fine-tune/child-$childCount;
|
ln -s $i $out/fine-tune/child-$childCount
|
||||||
done
|
done
|
||||||
|
|
||||||
ensureDir $out/bin
|
mkdir $out/bin
|
||||||
substituteAll ${./switch-to-configuration.sh} $out/bin/switch-to-configuration
|
substituteAll ${./switch-to-configuration.sh} $out/bin/switch-to-configuration
|
||||||
chmod +x $out/bin/switch-to-configuration
|
chmod +x $out/bin/switch-to-configuration
|
||||||
|
|
||||||
@ -151,15 +153,23 @@ let
|
|||||||
menuBuilder = config.system.build.menuBuilder;
|
menuBuilder = config.system.build.menuBuilder;
|
||||||
initScriptBuilder = config.system.build.initScriptBuilder;
|
initScriptBuilder = config.system.build.initScriptBuilder;
|
||||||
activationScript = config.system.activationScripts.script;
|
activationScript = config.system.activationScripts.script;
|
||||||
|
|
||||||
|
# Pass the names of all Upstart tasks to the activation script.
|
||||||
|
tasks = attrValues (mapAttrs (n: v: if v.task then ["[${v.name}]=1"] else []) config.jobs);
|
||||||
|
|
||||||
|
# Pass the names of all Upstart jobs that shouldn't be restarted
|
||||||
|
# to the activation script.
|
||||||
|
noRestartIfChanged = attrValues (mapAttrs (n: v: if v.restartIfChanged then [] else ["[${v.name}]=1"]) config.jobs);
|
||||||
|
|
||||||
# Most of these are needed by grub-install.
|
# Most of these are needed by grub-install.
|
||||||
path = [
|
path =
|
||||||
pkgs.coreutils
|
[ pkgs.coreutils
|
||||||
pkgs.gnused
|
pkgs.gnused
|
||||||
pkgs.gnugrep
|
pkgs.gnugrep
|
||||||
pkgs.findutils
|
pkgs.findutils
|
||||||
pkgs.diffutils
|
pkgs.diffutils
|
||||||
config.system.build.upstart # for initctl
|
config.system.build.upstart # for initctl
|
||||||
];
|
];
|
||||||
|
|
||||||
# Boot loaders
|
# Boot loaders
|
||||||
bootLoader = config.system.boot.loader.id;
|
bootLoader = config.system.boot.loader.id;
|
||||||
@ -185,9 +195,9 @@ in {
|
|||||||
require = [options];
|
require = [options];
|
||||||
|
|
||||||
system.extraSystemBuilderCmds =
|
system.extraSystemBuilderCmds =
|
||||||
pkgs.lib.optionalString
|
optionalString
|
||||||
config.system.copySystemConfiguration
|
config.system.copySystemConfiguration
|
||||||
"cp ${pkgs.lib.maybeEnv "NIXOS_CONFIG" "/etc/nixos/configuration.nix"} $out";
|
"cp ${maybeEnv "NIXOS_CONFIG" "/etc/nixos/configuration.nix"} $out";
|
||||||
|
|
||||||
system.build.toplevel = system;
|
system.build.toplevel = system;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,6 @@ let
|
|||||||
${optionalString job.task "task"}
|
${optionalString job.task "task"}
|
||||||
${optionalString (!job.task && job.respawn) "respawn"}
|
${optionalString (!job.task && job.respawn) "respawn"}
|
||||||
|
|
||||||
${optionalString job.restartIfChanged "# RESTART-IF-CHANGED"}
|
|
||||||
|
|
||||||
${ # preStop is run only if there is exec or script.
|
${ # preStop is run only if there is exec or script.
|
||||||
# (upstart 0.6.5, job.c:562)
|
# (upstart 0.6.5, job.c:562)
|
||||||
optionalString (job.preStop != "") (assert hasMain; ''
|
optionalString (job.preStop != "") (assert hasMain; ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user