mirror of
https://github.com/arcan1s/queued.git
synced 2025-12-16 04:03:45 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f465170fe | |||
| 051e6df16b | |||
| 74a95a57e5 | |||
| 345dfd574f | |||
| 9141a1fc12 | |||
| 4a002e0d8b | |||
| f11944394f | |||
| d0672e76ce | |||
| c50b0a1bcd |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
qdtest/*
|
||||||
21
PKGBUILD
21
PKGBUILD
@ -1,26 +1,19 @@
|
|||||||
# Author: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
|
|
||||||
# Maintainer: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
|
# Maintainer: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
|
||||||
|
# Author: Evgeniy "arcanis" Alexeev <esalexeev@gmail.com>
|
||||||
|
|
||||||
pkgname=queued
|
pkgname=queued
|
||||||
pkgver=1.0.0
|
pkgver=1.2.0
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Daemon for starting jobs to queue of calculations"
|
pkgdesc="Daemon for starting jobs to queue of calculations"
|
||||||
arch=('any')
|
arch=('any')
|
||||||
url="https://github.com/arcan1s/queued"
|
url="https://github.com/arcan1s/queued"
|
||||||
license=("GPL")
|
license=("GPLv3")
|
||||||
makedeps=('git')
|
depends=('bash')
|
||||||
source=(https://github.com/arcan1s/queued/releases/download/V.${pkgver}/${pkgname}-${pkgver}.tar.xz)
|
source=(https://github.com/arcan1s/queued/releases/download/V.${pkgver}/${pkgname}-${pkgver}-src.tar.xz)
|
||||||
md5sums=('d93c8cf20804b07b47645b0c43d45d3d')
|
md5sums=('94e7c73190939aaf6b63cb7bd2592a7c')
|
||||||
backup=('etc/queued.conf')
|
backup=('etc/queued.conf')
|
||||||
|
|
||||||
package()
|
package()
|
||||||
{
|
{
|
||||||
# daemon
|
"${srcdir}/${pkgname}/install.sh" "${pkgdir}"
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
|
|||||||
41
README.md
41
README.md
@ -5,18 +5,30 @@ Information
|
|||||||
-----------
|
-----------
|
||||||
Daemon for starting jobs to queue of calculations. To start deamon just run `systemctl start queued` as root.
|
Daemon for starting jobs to queue of calculations. To start deamon just run `systemctl start queued` as root.
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
GPLv3
|
||||||
|
|
||||||
help message
|
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:
|
||||||
|
|
||||||
Parametrs:
|
queued [ -c /etc/queued.conf ] [ -v | --version ] [ -h | --help ]
|
||||||
-jd --jobdir PATH - path to job directory. Default is '/var/lib/queued/job'
|
|
||||||
--priority NUM - defalut priority. Default is '0'
|
Parametrs:
|
||||||
-q --queuefile PATH - path to queue file. Default is '/var/lib/queued/queue'
|
-c PATH - path to configuration file. Default is `/etc/queued.conf`
|
||||||
-u --user USERNAME - start jobs by user. Default is 'root'
|
-v --version - show version and exit
|
||||||
-wd --workdir PATH - path to work directory. Default is '/var/lib/queued/work'
|
-h --help - show this help and exit
|
||||||
-v --version - show version and exit
|
|
||||||
-h --help - show this help and exit
|
* add_queued:
|
||||||
|
|
||||||
|
add_queued [ -c /etc/queued.conf ] [ -p NUM ] [ -u USER ] [ -h | --help ] /path/to/script
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
-c PATH - path to configuration file. Default is '/etc/queued.conf'
|
||||||
|
-p NUM - job priority
|
||||||
|
-u USER - username
|
||||||
|
-h --help - show this help and exit
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
@ -28,7 +40,13 @@ How-to run jobs
|
|||||||
* create priority file (`script.sh.pr`) with the job priority if it is needed
|
* create priority file (`script.sh.pr`) with the job priority if it is needed
|
||||||
* create user file (`script.sh.user`) with the job username if it is needed
|
* create user file (`script.sh.user`) with the job username if it is needed
|
||||||
* copy files to `$WORKDIR`
|
* copy files to `$WORKDIR`
|
||||||
|
Also you may use `add_queued`.
|
||||||
|
|
||||||
|
See also
|
||||||
|
--------
|
||||||
|
man 1 queued
|
||||||
|
man 1 add_queued
|
||||||
|
man 5 queued.conf
|
||||||
|
|
||||||
Instruction
|
Instruction
|
||||||
===========
|
===========
|
||||||
@ -41,6 +59,7 @@ Dependencies
|
|||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
* download sources
|
* download sources
|
||||||
* copy source to `/`:
|
* run `install.sh` from source directory:
|
||||||
|
|
||||||
sudo cp ../queued/* /
|
cd queued
|
||||||
|
sudo ./install.sh "/path/to/root"
|
||||||
|
|||||||
26
create_archive.sh
Executable file
26
create_archive.sh
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/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/add_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
|
||||||
23
install.sh
Executable file
23
install.sh
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/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 -m755 "usr/bin/add_queued" "$DESTDIR/usr/bin/add_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/man1/add_queued.1" "$DESTDIR/usr/share/man/man1/add_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.2.0-src.tar.xz
Normal file
BIN
queued-1.2.0-src.tar.xz
Normal file
Binary file not shown.
92
sources/add_queued
Executable file
92
sources/add_queued
Executable file
@ -0,0 +1,92 @@
|
|||||||
|
#!/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";;
|
||||||
|
"notfound" ) echo "[EE] File '$2' not found";;
|
||||||
|
"number" ) echo "[EE] '$2' is not a number";;
|
||||||
|
"priority" ) echo "[EE] Priority is not set";;
|
||||||
|
"unknown" ) echo "[EE] Unknown error";;
|
||||||
|
"user" ) echo "[EE] User is not set";;
|
||||||
|
esac
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
func_help() {
|
||||||
|
echo -e "Script to add job for queued"
|
||||||
|
echo -e "\nUsage: add_queued [ -c /etc/queued.conf ] [ -p NUM ] [ -u USER ] [ -h | --help ] /path/to/script"
|
||||||
|
echo -e "\nParameters:"
|
||||||
|
echo -e " -c PATH - path to configuration file. Default is '/etc/queued.conf'"
|
||||||
|
echo -e " -p NUM - job priority"
|
||||||
|
echo -e " -u USER - username"
|
||||||
|
echo -e " -h --help - show this help and exit"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
isnum() {
|
||||||
|
(t=$(( 0$1+0 ))) 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CONF_FILE="/etc/queued.conf"
|
||||||
|
# parametrs parsing
|
||||||
|
until [ -z $1 ]; do
|
||||||
|
case "$1" in
|
||||||
|
"-h" | "--help" ) func_help;;
|
||||||
|
"-c" ) [ -z "$2" ] && error_mes "config" || CONF_FILE="$2" && shift;;
|
||||||
|
"-p" ) [ -z "$2" ] && error_mes "priority" || JOB_PRIORITY="$2" && shift;;
|
||||||
|
"-u" ) [ -z "$2" ] && error_mes "user" || JOB_USER="$2" && shift;;
|
||||||
|
* ) JOB_SCRIPT="$1";;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
# default values
|
||||||
|
WORKDIR="/var/lib/queued/work"
|
||||||
|
echo "[II] Reading configuration from '$CONF_FILE'"
|
||||||
|
[ -e "$CONF_FILE" ] || error_mes "notfound" "$CONF_FILE"
|
||||||
|
for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done
|
||||||
|
|
||||||
|
# error check
|
||||||
|
if [ ! -d "$WORKDIR" ]; then
|
||||||
|
[ -e "$WORKDIR" ] && error_mes "file" "$WORKDIR"
|
||||||
|
echo "[II] Creating directory '$WORKDIR'"
|
||||||
|
mkdir -m777 -p "$WORKDIR" || error_mes "unknown"
|
||||||
|
fi
|
||||||
|
if [ ! -z "$JOB_PRIORITY" ]; then
|
||||||
|
isnum "$JOB_PRIORITY" || error_mes "number" "$JOB_PRIORITY"
|
||||||
|
fi
|
||||||
|
[ -z "$JOB_SCRIPT" ] && error_mes "notfound" "$JOB_SCRIPT"
|
||||||
|
[ -e "$JOB_SCRIPT" ] || error_mes "notfound" "$JOB_SCRIPT"
|
||||||
|
|
||||||
|
|
||||||
|
# work block
|
||||||
|
if [ -e "$WORKDIR/$(basename "$JOB_SCRIPT")" ]; then
|
||||||
|
echo "[WW] File '$WORKDIR/$(basename "$JOB_SCRIPT")' already exists. Creating backup"
|
||||||
|
mv "$WORKDIR/$(basename "$JOB_SCRIPT")" "$WORKDIR/$(basename "$JOB_SCRIPT")-$(date +%Y%m%d-%N)" || error_mes "unknown"
|
||||||
|
fi
|
||||||
|
echo "[II] Copying '$JOB_SCRIPT' to '$WORKDIR'"
|
||||||
|
cp --archive "$JOB_SCRIPT" "$WORKDIR" || error_mes "unknown"
|
||||||
|
if [ ! -z "$JOB_PRIORITY" ]; then
|
||||||
|
echo "$JOB_PRIORITY" > "$WORKDIR/$(basename "$JOB_SCRIPT").pr" || error_mes "unknown"
|
||||||
|
fi
|
||||||
|
if [ ! -z "$JOB_USER" ]; then
|
||||||
|
echo "$JOB_USER" > "$WORKDIR/$(basename "$JOB_SCRIPT").user" || error_mes "unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
32
sources/add_queued.1
Normal file
32
sources/add_queued.1
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
.TH add_queued 1 "December 24, 2013" "version 1.2.0" "USER COMMANDS"
|
||||||
|
.SH NAME
|
||||||
|
add_queued
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B add_queued
|
||||||
|
[ -c /etc/queued.conf ] [ -p NUM ] [ -u USER ] [ -h | --help ] /path/to/script
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.B add_queued
|
||||||
|
is a script to add job for
|
||||||
|
.BR queued (1)
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
/path/to/script
|
||||||
|
Path to the job script
|
||||||
|
.TP
|
||||||
|
-c /etc/queued.conf
|
||||||
|
Full path to configuration file. Default is
|
||||||
|
.B /etc/queued.conf.
|
||||||
|
.TP
|
||||||
|
-p NUM
|
||||||
|
priority of the job
|
||||||
|
.TP
|
||||||
|
-u USER
|
||||||
|
username for the job running
|
||||||
|
.TP
|
||||||
|
-h, --help
|
||||||
|
Show help and exit.
|
||||||
|
.SH SEE ALSO
|
||||||
|
.BR queued (1)
|
||||||
|
.BR queued.conf (5)
|
||||||
|
.SH AUTHOR
|
||||||
|
Evgeniy Alexeev aka arcanis <\fIesalexeev@gmail.com\fR>
|
||||||
203
sources/queued
203
sources/queued
@ -1,121 +1,119 @@
|
|||||||
#!/bin/bash
|
#!/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() {
|
func_help() {
|
||||||
echo -e "Simple daemon written on BASH for starting jobs to queue of calculations"
|
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 "\nUsage: queued [ -c /etc/queued.conf ] [ -v | --version ] [ -h | --help ]"
|
||||||
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 "\nParametrs:"
|
||||||
echo -e " -jd --jobdir PATH - path to job directory. Default is '/var/lib/queued/job'"
|
echo -e " -c PATH - path to configuration file. Default is '/etc/queued.conf'"
|
||||||
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 "\n -v --version - show version and exit"
|
||||||
echo -e " -h --help - show this help and exit"
|
echo -e " -h --help - show this help and exit"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func_ver() {
|
func_ver() {
|
||||||
echo -e " queued "
|
echo -e " queued "
|
||||||
echo -e "Simple daemon for starting jobs to queue of calculations"
|
echo -e "Simple daemon for starting jobs to queue of calculations"
|
||||||
echo -e "Version : 1.0.0 License : GPLv3"
|
echo -e "Version : 1.2.0 License : GPLv3"
|
||||||
echo -e "Author : Evgeniy Alexeev aka arcanis"
|
echo -e "Author : Evgeniy Alexeev aka arcanis"
|
||||||
echo -e "E-mail : esalexeev (at) gmail.com"
|
echo -e "E-mail : esalexeev (at) gmail.com"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
isnum() {
|
||||||
isnum () {
|
|
||||||
(t=$(( 0$1+0 ))) 2>/dev/null
|
(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
|
# default values
|
||||||
JOBDIR="/var/lib/queued/job"
|
JOBDIR="/var/lib/queued/job"
|
||||||
PRIORITY=0
|
PRIORITY=0
|
||||||
QUEUEFILE="/var/lib/queued/queue"
|
QUEUEFILE="/var/lib/queued/queue"
|
||||||
|
SLEEPTIME=5
|
||||||
STARTASUSER="root"
|
STARTASUSER="root"
|
||||||
WORKDIR="/var/lib/queued/work"
|
WORKDIR="/var/lib/queued/work"
|
||||||
# parametrs parsing
|
echo "[II] Reading configuration from '$CONF_FILE'"
|
||||||
until [ -z $1 ]; do
|
[ -e "$CONF_FILE" ] || error_mes "config"
|
||||||
if [ "$1" = "-h" ]; then
|
for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
# prepare
|
||||||
# creating directories if doesn't exist
|
# creating directories if doesn't exist
|
||||||
if [ ! -d "$JOBDIR" ]; then
|
if [ ! -d "$JOBDIR/done" ]; then
|
||||||
if [ -e "$JOBDIR" ]; then
|
[ -e "$JOBDIR/done" ] && error_mes "file" "$JOBDIR/done"
|
||||||
echo "[EE]: '$JOBDIR' is a file"
|
echo "[II] Creating directory '$JOBDIR/done'"
|
||||||
exit 1
|
mkdir -m777 -p "$JOBDIR/done" || error_mes "unknown"
|
||||||
fi
|
|
||||||
echo "[II]: Create directory '$JOBDIR'"
|
|
||||||
mkdir -m777 -p "$JOBDIR" || (echo "[EE] Unknown error"; exit 1)
|
|
||||||
fi
|
fi
|
||||||
if [ ! -d "$WORKDIR" ]; then
|
if [ ! -d "$WORKDIR" ]; then
|
||||||
if [ -e "$WORKDIR" ]; then
|
[ -e "$WORKDIR" ] && error_mes "file" "$WORKDIR"
|
||||||
echo "[EE]: '$WORKDIR' is a file"
|
echo "[II] Creating directory '$WORKDIR'"
|
||||||
exit 1
|
mkdir -m777 -p "$WORKDIR" || error_mes "unknown"
|
||||||
fi
|
|
||||||
echo "[II]: Create directory '$WORKDIR'"
|
|
||||||
mkdir -m777 -p "$WORKDIR" || (echo "[EE] Unknown error"; exit 1)
|
|
||||||
fi
|
fi
|
||||||
if [ ! -d "$(dirname "$QUEUEFILE")" ]; then
|
if [ ! -d "$(dirname "$QUEUEFILE")" ]; then
|
||||||
if [ -e "$(dirname "$QUEUEFILE")" ]; then
|
[ -e "$(dirname "$QUEUEFILE")" ] && error_mes "file" "$(dirname "$QUEUEFILE")"
|
||||||
echo "[EE]: '$(dirname "$QUEUEFILE")' is a file"
|
echo "[II] Creating directory '$(dirname "$QUEUEFILE")'"
|
||||||
exit 1
|
mkdir -m777 -p "$(dirname "$QUEUEFILE")" || error_mes "unknown"
|
||||||
fi
|
echo "[II] Creating file '$QUEUEFILE'"
|
||||||
echo "[II]: Create directory '$(dirname "$QUEUEFILE")'"
|
touch "$QUEUEFILE" || error_mes "unknown"
|
||||||
mkdir -m777 -p "$(dirname "$QUEUEFILE")" || (echo "[EE] Unknown error"; exit 1)
|
chmod 777 "$QUEUEFILE"
|
||||||
fi
|
fi
|
||||||
# check priority
|
# 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
|
# work block
|
||||||
# change cwd
|
# change cwd
|
||||||
cd /
|
cd /
|
||||||
# output to /dev/null
|
|
||||||
< /dev/null > /dev/null 2>&1 &
|
< /dev/null > /dev/null 2>&1 &
|
||||||
|
|
||||||
# forking
|
# forking
|
||||||
(
|
(
|
||||||
while true; do
|
while true; do
|
||||||
# check files
|
# check files
|
||||||
echo "[II] Check new files"
|
echo "[II] Checking new files"
|
||||||
for FILE in $(ls "$WORKDIR/"); do
|
for FILE in $(ls "$WORKDIR/"); do
|
||||||
[ -d "$WORKDIR/$FILE" ] && continue
|
[ -d "$WORKDIR/$FILE" ] && continue
|
||||||
FILE_EXT="${FILE##*.}"
|
FILE_EXT="${FILE##*.}"
|
||||||
@ -130,55 +128,38 @@ cd /
|
|||||||
CURJOB_PRIOR="$PRIORITY"
|
CURJOB_PRIOR="$PRIORITY"
|
||||||
fi
|
fi
|
||||||
echo "[II] Setting priority to '$CURJOB_PRIOR'"
|
echo "[II] Setting priority to '$CURJOB_PRIOR'"
|
||||||
if [ ! -e "$QUEUEFILE" ]; then
|
echo "$CURJOB_PRIOR==$WORKDIR/$FILE" >> "$QUEUEFILE"
|
||||||
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
|
done
|
||||||
|
|
||||||
# check running job
|
# check running job
|
||||||
CALC=0
|
CALC=0
|
||||||
for FILE in $(ls "$JOBDIR/"); do
|
for FILE in $(ls "$JOBDIR/"); do
|
||||||
[ -d "$JOBDIR/$FILE" ] && continue
|
[ -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
|
done
|
||||||
|
|
||||||
# running job
|
# running job
|
||||||
if [ "$CALC" = "0" ]; then
|
if [[ "$CALC" = "0" ]]; then
|
||||||
(
|
CURJOB_PRIOR=$(head -1 "$QUEUEFILE" | awk -F "==" '{print $1}')
|
||||||
CURJOB=$(tail -1 "$QUEUEFILE" | awk -F "==" '{print $2}')
|
CURJOB=$(head -1 "$QUEUEFILE" | awk -F "==" '{print $2}')
|
||||||
[ -z "$CURJOB" ] && break
|
for JOB in $(cat "$QUEUEFILE"); do
|
||||||
sed -i '$d' "$QUEUEFILE"
|
if [[ "$(echo "$JOB" | awk -F "==" '{print $1}')" > "$CURJOB_PRIOR" ]]; then
|
||||||
[ -e "$CURJOB".user ] && CUR_USER="$(cat "$CURJOB".user)" || CUR_USER="$STARTASUSER"
|
CURJOB_PRIOR=$(echo "$JOB" | awk -F "==" '{print $1}')
|
||||||
mv "$CURJOB"* "$JOBDIR/" 2> /dev/null || break
|
CURJOB=$(echo "$JOB" | awk -F "==" '{print $2}')
|
||||||
echo "[II] Running job '$CURJOB'"
|
fi
|
||||||
su -c "/bin/sh "$JOBDIR/$(basename "$CURJOB")" &> "$JOBDIR/$(basename "$CURJOB")".log" $CUR_USER &
|
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
|
else
|
||||||
echo "[II] You have a running job"
|
echo "[II] You have a running job"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wait for 60 seconds
|
# wait
|
||||||
sleep 60
|
sleep $SLEEPTIME
|
||||||
done
|
done
|
||||||
) &
|
) &
|
||||||
|
|||||||
79
sources/queued.1
Normal file
79
sources/queued.1
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
.TH queued 1 "December 24, 2013" "version 1.2.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. To add a new job you may use
|
||||||
|
.BR add_queued (1).
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
-c /etc/queued.conf
|
||||||
|
Full path to configuration file. Default is
|
||||||
|
.B /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 add_queued (1)
|
||||||
|
.BR queued.conf (5)
|
||||||
|
.SH AUTHOR
|
||||||
|
Evgeniy Alexeev aka arcanis <\fIesalexeev@gmail.com\fR>
|
||||||
@ -1,14 +1,16 @@
|
|||||||
## Configuration file for queued
|
## Configuration file for queued
|
||||||
## Paths
|
## Paths
|
||||||
# path to directory with source jobs
|
# path to directory with source jobs
|
||||||
WORKDIR=/home/arcanis/qdwork
|
#WORKDIR=/var/lib/queued/work
|
||||||
# path to directory with running jobs
|
# path to directory with running jobs
|
||||||
JOBDIR=/home/arcanis/qdjob
|
#JOBDIR=/var/lib/queued/job
|
||||||
# path to file with queue list
|
# path to file with queue list
|
||||||
QUEUEFILE=/home/arcanis/qdlist
|
#QUEUEFILE=/var/lib/queued/queue
|
||||||
|
|
||||||
## Additional parametrs
|
## Additional parametrs
|
||||||
# default priority
|
# default priority
|
||||||
PRIORITY=0
|
#PRIORITY=0
|
||||||
|
# time to sleep, minutes
|
||||||
|
#SLEEPTIME=5
|
||||||
# start as user
|
# start as user
|
||||||
STARTASUSER=arcanis
|
#STARTASUSER=root
|
||||||
|
|||||||
44
sources/queued.conf.5
Normal file
44
sources/queued.conf.5
Normal 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)
|
||||||
@ -2,9 +2,8 @@
|
|||||||
Description=Queue daemon
|
Description=Queue daemon
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
EnvironmentFile=/etc/queued.conf
|
|
||||||
Type=forking
|
Type=forking
|
||||||
ExecStart=/usr/bin/queued -jd $JOBDIR --priority $PRIORITY -q $QUEUEFILE -u $STARTASUSER -wd $WORKDIR
|
ExecStart=/usr/bin/queued
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
Reference in New Issue
Block a user