f37 -> f39
[infrastructure.git] / scripts / trash / reboot-all.sh
1 #!/bin/bash
2
3 # by default : reboot the boxes involved in testing
4 # with -a : reboot also the build boxes
5
6 COMMAND=$(basename $0)
7 function usage () {
8     echo "$COMMAND [-abtn]"
9     echo -e " -a\tall boxes, not just the test ones"
10     echo -e " -b\tbuild boxes only"
11     echo -e " -t\tjust clean the trackers"
12     echo -e " -n\tdry-run"
13     exit 1
14 }
15
16 build_boxes="mirror $(echo build{1,2,3})"
17 test_boxes="testplc $(echo testqemu{1,2,3} testqemu32-{1,2,3,4,5})"
18
19 while getopts "abtnh" opt ; do
20     case $opt in
21         a) ALL_BOXES=true ;;
22         b) BUILD_BOXES_ONLY=true ;;
23         t) TRACKERS_ONLY=true ;;
24         n) DRY_RUN=true ;;
25         h|*) usage ;;
26     esac
27 done
28 toshift=$(($OPTIND - 1))
29 shift $toshift
30         
31 CLEAN_TRACKERS="yes"
32 if [[ -n "$@" ]] ; then
33     BOXES="$@"
34 elif [ -n "$ALL_BOXES" ] ; then
35     BOXES="$build_boxes $test_boxes"
36 elif [ -n "$BUILD_BOXES_ONLY" ] ; then
37     BOXES="$build_boxes"
38     CLEAN_TRACKERS=""
39 elif [ -n "$TRACKERS_ONLY" ] ; then
40     BOXES=""
41     CLEAN_TRACKERS="yes"
42 else
43     BOXES="$test_boxes"
44 fi
45
46 if [ -n "$CLEAN_TRACKERS" ] ; then
47     echo '==================== cleaning trackers on testmaster'
48     if [ -n "$DRY_RUN" ] ; then
49         echo DRYRUN: ssh root@testmaster.onelab.eu rm 'tracker*'
50     else
51         ssh root@testmaster.onelab.eu rm 'tracker*'
52     fi
53 fi
54
55 function host_detail () {
56     box=$1; shift
57     host ${box} | tail -1
58 }
59
60 for box in $BOXES; do
61     msg=$(host ${box}.onelab.eu | grep alias)
62     echo "==================== rebooting ${box}.onelab.eu ($msg)"
63     command="ssh root@${box}.onelab.eu shutdown -r now"
64     if [ -n "$DRY_RUN" ] ; then
65         echo DRYRUN: $command
66     else
67         $command
68     fi
69 done