123 lines
3.3 KiB
Bash
Executable File
123 lines
3.3 KiB
Bash
Executable File
#! /bin/sh
|
|
|
|
cd $(dirname "$0")
|
|
|
|
GREP='/usr/bin/env grep -E'
|
|
SCREEN='/usr/bin/env screen'
|
|
SED='/usr/bin/env sed -E'
|
|
if [ `uname -s` = "FreeBSD" ]; then
|
|
SU="/usr/bin/env su"
|
|
else
|
|
SU='/usr/bin/env su -s /bin/sh'
|
|
fi
|
|
PERL='/usr/bin/env perl'
|
|
|
|
reset_agents()
|
|
{
|
|
echo "killall ssh-agent" | $SU intradmin
|
|
}
|
|
|
|
launch_screen()
|
|
{
|
|
CMD=$2
|
|
if [ -n "$3" ] && [ -f "$3" ]
|
|
then
|
|
TMP=`echo mktemp | $SU intradmin`
|
|
echo "ssh-agent" | $SU intradmin > "$TMP"
|
|
echo ". $TMP; ssh-add '$3'" | $SU intradmin
|
|
CMD=". $TMP; ssh-add -l; echo; $CMD"
|
|
fi
|
|
|
|
if [ "$HOSTNAME" = "ksh" ]
|
|
then
|
|
$SCREEN -S "$1" -d -m sh -c "$CMD"
|
|
else
|
|
echo "$SCREEN -S '$1' -d -m sh -c '$CMD'" | $SU intradmin
|
|
fi
|
|
|
|
if [ -f "$TMP" ]
|
|
then
|
|
sleep 1
|
|
/bin/rm "$TMP"
|
|
fi
|
|
}
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
ACTION="restart"
|
|
else
|
|
ACTION="$1"
|
|
fi
|
|
|
|
if [ -z "$2" ]
|
|
then
|
|
HOSTNAME=`/bin/hostname`
|
|
else
|
|
HOSTNAME="$2"
|
|
fi
|
|
|
|
if [ "$ACTION" = "stop" ] || [ "$ACTION" = "restart" ]
|
|
then
|
|
# Kill old liblersorf screen sessions
|
|
if [ "$HOSTNAME" = "ksh" ]
|
|
then
|
|
for i in `pgrep sh`
|
|
do
|
|
if [ "$$" != "$i" ]
|
|
then
|
|
pkill "$i"
|
|
fi
|
|
done
|
|
else
|
|
echo "$SCREEN -ls" | $SU intradmin | $GREP '[0-9]+\.lerdorf_[a-zA-Z0-9_-]+' |
|
|
while read LINE
|
|
do
|
|
SNAME=`echo $LINE | $SED "s/^[^0-9]*([0-9]+\.[^ \t]+).*$/\1/"`
|
|
echo "$SCREEN -S \"$SNAME\" -X kill" | $SU intradmin
|
|
done
|
|
fi
|
|
fi
|
|
|
|
|
|
if [ "$ACTION" = "start" ] || [ "$ACTION" = "restart" ]
|
|
then
|
|
case $HOSTNAME in
|
|
|
|
cpp)
|
|
launch_screen "lerdorf_process_exec_guantanamo" "while true; do $PERL ~/liblerdorf/process/exec/guantanamo.pl; done"
|
|
reset_agents
|
|
launch_screen "lerdorf_process_ldap_sync_ssh_keys_forge" "while true; do $PERL ~/liblerdorf/process/ldap/sync_ssh_keys_forge.pl; done" ~intradmin/.ssh/git
|
|
;;
|
|
|
|
hamano)
|
|
reset_agents
|
|
launch_screen "lerdorf_process_ldap_sync_ssh_keys_git" "while true; do $PERL ~/liblerdorf/process/ldap/sync_ssh_keys_git.pl; done" ~intradmin/.ssh/git
|
|
launch_screen "lerdorf_process_send_git" "while true; do $PERL ~/liblerdorf/process/files/send_git.pl; done" ~intradmin/.ssh/git
|
|
;;
|
|
|
|
moore)
|
|
launch_screen "lerdorf_process_ldap_check_ssh_key" "while true; do $PERL ~/liblerdorf/process/ldap/check_ssh_key.pl; done"
|
|
launch_screen "lerdorf_process_ldap_sync_ssh_keys" "while true; do $PERL ~/liblerdorf/process/ldap/sync_ssh_keys.pl; done"
|
|
launch_screen "lerdorf_process_ldap_update_group" "while true; do $PERL ~/liblerdorf/process/ldap/update_group.pl; done"
|
|
launch_screen "lerdorf_process_ldap_update_user" "while true; do $PERL ~/liblerdorf/process/ldap/update_user.pl; done"
|
|
|
|
#launch_screen "lerdorf_process_files_intradata_get" "while true; do $PERL ~/liblerdorf/process/files/intradata_get.pl; done"
|
|
;;
|
|
|
|
noyce)
|
|
launch_screen "lerdorf_process_files_intradata_get" "while true; do $PERL ~/liblerdorf/process/files/intradata_get.pl; done"
|
|
launch_screen "lerdorf_process_projects_gen_grading" "while true; do $PERL ~/liblerdorf/process/projects/gen_grading.pl; done"
|
|
launch_screen "lerdorf_process_projects_get_csv" "while true; do $PERL ~/liblerdorf/process/projects/get_csv.pl; done"
|
|
;;
|
|
|
|
ksh)
|
|
launch_screen "lerdorf_process_files_moulette_get" "while true; do $PERL ~/liblerdorf/process/files/moulette_get.pl; done"
|
|
;;
|
|
|
|
*)
|
|
echo "No process to launch for $HOSTNAME" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|