# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 ###################################################################### # Gestion des processus function wo_pidof() { # obtenir le(s) pid de l'instance $1 # attention! on doit avoir un ps non legacy (cf sysinc/system_caps) ps_all | grep "\-[W]OApplicationName $1 " | awk '{ print $1 }' # note: on met [W] entre crochet pour que le processus associé à grep ne # soit pas pris dans la liste # note: on met un espace après le nom de l'application pour ne matcher que # celle-là. } ###################################################################### # Services basés sur le parcours du fichier SiteConfig.xml AWK_FUNCTIONS=' function get_value(line) { match(line, /^[^<]*<[^<>]*>/); line = substr(line, RSTART + RLENGTH) match(line, /<.*$/); line = substr(line, 1, RSTART - 1) return line } function get_attr_value(attr, line) { match(line, attr "=\""); line = substr(line, RSTART + RLENGTH) match(line, /".*$/); line = substr(line, 1, RSTART - 1) return line } ' function siteconf_dump_hosts() { # Retourner la liste des hôtes configurés # Chaque ligne est de la forme: # host type [ -f "$WOCONFIGURATION/SiteConfig.xml" ] || return 1 awk <"$WOCONFIGURATION/SiteConfig.xml" "$AWK_FUNCTIONS"' BEGIN { in_hosts = 0 } !in_hosts && $0 ~ // { in_hosts = 0 } in_hosts && $0 ~ // { print name " " type } in_hosts && $0 ~ // { in_applications = 0 } in_applications && $0 ~ // { print name " " autoRecover " " debuggingEnabled " " path } in_applications && $0 ~ // { in_instances = 0 } in_instances && $0 ~ // { print applicationName " " id " " hostName " " port " " autoRecover " " debuggingEnabled " " path } in_instances && $0 ~ /([^<]*)<.*$", "\\1", 1) match($0, /^[^<]*<[^<>]*>/); $0 = substr($0, RSTART + RLENGTH) match($0, /<.*$/); $0 = substr($0, 1, RSTART - 1) print } ' } function siteconf_get_instance_data_for_updateWotaskd() { # obtenir les informations au format XML pour les instances données, à # utiliser avec # Les informations sont retournées pour chaque minstance, une par ligne. [ -f "$WOCONFIGURATION/SiteConfig.xml" ] || return 1 [ -n "$*" ] || return 1 script=' BEGIN { found_instances = 0 found_element = 0 } $0 ~ /([^<]*)<.*$", "\\1", 1) name = $0 match(name, /^[^<]*<[^<>]*>/); name = substr(name, RSTART + RLENGTH) match(name, /<.*$/); name = substr(name, 1, RSTART - 1) } found_element && $0 ~ /<\/element/ { if (' local instance notfirst= for instance in "$@"; do script="$script${notfirst:+|| }name == $(qawk "$instance")" notfirst=1 done script="$script"') { print data } found_element = 0 next } found_element { match($0, /^[\t]*/) $0 = substr($0, RSTART + RLENGTH) data = data $0 } found_instances && $0 ~ /<\/instanceArray/ { found_element = 0 found_instances = 0 } ' awk <"$WOCONFIGURATION/SiteConfig.xml" "$script" } function siteconf_get_instance_data_for_commandWotaskd() { # obtenir les informations au format XML pour les instances données, à # utiliser avec # Les informations sont retournées pour chaque minstance, une par ligne. [ -f "$WOCONFIGURATION/SiteConfig.xml" ] || return 1 script=' BEGIN { found_instances = 0 found_element = 0 } $0 ~ /([^<]*)<.*$", "\\1", 1) id = $0 match(id, /^[^<]*<[^<>]*>/); id = substr(id, RSTART + RLENGTH) match(id, /<.*$/); id = substr(id, 1, RSTART - 1) } found_element && $0 ~ /([^<]*)<.*$", "\\1", 1) port = $0 match(port, /^[^<]*<[^<>]*>/); port = substr(port, RSTART + RLENGTH) match(port, /<.*$/); port = substr(port, 1, RSTART - 1) } found_element && $0 ~ /([^<]*)<.*$", "\\1", 1) name = $0 match(name, /^[^<]*<[^<>]*>/); name = substr(name, RSTART + RLENGTH) match(name, /<.*$/); name = substr(name, 1, RSTART - 1) } found_element && $0 ~ /([^<]*)<.*$", "\\1", 1) hostName = $0 match(hostName, /^[^<]*<[^<>]*>/); hostName = substr(hostName, RSTART + RLENGTH) match(hostName, /<.*$/); hostName = substr(hostName, 1, RSTART - 1) } found_element && $0 ~ /<\/element/ { if (' local instance notfirst= for instance in "$@"; do script="$script${notfirst:+|| }name == $(qawk "$instance")" notfirst=1 done script="$script"') { print "" id "" port "" name "" hostName "" } found_element = 0 next } found_element { match($0, /^[\t]*/) $0 = substr($0, RSTART + RLENGTH) data = data $0 } found_instances && $0 ~ /<\/instanceArray/ { found_element = 0 found_instances = 0 } ' awk <"$WOCONFIGURATION/SiteConfig.xml" "$script" } function get_autostart() { # Afficher le chemin vers le fichier $WOCONFIGURATION/AutoStart.txt echo "$WOCONFIGURATION/AutoStart.txt" } function apply_autostart_order() { # Reordonner les instances du tableau $1 selon la liste données dans le # fichier $WOCONFIGURATION/AutoStart.txt local autostart_="$(get_autostart)" [ -r "$autostart_" ] || return local -a oinsts_ srcname_ dest_ local oinst_ array_from_lines oinsts_ "$(<"$autostart_" filter_conf)" srcname_="$1" for oinst_ in "${oinsts_[@]}"; do if array_contains "$srcname_" "$oinst_"; then array_add dest_ "$oinst_" array_del "$srcname_" "$oinst_" fi done array_extend dest_ "$srcname_" array_copy "$srcname_" dest_ } ###################################################################### # Services basés sur wotaskd, sans mot de passe function wotaskd_dump_woconfig() { # afficher la configuration de wotaskd sur l'hôte $1 (par défaut # $FQDNHOST). Il s'agit de la liste, pour chacune des instances, des # minstances qui tournent actuellement. # cette fonction n'a pas besoin de mot de passe pour fonctionner. local host="${1:-$FQDNHOST}" dumpurl -X "http://$host:1085/cgi-bin/WebObjects/wotaskd.woa/wa/woconfig" } function wotaskd_dump_running_instances() { wotaskd_dump_woconfig | awk "$AWK_FUNCTIONS"' BEGIN { in_application = 0 } !in_application && $0 ~ // { in_application = 0 } in_application && $0 ~ /APPLICATION' "$password" "$host" } function wotaskd_dump_minstances() { # afficher la configuration des minstances de wotaskd sur un hôte. Il # s'agit de la liste des instances qui sont configurées eval "$(_getopt_host_and_password)" wotaskd_command 'INSTANCE' "$password" "$host" } function dump_minstances_stats_from_stdin() { # Afficher les statistiques pour les instances de la ligne de commande à # partir de la sortie de wotaskd_dump_minstances # Les lignes affichées sont de la forme: # applicationName id port runningState activeSessions transactions startedAt avgTransactionTime averageIdlePeriod script="$AWK_FUNCTIONS"' BEGIN { in_instances = 0 } !in_instances && $0 ~ // { in_instances = 0 } in_instances && $0 ~ // { if (applicationName != ""' local mapp filter for mapp in "$@"; do filter="${filter:+$filter || }applicationName == \"$mapp\"" done [ -n "$filter" ] && filter="&& ($filter)" script="$script$filter"') { print applicationName " " id " " port " " runningState " " activeSessions " " transactions " " startedAt " " avgTransactionTime " " averageIdlePeriod } } in_instances && $0 ~ /([^<]*)<.*$", "\\1", 1) match($0, /^[^<]*<[^<>]*>/); $0 = substr($0, RSTART + RLENGTH) match($0, /<.*$/); $0 = substr($0, 1, RSTART - 1) print } ' } function wotaskd_command_instances_from_stdin() { # lancer une commande pour les instances avec les lignes lues sur stdin eval "$(_getopt_host_and_password)" local COMMAND="$1"; shift wotaskd_command "$( echo ''"$COMMAND"'' while read element; do echo ''"$element"'' done echo '' )" "$password" "$host" >&"$outputfile" } function wotaskd_update_instances_from_stdin() { # Metttre à jour les instances avec les lignes lues sur stdin eval "$(_getopt_host_and_password)" wotaskd_command "$( echo '' while read element; do echo ''"$element"'' done echo '' )" "$password" "$host" >&"$outputfile" }