* 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
|
||||
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
|
||||
# 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
|
||||
if ! [ -e "$jobsDir/$job.conf" ] ; then
|
||||
echo "stopping obsolete job ‘$job’..."
|
||||
stop --quiet "$job" || true
|
||||
fi
|
||||
@ -99,16 +99,19 @@ initctl reload-configuration
|
||||
# Allow Upstart jobs to react intelligently to a config change.
|
||||
initctl emit config-changed
|
||||
|
||||
declare -A tasks=(@tasks@)
|
||||
declare -A noRestartIfChanged=(@noRestartIfChanged@)
|
||||
|
||||
# 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
|
||||
for job in $(cd $jobsDir && 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
|
||||
if ! grep -q "^# RESTART-IF-CHANGED" "$newJobs/$job.conf"; then
|
||||
if [ "$(readlink -f "$jobsDir/$job.conf")" = "$(readlink -f "/var/run/upstart-jobs/$job")" ]; then continue; fi
|
||||
if [ -n "${noRestartIfChanged[$job]}" ]; then
|
||||
echo "not restarting changed service ‘$job’"
|
||||
continue
|
||||
fi
|
||||
@ -125,20 +128,20 @@ done
|
||||
# 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
|
||||
for job in $(cd $jobsDir && 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 [ -n "${tasks[$job]}" ]; then
|
||||
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
|
||||
if ! grep -q "^# RESTART-IF-CHANGED" "$newJobs/$job.conf"; then continue; fi
|
||||
if [ -n "${noRestartIfChanged[$job]}" ]; then continue; fi
|
||||
echo "starting task ‘$job’..."
|
||||
start --quiet "$job" || true
|
||||
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’..."
|
||||
start --quiet "$job" || true
|
||||
fi
|
||||
|
@ -1,24 +1,26 @@
|
||||
{pkgs, config, modules, baseModules, ...}:
|
||||
{ config, pkgs, modules, baseModules, ... }:
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
let
|
||||
|
||||
options = {
|
||||
|
||||
system.build = pkgs.lib.mkOption {
|
||||
system.build = mkOption {
|
||||
default = {};
|
||||
description = ''
|
||||
Attribute set of derivations used to setup the system.
|
||||
'';
|
||||
};
|
||||
|
||||
nesting.children = pkgs.lib.mkOption {
|
||||
nesting.children = mkOption {
|
||||
default = [];
|
||||
description = ''
|
||||
Additional configurations to build.
|
||||
'';
|
||||
};
|
||||
|
||||
nesting.clone = pkgs.lib.mkOption {
|
||||
nesting.clone = mkOption {
|
||||
default = [];
|
||||
description = ''
|
||||
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 = "";
|
||||
description = ''
|
||||
Id string of the used bootloader.
|
||||
'';
|
||||
};
|
||||
|
||||
system.boot.loader.kernelFile = pkgs.lib.mkOption {
|
||||
system.boot.loader.kernelFile = mkOption {
|
||||
default = "";
|
||||
description = ''
|
||||
Name of the kernel file to be passed to the bootloader.
|
||||
'';
|
||||
};
|
||||
|
||||
system.copySystemConfiguration = pkgs.lib.mkOption {
|
||||
system.copySystemConfiguration = mkOption {
|
||||
default = false;
|
||||
description = ''
|
||||
If enabled, copies the NixOS configuration file
|
||||
@ -50,10 +52,10 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
system.extraSystemBuilderCmds = pkgs.lib.mkOption {
|
||||
system.extraSystemBuilderCmds = mkOption {
|
||||
default = "";
|
||||
internal = true;
|
||||
merge = pkgs.lib.concatStringsSep "\n";
|
||||
merge = concatStringsSep "\n";
|
||||
description = ''
|
||||
This code will be added to the builder creating the system store path.
|
||||
'';
|
||||
@ -89,7 +91,7 @@ let
|
||||
kernelPath = "${config.boot.kernelPackages.kernel}/" +
|
||||
"${config.system.boot.loader.kernelFile}";
|
||||
in ''
|
||||
ensureDir $out
|
||||
mkdir $out
|
||||
|
||||
if [ ! -f ${kernelPath} ]; then
|
||||
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
|
||||
|
||||
mkdir $out/fine-tune
|
||||
childCount=0;
|
||||
childCount=0
|
||||
for i in $children; do
|
||||
childCount=$(( childCount + 1 ));
|
||||
ln -s $i $out/fine-tune/child-$childCount;
|
||||
childCount=$(( childCount + 1 ))
|
||||
ln -s $i $out/fine-tune/child-$childCount
|
||||
done
|
||||
|
||||
ensureDir $out/bin
|
||||
mkdir $out/bin
|
||||
substituteAll ${./switch-to-configuration.sh} $out/bin/switch-to-configuration
|
||||
chmod +x $out/bin/switch-to-configuration
|
||||
|
||||
@ -151,15 +153,23 @@ let
|
||||
menuBuilder = config.system.build.menuBuilder;
|
||||
initScriptBuilder = config.system.build.initScriptBuilder;
|
||||
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.
|
||||
path = [
|
||||
pkgs.coreutils
|
||||
pkgs.gnused
|
||||
pkgs.gnugrep
|
||||
pkgs.findutils
|
||||
pkgs.diffutils
|
||||
config.system.build.upstart # for initctl
|
||||
];
|
||||
path =
|
||||
[ pkgs.coreutils
|
||||
pkgs.gnused
|
||||
pkgs.gnugrep
|
||||
pkgs.findutils
|
||||
pkgs.diffutils
|
||||
config.system.build.upstart # for initctl
|
||||
];
|
||||
|
||||
# Boot loaders
|
||||
bootLoader = config.system.boot.loader.id;
|
||||
@ -185,9 +195,9 @@ in {
|
||||
require = [options];
|
||||
|
||||
system.extraSystemBuilderCmds =
|
||||
pkgs.lib.optionalString
|
||||
optionalString
|
||||
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;
|
||||
}
|
||||
|
@ -94,8 +94,6 @@ let
|
||||
${optionalString job.task "task"}
|
||||
${optionalString (!job.task && job.respawn) "respawn"}
|
||||
|
||||
${optionalString job.restartIfChanged "# RESTART-IF-CHANGED"}
|
||||
|
||||
${ # preStop is run only if there is exec or script.
|
||||
# (upstart 0.6.5, job.c:562)
|
||||
optionalString (job.preStop != "") (assert hasMain; ''
|
||||
|
Loading…
x
Reference in New Issue
Block a user