nix-processmgmt/tools/common/nixproc-build.in

171 lines
4.7 KiB
Bash

#!/bin/bash -e
# Shows the usage of this command to the user
showUsage()
{
cat <<EOF
Usage: $0 [OPTION] [PATH]
or: $0 --undeploy [OPTION]
This command builds a Nix profile containing multiple sysvinit scripts, and
their start and stop symlinks.
Options:
--undeploy Generates a configuration to undeploy all processes
-P, --process-manager=MANAGER
Process manager to build for
--state-dir Changes the directory in which the state of the processes
are stored
--runtime-dir Changes the directory in which the PID files are stored
--log-dir Changes the directory in which the log files are stored
--tmp-dir Changes the directory in which temp files are stored
--cache-dir Changes the directory in which cache files are stored
--force-disable-user-change
Forces to not create users, groups or change user
permissions
--no-out-link Do not create a symlink to the output path
--show-trace Shows a trace of the output
--extra-params=PARAMS
A string with an attribute set in the Nix expression
language propagating extra parameters to the input models
-h, --help Shows the usage of this command
Environment:
NIXPROC_PROCESSES Path to a processes model
NIXPROC_STATE_DIR Changes the directory in which the state of the
processes is stored
NIXPROC_RUNTIME_DIR Changes the directory in which the PID files are stored
NIXPROC_LOG_DIR Changes the directory in which log files are stored
NIXPROC_TMP_DIR Changes the directory in which temp files are stored
NIXPROC_CACHE_DIR Changes the directory in which cache files are stored
NIXPROC_FORCE_DISABLE_USER_CHANGE
Forces to not create users, groups or change user
permissions
EOF
}
# Parse valid argument options
PARAMS=`@getopt@ -n $0 -o P:h -l undeploy,process-manager:,state-dir:,runtime-dir:,log-dir:,tmp-dir:,cache-dir:,force-disable-user-change,no-out-link,show-trace,extra-params:,help -- "$@"`
if [ $? != 0 ]
then
showUsage
exit 1
fi
# Evaluate valid options
eval set -- "$PARAMS"
while [ "$1" != "--" ]
do
case "$1" in
--undeploy)
undeploy=1
;;
-P|--process-manager)
processManager="$2"
;;
--state-dir)
stateDirArg="--argstr stateDir $2"
;;
--runtime-dir)
runtimeDirArg="--argstr runtimeDir $2"
;;
--log-dir)
logDir="--argstr logDir $2"
;;
--tmp-dir)
tmpDir="--argstr tmpDir $2"
;;
--cache-dir)
cacheDir="--argstr cacheDir $2"
;;
--force-disable-user-change)
forceDisableUserChangeArg="--arg forceDisableUserChange true"
;;
--no-out-link)
noOutLinkArg="--no-out-link"
;;
--show-trace)
showTraceArg="--show-trace"
;;
--extra-params)
extraParamsArg=("--arg" "extraParams" "$2")
;;
-h|--help)
showUsage
exit 0
;;
esac
shift
done
shift
# Validate the given options
if [ "$processManager" = "" ]
then
echo "No process manager specified!" >&2
exit 1
else
processManagerArg="--argstr processManager $processManager"
fi
if [ "$undeploy" = "1" ]
then
exprFileArg="--arg exprFile null"
else
if [ "$1" != "" ]
then
exprFile="$(@readlink@ -f "$1")"
elif [ "$NIXPROC_PROCESSES" != "" ]
then
exprFile="$(@readlink@ -f "$NIXPROC_PROCESSES")"
else
echo "No processes expression provided!" >&2
exit 1
fi
exprFileArg="--argstr exprFile $exprFile"
fi
if [ "$NIXPROC_STATE_DIR" != "" ]
then
stateDirArg="--argstr stateDir $NIXPROC_STATE_DIR"
fi
if [ "$NIXPROC_RUNTIME_DIR" != "" ]
then
runtimeDirArg="--argstr stateDir $NIXPROC_RUNTIME_DIR"
fi
if [ "$NIXPROC_LOG_DIR" != "" ]
then
logDirArg="--argstr logDir $NIXPROC_LOG_DIR"
fi
if [ "$NIXPROC_TMP_DIR" != "" ]
then
tmpDirArg="--argstr tmpDir $NIXPROC_TMP_DIR"
fi
if [ "$NIXPROC_CACHE_DIR" != "" ]
then
cacheDirArg="--argstr cacheDir $NIXPROC_CACHE_DIR"
fi
if [ "$NIXPROC_FORCE_DISABLE_USER_CHANGE" = "1" ]
then
forceDisableUserChangeArg="--arg forceDisableUserChange true"
fi
NIXPROC=${NIXPROC:-@NIXPROC@}
# Build the profile
nix-build $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $cacheDirArg $forceDisableUserChangeArg $noOutLinkArg $showTraceArg $processManagerArg "${extraParamsArg[@]}" $exprFileArg $NIXPROC/backends/$processManager/build-$processManager-env.nix