Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mxq/mxqdctl-hostconfig.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
160 lines (139 sloc)
4 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
hostconfig=/etc/hostconfig | |
shorthost=${HOSTNAME%.molgen.mpg.de} | |
declare -i started=0 | |
mxqd=mxqd | |
defaultargs=(--daemonize) | |
pidfilebase=/dev/shm/mxqdctl-hostconfig | |
shopt -s nullglob | |
function start_all_hostconfig() | |
{ | |
while read -a line ; do | |
host=${line[0]} | |
var=${line[1]} | |
unset 'line[0]' | |
unset 'line[1]' | |
if [ "${var}" != "mxqd" ] ; then | |
continue | |
fi | |
if [ "${host}" != "${shorthost}" ] ; then | |
continue | |
fi | |
args=(${defaultargs[@]} --pid-file "${pidfilebase}${started}.pid" ${line[@]}) | |
echo "executing ${mxqd} ${args[@]}" | |
${mxqd} ${args[@]} | |
started+=1 | |
done < ${hostconfig} | |
if [ ${started} -lt 1 ] ; then | |
echo >&2 "host '${shorthost}' is not configured for mxqd in '${hostconfig}'." | |
exit 1 | |
fi | |
} | |
function stop_all_started() | |
{ | |
for pidfile in ${pidfilebase}* ; do | |
ouid=$(stat --format "%u" "${pidfile}") | |
if [ "${UID}" != "${ouid}" ] ; then | |
continue | |
fi | |
pid=$(cat ${pidfile}) | |
echo "${pidfile}: killing ${pid}" | |
kill ${pid} | |
done | |
} | |
function quit_all_started() | |
{ | |
for pidfile in ${pidfilebase}* ; do | |
ouid=$(stat --format "%u" "${pidfile}") | |
if [ "${UID}" != "${ouid}" ] ; then | |
continue | |
fi | |
pid=$(cat ${pidfile}) | |
echo "${pidfile}: sending signal SIGQUIT to ${pid}" | |
kill -QUIT ${pid} | |
done | |
} | |
function reload_all_started() | |
{ | |
for pidfile in ${pidfilebase}* ; do | |
ouid=$(stat --format "%u" "${pidfile}") | |
if [ "${UID}" != "${ouid}" ] ; then | |
continue | |
fi | |
pid=$(cat ${pidfile}) | |
echo "${pidfile}: sending signal SIGUSR1 to restart pid ${pid}" | |
kill -USR1 ${pid} | |
done | |
} | |
function kill_all_started() | |
{ | |
for pidfile in ${pidfilebase}* ; do | |
ouid=$(stat --format "%u" "${pidfile}") | |
if [ "${UID}" != "${ouid}" ] ; then | |
continue | |
fi | |
pid=$(cat ${pidfile}) | |
echo "${pidfile}: sending signal SIGINT to kill pid ${pid} and all running jobs" | |
kill -INT ${pid} | |
done | |
} | |
case "${BASH_ARGV[0]}" in | |
start) | |
start_all_hostconfig | |
;; | |
stop) | |
stop_all_started | |
;; | |
kill) | |
kill_all_started | |
;; | |
quit) | |
quit_all_started | |
;; | |
reload|restart) | |
reload_all_started | |
;; | |
stopall) | |
env kill mxqd | |
;; | |
killall) | |
env kill -int mxqd | |
;; | |
quitall) | |
env kill -quit mxqd | |
;; | |
reloadall|restartall) | |
env kill -usr1 mxqd | |
;; | |
stateall) | |
env kill -usr2 -q 10 mxqd | |
;; | |
setinfoall|setnodebugall) | |
env kill -usr2 -q 20 mxqd | |
;; | |
setdebugall) | |
env kill -usr2 -q 21 mxqd | |
;; | |
*) | |
echo "usage $0 CMD" | |
echo "" | |
echo "to mxqd configured by hostconfig:" | |
echo "" | |
echo " start : start mxqd (if configured by hostconfig)" | |
echo " stop : tell mxqd to stop accepting new jobs, wait for running jobs, exit" | |
echo " kill : tell mxqd to stop accepting new jobs, kill and wait for running jobs, exit" | |
echo " quit : tell mxqd to exit (leave jobs running)" | |
echo " reload|restart : tell mxqd to re-exec itself, leave jobs running" | |
echo "" | |
echo "to all mxqd owned by calling user:" | |
echo "" | |
echo " stopall : tell mxqd to stop accepting new jobs, wait for running jobs, exit" | |
echo " killall : tell mxqd to stop accepting new jobs, kill and wait for running jobs, exit" | |
echo " quitall : tell mxqd to exit (leave jobs running)" | |
echo " reloadall|restartall : tell mxqd to re-exec itself, leave jobs running" | |
echo "" | |
echo " stateall : tell mxqd to dump state" | |
echo " setdebugall : tell to set loglevel to debug" | |
echo " setinfoall|setnodebugall : tell mxqd to set loglevel to info" | |
;; | |
esac |