#!/bin/sh
set -e

cat > /etc/slurm-llnl/slurm.conf <<EOF 
ControlMachine=localhost
AuthType=auth/munge
CacheGroups=0
CryptoType=crypto/munge
JobCheckpointDir=/var/lib/slurm-llnl/checkpoint
MpiDefault=none
ProctrackType=proctrack/pgid
ReturnToService=1
SlurmctldPidFile=/run/slurmctld.pid
SlurmctldPort=6817
SlurmdPidFile=/run/slurmd.pid
SlurmdPort=6818
SlurmdSpoolDir=/var/lib/slurm-llnl/slurmd
SlurmUser=slurm
StateSaveLocation=/var/lib/slurm-llnl/slurmctld
SwitchType=switch/none
TaskPlugin=task/none
InactiveLimit=0
KillWait=30
MinJobAge=300
SlurmctldTimeout=300
SlurmdTimeout=300
Waittime=0
FastSchedule=1
SchedulerType=sched/backfill
SchedulerPort=7321
SelectType=select/linear
AccountingStorageType=accounting_storage/none
ClusterName=cluster
JobCompType=jobcomp/none
JobAcctGatherFrequency=30
JobAcctGatherType=jobacct_gather/none
SlurmctldDebug=3
SlurmctldLogFile=/var/log/slurm-llnl/slurmctld.log
SlurmdDebug=3
SlurmdLogFile=/var/log/slurm-llnl/slurmd.log
NodeName=localhost Procs=1 State=UNKNOWN
PartitionName=test Nodes=localhost Default=YES MaxTime=INFINITE State=UP
EOF

service slurmctld restart
service slurmd restart

sinfo

sinfo --Node

rm -f /tmp/job.touch

cat > /tmp/job.sh <<EOF
#!/bin/sh
/usr/bin/touch /tmp/job.touch
EOF

sbatch /tmp/job.sh

# Testing if the job is still in the queue every second, at most 5 times
retry=5
while [ "$retry" -gt 0 ] && [ -n "$(squeue --noheader)" ] ; do
	retry=$(($retry-1))
	sleep 1
done

# This test fails if the job didn't run
test -f /tmp/job.touch
