diff --git a/PKGBUILD b/PKGBUILD index 4473125..810e2fc 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -2,7 +2,7 @@ # Author: Evgeniy "arcanis" Alexeev pkgname=queued -pkgver=1.1.0 +pkgver=1.2.0 pkgrel=1 pkgdesc="Daemon for starting jobs to queue of calculations" arch=('any') @@ -10,7 +10,7 @@ url="https://github.com/arcan1s/queued" license=("GPLv3") depends=('bash') source=(https://github.com/arcan1s/queued/releases/download/V.${pkgver}/${pkgname}-${pkgver}-src.tar.xz) -md5sums=('0832ae610567e0aed4dccea02408e5a3') +md5sums=('a5e1af503128283cda85ca21d08b6853') backup=('etc/queued.conf') package() diff --git a/create_archive.sh b/create_archive.sh index 26b0524..0e5d768 100755 --- a/create_archive.sh +++ b/create_archive.sh @@ -8,6 +8,7 @@ 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/ diff --git a/install.sh b/install.sh index 39cfebc..dff3e1b 100755 --- a/install.sh +++ b/install.sh @@ -11,11 +11,13 @@ 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 diff --git a/queued-1.1.0-src.tar.xz b/queued-1.1.0-src.tar.xz deleted file mode 100644 index 1a91479..0000000 Binary files a/queued-1.1.0-src.tar.xz and /dev/null differ diff --git a/queued-1.2.0-src.tar.xz b/queued-1.2.0-src.tar.xz new file mode 100644 index 0000000..5c77398 Binary files /dev/null and b/queued-1.2.0-src.tar.xz differ diff --git a/sources/add_queued b/sources/add_queued new file mode 100755 index 0000000..6de3d6d --- /dev/null +++ b/sources/add_queued @@ -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 diff --git a/sources/add_queued.1 b/sources/add_queued.1 new file mode 100644 index 0000000..b144e59 --- /dev/null +++ b/sources/add_queued.1 @@ -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> diff --git a/sources/queued b/sources/queued index b42f533..4ef0a45 100755 --- a/sources/queued +++ b/sources/queued @@ -22,9 +22,9 @@ error_mes() { case "$1" in "config" ) echo "[EE] Configuration file is not set";; - "file" ) echo "[EE]: '$2' is a file";; + "file" ) echo "[EE] '$2' is a file";; "flag" ) echo "[EE] Unknown flag";; - "number" ) echo "[EE]: '$2' is not a number";; + "number" ) echo "[EE] '$2' is not a number";; "unknown" ) echo "[EE] Unknown error";; esac exit 1 @@ -41,7 +41,7 @@ func_help() { func_ver() { echo -e " queued " echo -e "Simple daemon for starting jobs to queue of calculations" - echo -e "Version : 1.1.0 License : GPLv3" + echo -e "Version : 1.2.0 License : GPLv3" echo -e "Author : Evgeniy Alexeev aka arcanis" echo -e "E-mail : esalexeev (at) gmail.com" exit 0 @@ -74,6 +74,7 @@ SLEEPTIME=5 STARTASUSER="root" WORKDIR="/var/lib/queued/work" echo "[II] Reading configuration from '$CONF_FILE'" +[ -e "$CONF_FILE" ] || error_mes "config" for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done @@ -81,19 +82,19 @@ for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done # creating directories if doesn't exist if [ ! -d "$JOBDIR/done" ]; then [ -e "$JOBDIR/done" ] && error_mes "file" "$JOBDIR/done" - echo "[II]: Create directory '$JOBDIR/done'" + echo "[II] Creating directory '$JOBDIR/done'" mkdir -m777 -p "$JOBDIR/done" || error_mes "unknown" fi if [ ! -d "$WORKDIR" ]; then [ -e "$WORKDIR" ] && error_mes "file" "$WORKDIR" - echo "[II]: Create directory '$WORKDIR'" + echo "[II] Creating directory '$WORKDIR'" mkdir -m777 -p "$WORKDIR" || error_mes "unknown" fi if [ ! -d "$(dirname "$QUEUEFILE")" ]; then [ -e "$(dirname "$QUEUEFILE")" ] && error_mes "file" "$(dirname "$QUEUEFILE")" - echo "[II]: Create directory '$(dirname "$QUEUEFILE")'" + echo "[II] Creating directory '$(dirname "$QUEUEFILE")'" mkdir -m777 -p "$(dirname "$QUEUEFILE")" || error_mes "unknown" - echo "[II]: Create file '$QUEUEFILE'" + echo "[II] Creating file '$QUEUEFILE'" touch "$QUEUEFILE" || error_mes "unknown" chmod 777 "$QUEUEFILE" fi @@ -112,7 +113,7 @@ cd / ( while true; do # check files - echo "[II] Check new files" + echo "[II] Checking new files" for FILE in $(ls "$WORKDIR/"); do [ -d "$WORKDIR/$FILE" ] && continue FILE_EXT="${FILE##*.}" diff --git a/sources/queued.1 b/sources/queued.1 index 0bcb468..3bf10f1 100644 --- a/sources/queued.1 +++ b/sources/queued.1 @@ -1,4 +1,4 @@ -.TH queued 1 "December 24, 2013" "version 1.1.0" "USER COMMANDS" +.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 @@ -10,7 +10,8 @@ is a simple daemon written on BASH for starting jobs to queue of calculations in .SH OPTIONS .TP -c /etc/queued.conf -Full path to configuration file. Default is '/etc/queued.conf'. +Full path to configuration file. Default is +.B /etc/queued.conf. .TP -h, --help Show help and exit. @@ -71,6 +72,7 @@ to determine errors: [EE] - error .fi .SH SEE ALSO +.BR add_queued (1) .BR queued.conf (5) .SH AUTHOR Evgeniy Alexeev aka arcanis <\fIesalexeev@gmail.com\fR>