6 Commits

Author SHA1 Message Date
345dfd574f Added license to readme 2013-12-23 23:41:43 +04:00
9141a1fc12 Release 1.1.0
* edited install script
* edited README
+ added license
2013-12-23 23:39:07 +04:00
4a002e0d8b Added mans, edited readme 2013-12-23 23:09:51 +04:00
f11944394f Changes in daemon
* changes in cmd parametrs
* some refactoring
+ added sleeptime parametr
- bug with pgrep
2013-12-23 22:15:23 +04:00
d0672e76ce Added install scripts 2013-12-23 12:20:01 +04:00
c50b0a1bcd Prerelease 1.1.0
* fix bug with moving root (ooops)
* changes in work
2013-12-23 04:39:08 +04:00
12 changed files with 283 additions and 137 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
qdtest/*

View File

@ -1,26 +1,19 @@
# Author: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
# Maintainer: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
# Author: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
pkgname=queued
pkgver=1.0.0
pkgver=1.1.0
pkgrel=1
pkgdesc="Daemon for starting jobs to queue of calculations"
arch=('any')
url="https://github.com/arcan1s/queued"
license=("GPL")
makedeps=('git')
source=(https://github.com/arcan1s/queued/releases/download/V.${pkgver}/${pkgname}-${pkgver}.tar.xz)
md5sums=('d93c8cf20804b07b47645b0c43d45d3d')
license=("GPLv3")
depends=('bash')
source=(https://github.com/arcan1s/queued/releases/download/V.${pkgver}/${pkgname}-${pkgver}-src.tar.xz)
md5sums=('0832ae610567e0aed4dccea02408e5a3')
backup=('etc/queued.conf')
package()
{
# daemon
install -D -m755 "${srcdir}/${pkgname}/usr/bin/queued" "${pkgdir}/usr/bin/queued"
# service
install -D -m644 "${srcdir}/${pkgname}/usr/lib/systemd/system/queued.service" \
"${pkgdir}/usr/lib/systemd/system/queued.service"
install -D -m644 "${srcdir}/${pkgname}/etc/queued.conf" \
"${pkgdir}/etc/queued.conf"
"${srcdir}/${pkgname}/install.sh" "${pkgdir}"
}

View File

@ -5,16 +5,16 @@ Information
-----------
Daemon for starting jobs to queue of calculations. To start deamon just run `systemctl start queued` as root.
License
-------
GPLv3
help message
------------
queued [ -jd | --jobdir /var/lib/queued/job ] [ --priority 0 ] [ -q | --queuefile /var/lib/queued/queue ] [ -u | --user root ] [ -wd | --workdir /var/lib/queued/work ] [-v | --version ] [ -h | --help ]
queued [ -c /etc/queued.conf ] [ -v | --version ] [ -h | --help ]
Parametrs:
-jd --jobdir PATH - path to job directory. Default is '/var/lib/queued/job'
--priority NUM - defalut priority. Default is '0'
-q --queuefile PATH - path to queue file. Default is '/var/lib/queued/queue'
-u --user USERNAME - start jobs by user. Default is 'root'
-wd --workdir PATH - path to work directory. Default is '/var/lib/queued/work'
-c PATH - path to configuration file. Default is `/etc/queued.conf`
-v --version - show version and exit
-h --help - show this help and exit
@ -29,6 +29,10 @@ How-to run jobs
* create user file (`script.sh.user`) with the job username if it is needed
* copy files to `$WORKDIR`
See also
--------
man 1 queued
man 5 queued.conf
Instruction
===========
@ -41,6 +45,7 @@ Dependencies
Installation
------------
* download sources
* copy source to `/`:
* run `install.sh` from source directory:
sudo cp ../queued/* /
cd queued
sudo ./install.sh "/path/to/root"

25
create_archive.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
ARCHIVE="queued"
[ -d ${ARCHIVE} ] && rm -rf ${ARCHIVE}
mkdir -p ${ARCHIVE}/usr/{bin,lib/systemd/system}
mkdir -p ${ARCHIVE}/usr/share/man/{man1,man5}
mkdir -p ${ARCHIVE}/etc
cp sources/queued ${ARCHIVE}/usr/bin/
cp sources/queued.service ${ARCHIVE}/usr/lib/systemd/system/
cp sources/queued.conf ${ARCHIVE}/etc/
cp sources/*.1 ${ARCHIVE}/usr/share/man/man1/
cp sources/*.5 ${ARCHIVE}/usr/share/man/man5/
cp install.sh ${ARCHIVE}/
cp {AUTHORS,COPYING} ${ARCHIVE}/
VERSION=$(grep Version sources/queued | awk '{printf $5;}')
tar -cf - ${ARCHIVE} | xz -9 -c - > ${ARCHIVE}-${VERSION}-src.tar.xz
rm -r ${ARCHIVE}
# update PKGBUILD
MD5SUMS=$(md5sum ${ARCHIVE}-${VERSION}-src.tar.xz | awk '{print $1}')
sed -i "s/md5sums=('[0-9a-f]\{32\}')/md5sums=('${MD5SUMS}')/" PKGBUILD
sed -i "s/pkgver=[0-9.]\{5\}/pkgver=${VERSION}/" PKGBUILD

21
install.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
func_error() {
echo "Error installing"
exit 1
}
[ -z "$1" ] && DESTDIR="/" || DESTDIR="$1"
[ -d "$DESTDIR" ] || mkdir -p "$DESTDIR" || func_error
cd "$(dirname "${BASH_SOURCE[0]}")"
# daemon and configuration
install -D -m755 "usr/bin/queued" "$DESTDIR/usr/bin/queued" || func_error
install -D -m644 "etc/queued.conf" "$DESTDIR/etc/queued.conf" || func_error
# service
install -D -m644 "usr/lib/systemd/system/queued.service" "$DESTDIR/usr/lib/systemd/system/queued.service" || func_error
# man pages
install -D -m644 "usr/share/man/man1/queued.1" "$DESTDIR/usr/share/man/man1/queued.1" || func_error
install -D -m644 "usr/share/man/man5/queued.conf.5" "$DESTDIR/usr/share/man/man5/queued.conf.5" || func_error
exit 0

Binary file not shown.

BIN
queued-1.1.0-src.tar.xz Normal file

Binary file not shown.

View File

@ -1,114 +1,111 @@
#!/bin/bash
# queued is a simple daemon for starting jobs to queue of calculations
# Copyright (C) 2013 Evgeniy Alekseev
#
# 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
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see http://www.gnu.org/licenses
# or write to the Free Software Foundation,Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301 USA
# functions
error_mes() {
case "$1" in
"config" ) echo "[EE] Configuration file is not set";;
"file" ) echo "[EE]: '$2' is a file";;
"flag" ) echo "[EE] Unknown flag";;
"number" ) echo "[EE]: '$2' is not a number";;
"unknown" ) echo "[EE] Unknown error";;
esac
exit 1
}
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 "\nUsage: queued [ -c /etc/queued.conf ] [ -v | --version ] [ -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 " -c PATH - path to configuration file. Default is '/etc/queued.conf'"
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 "Version : 1.1.0 License : GPLv3"
echo -e "Author : Evgeniy Alexeev aka arcanis"
echo -e "E-mail : esalexeev (at) gmail.com"
exit 0
}
isnum () {
isnum() {
(t=$(( 0$1+0 ))) 2>/dev/null
}
start_job() {
echo "[II] Running job '$CURJOB' (priority '$CURJOB_PRIOR') as '$CURJOB_USER'"
su -c "/bin/sh "$JOBDIR/$(basename "$CURJOB")" &> "$JOBDIR/$(basename "$CURJOB")".log" $CURJOB_USER &
}
CONF_FILE="/etc/queued.conf"
# parametrs parsing
until [ -z $1 ]; do
case "$1" in
"-h" | "--help" ) func_help;;
"-v" | "--version" ) func_ver;;
"-c" ) [ -z "$2" ] && error_mes "config" || CONF_FILE="$2" && shift;;
* ) error_mes "flag";;
esac
shift
done
# default values
JOBDIR="/var/lib/queued/job"
PRIORITY=0
QUEUEFILE="/var/lib/queued/queue"
SLEEPTIME=5
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
echo "[II] Reading configuration from '$CONF_FILE'"
for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done
# prepare
# 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)
if [ ! -d "$JOBDIR/done" ]; then
[ -e "$JOBDIR/done" ] && error_mes "file" "$JOBDIR/done"
echo "[II]: Create directory '$JOBDIR/done'"
mkdir -m777 -p "$JOBDIR/done" || error_mes "unknown"
fi
if [ ! -d "$WORKDIR" ]; then
if [ -e "$WORKDIR" ]; then
echo "[EE]: '$WORKDIR' is a file"
exit 1
fi
[ -e "$WORKDIR" ] && error_mes "file" "$WORKDIR"
echo "[II]: Create directory '$WORKDIR'"
mkdir -m777 -p "$WORKDIR" || (echo "[EE] Unknown error"; exit 1)
mkdir -m777 -p "$WORKDIR" || error_mes "unknown"
fi
if [ ! -d "$(dirname "$QUEUEFILE")" ]; then
if [ -e "$(dirname "$QUEUEFILE")" ]; then
echo "[EE]: '$(dirname "$QUEUEFILE")' is a file"
exit 1
fi
[ -e "$(dirname "$QUEUEFILE")" ] && error_mes "file" "$(dirname "$QUEUEFILE")"
echo "[II]: Create directory '$(dirname "$QUEUEFILE")'"
mkdir -m777 -p "$(dirname "$QUEUEFILE")" || (echo "[EE] Unknown error"; exit 1)
mkdir -m777 -p "$(dirname "$QUEUEFILE")" || error_mes "unknown"
echo "[II]: Create file '$QUEUEFILE'"
touch "$QUEUEFILE" || error_mes "unknown"
chmod 777 "$QUEUEFILE"
fi
# check priority
isnum "$PRIORITY" || (echo "[EE]: '$PRIORITY' isn't a number"; exit 1)
isnum "$PRIORITY" || error_mes "number" "$PRIORITY"
# check sleep time
isnum "$SLEEPTIME" && SLEEPTIME=$(($SLEEPTIME*60)) || error_mes "number" "$SLEEPTIME"
# work block
# change cwd
cd /
# output to /dev/null
< /dev/null > /dev/null 2>&1 &
# forking
@ -130,55 +127,38 @@ cd /
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
echo "$CURJOB_PRIOR==$WORKDIR/$FILE" >> "$QUEUEFILE"
done
# check running job
CALC=0
for FILE in $(ls "$JOBDIR/"); do
[ -d "$JOBDIR/$FILE" ] && continue
pgrep "$JOBDIR/$FILE" &> /dev/null && CALC=$(($CALC+1))
(ps aux | grep "$JOBDIR/$FILE" | grep --quiet --invert-match "grep") && 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".user ] && CUR_USER="$(cat "$CURJOB".user)" || CUR_USER="$STARTASUSER"
mv "$CURJOB"* "$JOBDIR/" 2> /dev/null || break
echo "[II] Running job '$CURJOB'"
su -c "/bin/sh "$JOBDIR/$(basename "$CURJOB")" &> "$JOBDIR/$(basename "$CURJOB")".log" $CUR_USER &
)
if [[ "$CALC" = "0" ]]; then
CURJOB_PRIOR=$(head -1 "$QUEUEFILE" | awk -F "==" '{print $1}')
CURJOB=$(head -1 "$QUEUEFILE" | awk -F "==" '{print $2}')
for JOB in $(cat "$QUEUEFILE"); do
if [[ "$(echo "$JOB" | awk -F "==" '{print $1}')" > "$CURJOB_PRIOR" ]]; then
CURJOB_PRIOR=$(echo "$JOB" | awk -F "==" '{print $1}')
CURJOB=$(echo "$JOB" | awk -F "==" '{print $2}')
fi
done
[ -e "$CURJOB".user ] && CURJOB_USER="$(cat "$CURJOB".user)" || CURJOB_USER="$STARTASUSER"
sed '/'"$(basename "$CURJOB")"'/d' -i "$QUEUEFILE"
if [ -z "$CURJOB" ]; then
echo "[II] You haven't job"
else
mv "$CURJOB"* "$JOBDIR/" && start_job || echo "[WW] Missing files for job '$CURJOB'"
fi
else
echo "[II] You have a running job"
fi
# wait for 60 seconds
sleep 60
# wait
sleep $SLEEPTIME
done
) &

76
sources/queued.1 Normal file
View File

@ -0,0 +1,76 @@
.TH queued 1 "December 24, 2013" "version 1.1.0" "USER COMMANDS"
.SH NAME
queued - daemon for starting jobs to queue of calculations
.SH SYNOPSIS
.B queued
[ -c /etc/queued.conf ] [ -v | --version ] [ -h | --help ]
.SH DESCRIPTION
.B queued
is a simple daemon written on BASH for starting jobs to queue of calculations in the background.
.SH OPTIONS
.TP
-c /etc/queued.conf
Full path to configuration file. Default is '/etc/queued.conf'.
.TP
-h, --help
Show help and exit.
.TP
-v, --version
Show version and exit.
.SH FILES
.TP
/usr/lib/systemd/system/queued.service
Systemd service file.
.TP
/etc/queued.conf
Configuration file.
.SH EXAMPLES
.TP
# systemctl start queued.service
Start daemon with parameters that are described in configuration file.
.TP
# systemctl enable queued.service
Enable daemon autostart.
.SH USAGE WITH SYSTEMD
If you need change path to configuration file, copy standart service file to /etc directory:
.PP
.nf
# cp /usr/lib/systemd/system/queued.service /etc/systemd/system/queued-my-profile.service
.fi
.PP
Then replace path to configuration file to your option. For example,
.PP
.B from:
.nf
ExecStart=/usr/bin/queued
.fi
.B to
.nf
ExecStart=/usr/bin/queued -c /path/to/new/queued.conf
.fi
.PP
Copy configuration file and edit it:
.PP
.nf
# cp /etc/queued.conf /path/to/new/queued.conf
# $EDITOR /path/to/new/queued.conf
.fi
.PP
Then start service:
.PP
.nf
# systemctl start queued-my-profile.service
.fi
.SH ERRORS
Use
.B journalctl
to determine errors:
.nf
[II] - information string
[WW] - warning
[EE] - error
.fi
.SH SEE ALSO
.BR queued.conf (5)
.SH AUTHOR
Evgeniy Alexeev aka arcanis <\fIesalexeev@gmail.com\fR>

View File

@ -1,14 +1,16 @@
## Configuration file for queued
## Paths
# path to directory with source jobs
WORKDIR=/home/arcanis/qdwork
#WORKDIR=/var/lib/queued/work
# path to directory with running jobs
JOBDIR=/home/arcanis/qdjob
#JOBDIR=/var/lib/queued/job
# path to file with queue list
QUEUEFILE=/home/arcanis/qdlist
#QUEUEFILE=/var/lib/queued/queue
## Additional parametrs
# default priority
PRIORITY=0
#PRIORITY=0
# time to sleep, minutes
#SLEEPTIME=5
# start as user
STARTASUSER=arcanis
#STARTASUSER=root

44
sources/queued.conf.5 Normal file
View File

@ -0,0 +1,44 @@
.TH queued.conf 5
.SH NAME
queued.conf - queued configuration file
.SH SYNOPSIS
/etc/queued.conf
.SH DESCRIPTION
This file configures various parameters of
.BR queued (1).
.SH OPTIONS
.TP
.I WORKDIR=
Full path to directory with source jobs. Default is
.B /var/lib/queued/work.
This directory must contain source scripts
.B script-name
, a priority file (it is not necessary)
.B script-name.pr
and a file with username (it is not necessary too)
.B script-name.user.
.TP
.I JOBDIR=
Full path to directory with running jobs. Default is
.B /var/lib/queued/job.
All job files will be moved here.
.TP
.I QUEUEFILE=
Full path to file with queue list. Default is
.B /var/lib/queued/queue.
.TP
.I PRIORITY=
Default priority. Default is
.B 0.
The higher the value, the higher the priority of the task
.TP
.I SLEEPTIME=
Time interval in minutes. Default is
.B 5.
.TP
.I STARTASUSER=
Default user. Default is
.B root.
This user will own created files.
.SH SEE ALSO
.BR queued (1)

View File

@ -2,9 +2,8 @@
Description=Queue daemon
[Service]
EnvironmentFile=/etc/queued.conf
Type=forking
ExecStart=/usr/bin/queued -jd $JOBDIR --priority $PRIORITY -q $QUEUEFILE -u $STARTASUSER -wd $WORKDIR
ExecStart=/usr/bin/queued
RemainAfterExit=yes
[Install]