| 1 | #! /bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | #set -x |
| 4 | |
| 5 | # The type of host. Could be : |
| 6 | # - server |
| 7 | # - frontend |
| 8 | # - node |
| 9 | SCRIPT_PREFIX=oar_host_setup_as_ |
| 10 | SCRIPT_BASENAME=$(basenamescip-shell system . . basename. $0) |
| 11 | TYPE=${SCRIPT_BASENAME##$SCRIPT_PREFIX} |
| 12 | |
| 13 | THIS_HOSTNAME=$1 |
| 14 | shift |
| 15 | |
| 16 | # The first node is the server |
| 17 | SERVER_HOSTNAME=$1 |
| 18 | shift |
| 19 | |
| 20 | # The second node is the frontend |
| 21 | FRONTEND_HOSTNAME=$1 |
| 22 | shift |
| 23 | |
| 24 | # the other nodes are compute nodes. |
| 25 | NODE_HOSTNAME_LISTFILE=$1 |
| 26 | shift |
| 27 | |
| 28 | |
| 29 | configure_databasescip-shell shell shell-project 0.0.0 configure_database().() { |
| 30 | sedscip-shell system . . sed. -e "s/^DB_HOSTNAME=.*/DB_HOSTNAME=\"$SERVER_HOSTNAME\"/" -i /etc/oar/oar.confscip-shell filesystem . . `/etc/oar/oar.conf`. |
| 31 | sedscip-shell system . . sed. -e "s/^SERVER_HOSTNAME=.*/SERVER_HOSTNAME=\"$SERVER_HOSTNAME\"/" -i /etc/oar/oar.confscip-shell filesystem . . `/etc/oar/oar.conf`. |
| 32 | } |
| 33 | |
| 34 | configure_hostnamescip-shell shell shell-project 0.0.0 configure_hostname().() { |
| 35 | echoscip-shell system . . echo. "$THIS_HOSTNAME" > /etc/hostnamescip-shell filesystem . . `/etc/hostname`. |
| 36 | hostnamescip-shell system . . hostname. $THIS_HOSTNAME |
| 37 | IPV4=$(ip -o -f inet addr show scope global | awkscip-shell system . . awk. '{print $4;};' | sedscip-shell system . . sed. -e "s%/.*%%") |
| 38 | echoscip-shell system . . echo. "$IPV4 $THIS_HOSTNAME $(hostnamescip-shell system . . hostname. -s)" >> /etc/hostsscip-shell filesystem . . `/etc/hosts`. |
| 39 | } |
| 40 | |
| 41 | configure_userscip-shell shell shell-project 0.0.0 configure_user(). () { |
| 42 | adduserscip-shell system . . adduser. --disabled-password --gecos "user" user |
| 43 | mkdirscip-shell system . . mkdir. /home/user/.sshscip-shell filesystem . . `/home/user/.ssh`. |
| 44 | touchscip-shell system . . touch. /home/user/.ssh/authorized_keysscip-shell filesystem . . `/home/user/.ssh/authorized_keys`. |
| 45 | chownscip-shell system . . chown. -R user:user /home/user/.sshscip-shell filesystem . . `/home/user/.ssh`. |
| 46 | chmodscip-shell system . . chmod. 700 /home/user/.sshscip-shell filesystem . . `/home/user/.ssh`. |
| 47 | chmodscip-shell system . . chmod. 600 /home/user/.ssh/authorized_keysscip-shell filesystem . . `/home/user/.ssh/authorized_keys`. |
| 48 | adduserscip-shell system . . adduser. user sudo |
| 49 | catscip-shell system . . cat. /root/.ssh/authorized_keysscip-shell filesystem . . `/root/.ssh/authorized_keys`. >> /home/user/.ssh/authorized_keysscip-shell filesystem . . `/home/user/.ssh/authorized_keys`. |
| 50 | } |
| 51 | |
| 52 | common_setupscip-shell shell shell-project 0.0.0 common_setup().() { |
| 53 | configure_hostnamescip-shell shell shell-project 0.0.0 configure_hostname(). |
| 54 | configure_userscip-shell shell shell-project 0.0.0 configure_user(). |
| 55 | } |
| 56 | |
| 57 | |
| 58 | server_setupscip-shell shell shell-project 0.0.0 server_setup().() { |
| 59 | servicescip-shell system . . service. oar-server stop |
| 60 | servicescip-shell system . . service. mysql stop |
| 61 | |
| 62 | configure_databasescip-shell shell shell-project 0.0.0 configure_database(). |
| 63 | |
| 64 | sedscip-shell system . . sed. -e "s/^\(bind-address.*\)/#\1/" -i /etc/mysql/my.cnfscip-shell filesystem . . `/etc/mysql/my.cnf`. |
| 65 | |
| 66 | update-rc.dscip-shell system . . `update-rc.d`. oar-server enable |
| 67 | update-rc.dscip-shell system . . `update-rc.d`. mysql enable |
| 68 | servicescip-shell system . . service. mysql start |
| 69 | |
| 70 | sleepscip-shell system . . sleep. 3 |
| 71 | |
| 72 | oar-database --drop --db-admin-user root --db-host localhost || truescip-shell system . . true. |
| 73 | oar-database --create --db-admin-user root --db-host localhost || truescip-shell system . . true. |
| 74 | servicescip-shell system . . service. oar-server start |
| 75 | } |
| 76 | |
| 77 | frontend_setupscip-shell shell shell-project 0.0.0 frontend_setup().() { |
| 78 | servicescip-shell system . . service. apache2 stop |
| 79 | servicescip-shell system . . service. oidentd stop |
| 80 | |
| 81 | configure_databasescip-shell shell shell-project 0.0.0 configure_database(). |
| 82 | |
| 83 | sedscip-shell system . . sed. -e "s/^hostname.*/hostname = $SERVER_HOSTNAME/" -i /etc/oar/monika.confscip-shell filesystem . . `/etc/oar/monika.conf`. |
| 84 | sedscip-shell system . . sed. -e "s/^DB_HOSTNAME.*/DB_HOSTNAME: $SERVER_HOSTNAME/" -i /etc/oar/drawgantt.confscip-shell filesystem . . `/etc/oar/drawgantt.conf`. |
| 85 | |
| 86 | update-rc.dscip-shell system . . `update-rc.d`. oidentd enable |
| 87 | update-rc.dscip-shell system . . `update-rc.d`. apache2 enable |
| 88 | servicescip-shell system . . service. oidentd start |
| 89 | servicescip-shell system . . service. apache2 start |
| 90 | } |
| 91 | |
| 92 | node_setupscip-shell shell shell-project 0.0.0 node_setup().() { |
| 93 | servicescip-shell system . . service. oar-node stop |
| 94 | update-rc.dscip-shell system . . `update-rc.d`. oar-node enable |
| 95 | servicescip-shell system . . service. oar-node start |
| 96 | } |
| 97 | |
| 98 | |
| 99 | case $TYPE in |
| 100 | server) |
| 101 | common_setupscip-shell shell shell-project 0.0.0 common_setup(). |
| 102 | server_setupscip-shell shell shell-project 0.0.0 server_setup(). |
| 103 | ;; |
| 104 | frontend) |
| 105 | common_setupscip-shell shell shell-project 0.0.0 common_setup(). |
| 106 | frontend_setupscip-shell shell shell-project 0.0.0 frontend_setup(). |
| 107 | ;; |
| 108 | compute|node) |
| 109 | TYPE=node |
| 110 | common_setupscip-shell shell shell-project 0.0.0 common_setup(). |
| 111 | node_setupscip-shell shell shell-project 0.0.0 node_setup(). |
| 112 | ;; |
| 113 | demo) |
| 114 | common_setupscip-shell shell shell-project 0.0.0 common_setup(). |
| 115 | server_setupscip-shell shell shell-project 0.0.0 server_setup(). |
| 116 | frontend_setupscip-shell shell shell-project 0.0.0 frontend_setup(). |
| 117 | node_setupscip-shell shell shell-project 0.0.0 node_setup(). |
| 118 | ;; |
| 119 | *) |
| 120 | echoscip-shell system . . echo. "$0: The type is not valid (could be server|frontend|node|demo)" |
| 121 | exit 1 |
| 122 | ;; |
| 123 | esac |
| 124 | |
| 125 | touchscip-shell system . . touch. /root/oar-$TYPE |