mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
Prerelease 1.0.0
This commit is contained in:
parent
8bede51e7d
commit
8d20e06d09
3
AUTHORS
Normal file
3
AUTHORS
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Current developers:
|
||||||
|
|
||||||
|
Evgeniy Alekseev aka arcanis <esalexeev (at) gmail (dot) com>
|
@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
|
|||||||
state the exclusion of warranty; and each file should have at least
|
state the exclusion of warranty; and each file should have at least
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
{one line to give the program's name and a brief idea of what it does.}
|
queued
|
||||||
Copyright (C) {year} {name of author}
|
Copyright (C) 2013 Evgeniy Alekseev
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
{project} Copyright (C) {year} {fullname}
|
queued Copyright (C) 2013 Evgeniy Alekseev
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
183
sources/queued
Executable file
183
sources/queued
Executable file
@ -0,0 +1,183 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
func_help() {
|
||||||
|
echo -e "Simple daemon written on BASH for starting jobs to queue of calculations"
|
||||||
|
echo -e "\nUsage: queued [ -jd | --jobdir /var/lib/queued/job ] [ --priority 0 ]"
|
||||||
|
echo -e " [ -q | --queuefile /var/lib/queued/queue ] [ -u | --user root ]"
|
||||||
|
echo -e " [ -wd | --workdir /var/lib/queued/work ] [ -v | --version ]"
|
||||||
|
echo -e " [ -h | --help ]"
|
||||||
|
echo -e "\nParametrs:"
|
||||||
|
echo -e " -jd --jobdir PATH - path to job directory. Default is '/var/lib/queued/job'"
|
||||||
|
echo -e " --priority NUM - defalut priority. Default is '0'"
|
||||||
|
echo -e " -q --queuefile PATH - path to queue file. Default is '/var/lib/queued/queue'"
|
||||||
|
echo -e " -u --user USERNAME - start jobs by user. Default is 'root'"
|
||||||
|
echo -e " -wd --workdir PATH - path to work directory. Default is '/var/lib/queued/work'"
|
||||||
|
echo -e "\n -v --version - show version and exit"
|
||||||
|
echo -e " -h --help - show this help and exit"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func_ver() {
|
||||||
|
echo -e " queued "
|
||||||
|
echo -e "Simple daemon for starting jobs to queue of calculations"
|
||||||
|
echo -e "Version : 1.0.0 License : GPLv3"
|
||||||
|
echo -e "Author : Evgeniy Alexeev aka arcanis"
|
||||||
|
echo -e "E-mail : esalexeev (at) gmail.com"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
isnum () {
|
||||||
|
(t=$(( 0$1+0 ))) 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# default values
|
||||||
|
JOBDIR="/var/lib/queued/job"
|
||||||
|
PRIORITY=0
|
||||||
|
QUEUEFILE="/var/lib/queued/queue"
|
||||||
|
STARTASUSER="root"
|
||||||
|
WORKDIR="/var/lib/queued/work"
|
||||||
|
# parametrs parsing
|
||||||
|
until [ -z $1 ]; do
|
||||||
|
if [ "$1" = "-h" ]; then
|
||||||
|
func_help; fi
|
||||||
|
if [ "$1" = "--help" ]; then
|
||||||
|
func_help; fi
|
||||||
|
if [ "$1" = "-v" ]; then
|
||||||
|
func_ver; fi
|
||||||
|
if [ "$1" = "--version" ]; then
|
||||||
|
func_ver; fi
|
||||||
|
if [ "$1" = "-jd" ]; then
|
||||||
|
JOBDIR="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "--jobdir" ]; then
|
||||||
|
JOBDIR="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "--priority" ]; then
|
||||||
|
PRIORITY="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "-q" ]; then
|
||||||
|
QUEUEFILE="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "--queuefile" ]; then
|
||||||
|
QUEUEFILE="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "-u" ]; then
|
||||||
|
STARTASUSER="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "--user" ]; then
|
||||||
|
STARTASUSER="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "-wd" ]; then
|
||||||
|
WORKDIR="$2"
|
||||||
|
shift; fi
|
||||||
|
if [ "$1" = "--workdir" ]; then
|
||||||
|
WORKDIR="$2"
|
||||||
|
shift; fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# creating directories if doesn't exist
|
||||||
|
if [ ! -d "$JOBDIR" ]; then
|
||||||
|
if [ -e "$JOBDIR" ]; then
|
||||||
|
echo "[EE]: '$JOBDIR' is a file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[II]: Create directory '$JOBDIR'"
|
||||||
|
mkdir -m777 -p "$JOBDIR" || (echo "[EE] Unknown error"; exit 1)
|
||||||
|
fi
|
||||||
|
if [ ! -d "$WORKDIR" ]; then
|
||||||
|
if [ -e "$WORKDIR" ]; then
|
||||||
|
echo "[EE]: '$WORKDIR' is a file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[II]: Create directory '$WORKDIR'"
|
||||||
|
mkdir -m777 -p "$WORKDIR" || (echo "[EE] Unknown error"; exit 1)
|
||||||
|
fi
|
||||||
|
if [ ! -d "$(dirname "$QUEUEFILE")" ]; then
|
||||||
|
if [ -e "$(dirname "$QUEUEFILE")" ]; then
|
||||||
|
echo "[EE]: '$(dirname "$QUEUEFILE")' is a file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "[II]: Create directory '$(dirname "$QUEUEFILE")'"
|
||||||
|
mkdir -m777 -p "$(dirname "$QUEUEFILE")" || (echo "[EE] Unknown error"; exit 1)
|
||||||
|
fi
|
||||||
|
# check priority
|
||||||
|
isnum "$PRIORITY" || (echo "[EE]: '$PRIORITY' isn't a number"; exit 1)
|
||||||
|
|
||||||
|
|
||||||
|
# work block
|
||||||
|
# change cwd
|
||||||
|
cd /
|
||||||
|
# output to /dev/null
|
||||||
|
< /dev/null > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
# forking
|
||||||
|
(
|
||||||
|
while true; do
|
||||||
|
# check files
|
||||||
|
echo "[II] Check new files"
|
||||||
|
for FILE in $(ls "$WORKDIR/"); do
|
||||||
|
[ -d "$WORKDIR/$FILE" ] && continue
|
||||||
|
FILE_EXT="${FILE##*.}"
|
||||||
|
[ "$FILE_EXT" = "pr" ] && continue
|
||||||
|
[ -e "$QUEUEFILE" ] && grep --quiet "$WORKDIR/$FILE" "$QUEUEFILE" && continue
|
||||||
|
echo "[II] Adding file '$FILE' to list"
|
||||||
|
if [ -e "$WORKDIR/$FILE".pr ]; then
|
||||||
|
CURJOB_PRIOR=$(cat "$WORKDIR/$FILE".pr)
|
||||||
|
isnum "$CURJOB_PRIOR" || CURJOB_PRIOR="$PRIORITY"
|
||||||
|
else
|
||||||
|
CURJOB_PRIOR="$PRIORITY"
|
||||||
|
fi
|
||||||
|
echo "[II] Setting priority to '$CURJOB_PRIOR'"
|
||||||
|
if [ ! -e "$QUEUEFILE" ]; then
|
||||||
|
echo "$CURJOB_PRIOR==$WORKDIR/$FILE" > "$QUEUEFILE"
|
||||||
|
chmod 777 "$QUEUEFILE"
|
||||||
|
else
|
||||||
|
if [[ $(cat "$QUEUEFILE") = "" ]]; then
|
||||||
|
echo "$CURJOB_PRIOR==$WORKDIR/$FILE" >> "$QUEUEFILE"
|
||||||
|
else
|
||||||
|
LASTLINE=""
|
||||||
|
for JOB in $(cat "$QUEUEFILE"); do
|
||||||
|
JOB_PRIOR=$(echo "$JOB" | awk -F "==" '{print $1}')
|
||||||
|
if [[ $JOB_PRIOR < $CURJOB_PRIOR ]]; then
|
||||||
|
LASTLINE="$JOB"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ -z "$LASTLINE" ]; then
|
||||||
|
sed -i '1i '"$CURJOB_PRIOR==$WORKDIR/$FILE" "$QUEUEFILE"
|
||||||
|
else
|
||||||
|
sed -i '/'$LASTLINE'/a '"$CURJOB_PRIOR==$WORKDIR/$FILE" "$QUEUEFILE"
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
|
grep --quiet "$WORKDIR/$FILE" "$QUEUEFILE" || echo "$CURJOB_PRIOR==$WORKDIR/$FILE" >> "$QUEUEFILE"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# check running job
|
||||||
|
CALC=0
|
||||||
|
for FILE in $(ls "$JOBDIR/"); do
|
||||||
|
[ -d "$JOBDIR/$FILE" ] && continue
|
||||||
|
pgrep "$JOBDIR/$FILE" &> /dev/null && CALC=$(($CALC+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
# running job
|
||||||
|
if [ "$CALC" = "0" ]; then
|
||||||
|
(
|
||||||
|
CURJOB=$(tail -1 "$QUEUEFILE" | awk -F "==" '{print $2}')
|
||||||
|
[ -z "$CURJOB" ] && break
|
||||||
|
sed -i '$d' "$QUEUEFILE"
|
||||||
|
[ -e "$CURJOB".pr ] && mv "$CURJOB".pr "$JOBDIR/$(basename "$CURJOB")".pr
|
||||||
|
mv "$CURJOB" "$JOBDIR/$(basename "$CURJOB")" 2> /dev/null || break
|
||||||
|
echo "[II] Running job '$CURJOB'"
|
||||||
|
su -c "/bin/sh "$JOBDIR/$(basename "$CURJOB")"" $STARTASUSER &> "$JOBDIR/$(basename "$CURJOB")".log &
|
||||||
|
)
|
||||||
|
else
|
||||||
|
echo "[II] You have a running job"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# wait for 60 seconds
|
||||||
|
sleep 60
|
||||||
|
done
|
||||||
|
) &
|
14
sources/queued.conf
Normal file
14
sources/queued.conf
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
## Configuration file for queued
|
||||||
|
## Paths
|
||||||
|
# path to directory with source jobs
|
||||||
|
WORKDIR=/home/arcanis/qdwork
|
||||||
|
# path to directory with running jobs
|
||||||
|
JOBDIR=/home/arcanis/qdjob
|
||||||
|
# path to file with queue list
|
||||||
|
QUEUEFILE=/home/arcanis/qdlist
|
||||||
|
|
||||||
|
## Additional parametrs
|
||||||
|
# default priority
|
||||||
|
PRIORITY=0
|
||||||
|
# start as user
|
||||||
|
STARTASUSER=arcanis
|
11
sources/queued.service
Normal file
11
sources/queued.service
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Queue daemon
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
EnvironmentFile=/etc/queued.conf
|
||||||
|
Type=forking
|
||||||
|
ExecStart=/usr/bin/queued -jd $JOBDIR --priority $PRIORITY -q $QUEUEFILE -u $STARTASUSER -wd $WORKDIR
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user