Skip to content

Commit

Permalink
systemd manager: fixed oarsh_shell
Browse files Browse the repository at this point in the history
  • Loading branch information
bzizou committed Apr 15, 2024
1 parent 09e7be5 commit 5b159e2
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions oar/tools/oarsh/oarsh_shell.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ umask 0022
if [ -f /etc/oar/use_systemd ]
then
SYSTEMD=1
# For systemd exec, we need to pass the variables as an rcfile
RCFILE="$JOBENVFILE.rc"
echo "source $OARDIR/.batch_job_bashrc " > $RCFILE
[ -r "$JOBENVFILE" ] && echo "source $JOBENVFILE" >> $RCFILE
else
SYSTEMD=0
fi
Expand All @@ -36,14 +32,26 @@ fi
# $2,$3,... = PIDs to add
# Add PIDS into the cpuset $1
function add_process_to_cpuset() {
[ "$1" = "undef" ] && return
######################
# CPUSET assignation #
###########################################################################
if [ "$SYSTEMD" = "1" ]
then
echo "oarsh: Using systemd" 1>&2
SLICE=${1##*/}.slice
PROCS_FILE="/sys/fs/cgroup/systemd/$SLICE/cgroup.procs"
if [ ! -f $PROCS_FILE ]; then
echo "oarsh: Cannot find cpuset file : $PROCS_FILE" 1>&2
exit 61
fi
shift

# Add each processes to the right OAR cgroups
for p in $@; do
$OARDIR/oardodo/oardodo sh -c "echo $p > $PROCS_FILE" || return 1
done
else
[ "$1" = "undef" ] && return
######################
# CPUSET assignation #
###########################################################################
CPUSETNAME=$1
if [ ! -w /dev/cpuset/$CPUSETNAME/tasks ]; then
echo "oarsh: Cannot find cpuset file : /dev/cpuset/$CPUSETNAME/tasks" 1>&2
Expand All @@ -66,8 +74,8 @@ function add_process_to_cpuset() {
$OARDIR/oardodo/oardodo sh -c "echo $p > /dev/cpuset/$CPUSETNAME/tasks" || return 1
fi
done
###########################################################################
fi
###########################################################################
}

if [ "$OAR_JOB_USER" = "" ]
Expand All @@ -87,12 +95,7 @@ then
export SHELL=$DEFAULT_SHELL

umask $OLDUMASK
if [ "$SYSTEMD" = "1" ]
then
exec /usr/lib/oar/oardodo/oardodo systemd-run --uid=$OAR_JOB_USER --scope --slice $OAR_CPUSET --unit $OAR_CPUSET "$DEFAULT_SHELL --rcfile $RCFILE $@"
else
exec $DEFAULT_SHELL "$@"
fi
exec $DEFAULT_SHELL "$@"
echo "oarsh: exec failed" 1>&2
exit 66
else
Expand Down Expand Up @@ -121,26 +124,15 @@ else
# Simulate initial login
export OARDO_BECOME_USER=$OAR_JOB_USER
umask $OLDUMASK
if [ "$SYSTEMD" = "1" ]
then
exec $OARDIR/oardodo/oardodo systemd-run --uid=$OAR_JOB_USER -p Delegate=yes --scope --slice $OAR_CPUSET --unit $OAR_CPUSET $DEFAULT_SHELL --rcfile $RCFILE -c "bash -l"
else
exec $OARDIR/oardodo/oardodo
#exec oardodo su - $OAR_JOB_USER
fi
exec $OARDIR/oardodo/oardodo
#exec oardodo su - $OAR_JOB_USER
echo "oarsh: exec failed" 1>&2
exit 66
else
export OARDO_BECOME_USER=$OAR_JOB_USER
export OARDO_USE_USER_SHELL=1
umask $OLDUMASK
if [ "$SYSTEMD" = "1" ]
then
# TODO: adapt to the user's shell if not bash
exec $OARDIR/oardodo/oardodo systemd-run --uid=$OAR_JOB_USER -p Delegate=yes --scope --slice $OAR_CPUSET --unit $OAR_CPUSET $DEFAULT_SHELL --rcfile $RCFILE "$@"
else
exec $OARDIR/oardodo/oardodo "$@"
fi
exec $OARDIR/oardodo/oardodo "$@"
echo "oarsh: exec failed" 1>&2
exit 66
fi
Expand Down

0 comments on commit 5b159e2

Please sign in to comment.