| 1 |
#! /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=$(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_database() { |
| 30 |
sed -e "s/^DB_HOSTNAME=.*/DB_HOSTNAME=\"$SERVER_HOSTNAME\"/" -i /etc/oar/oar.conf |
| 31 |
sed -e "s/^SERVER_HOSTNAME=.*/SERVER_HOSTNAME=\"$SERVER_HOSTNAME\"/" -i /etc/oar/oar.conf |
| 32 |
} |
| 33 |
|
| 34 |
configure_hostname() { |
| 35 |
echo "$THIS_HOSTNAME" > /etc/hostname |
| 36 |
hostname $THIS_HOSTNAME |
| 37 |
IPV4=$(ip -o -f inet addr show scope global | awk '{print $4;};' | sed -e "s%/.*%%") |
| 38 |
echo "$IPV4 $THIS_HOSTNAME $(hostname -s)" >> /etc/hosts |
| 39 |
} |
| 40 |
|
| 41 |
configure_user () { |
| 42 |
adduser --disabled-password --gecos "user" user |
| 43 |
mkdir /home/user/.ssh |
| 44 |
touch /home/user/.ssh/authorized_keys |
| 45 |
chown -R user:user /home/user/.ssh |
| 46 |
chmod 700 /home/user/.ssh |
| 47 |
chmod 600 /home/user/.ssh/authorized_keys |
| 48 |
adduser user sudo |
| 49 |
cat /root/.ssh/authorized_keys >> /home/user/.ssh/authorized_keys |
| 50 |
} |
| 51 |
|
| 52 |
common_setup() { |
| 53 |
configure_hostname |
| 54 |
configure_user |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
server_setup() { |
| 59 |
service oar-server stop |
| 60 |
service mysql stop |
| 61 |
|
| 62 |
configure_database |
| 63 |
|
| 64 |
sed -e "s/^\(bind-address.*\)/#\1/" -i /etc/mysql/my.cnf |
| 65 |
|
| 66 |
update-rc.d oar-server enable |
| 67 |
update-rc.d mysql enable |
| 68 |
service mysql start |
| 69 |
|
| 70 |
sleep 3 |
| 71 |
|
| 72 |
oar-database --drop --db-admin-user root --db-host localhost || true |
| 73 |
oar-database --create --db-admin-user root --db-host localhost || true |
| 74 |
service oar-server start |
| 75 |
} |
| 76 |
|
| 77 |
frontend_setup() { |
| 78 |
service apache2 stop |
| 79 |
service oidentd stop |
| 80 |
|
| 81 |
configure_database |
| 82 |
|
| 83 |
sed -e "s/^hostname.*/hostname = $SERVER_HOSTNAME/" -i /etc/oar/monika.conf |
| 84 |
sed -e "s/^DB_HOSTNAME.*/DB_HOSTNAME: $SERVER_HOSTNAME/" -i /etc/oar/drawgantt.conf |
| 85 |
|
| 86 |
update-rc.d oidentd enable |
| 87 |
update-rc.d apache2 enable |
| 88 |
service oidentd start |
| 89 |
service apache2 start |
| 90 |
} |
| 91 |
|
| 92 |
node_setup() { |
| 93 |
service oar-node stop |
| 94 |
update-rc.d oar-node enable |
| 95 |
service oar-node start |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
case $TYPE in |
| 100 |
server) |
| 101 |
common_setup |
| 102 |
server_setup |
| 103 |
;; |
| 104 |
frontend) |
| 105 |
common_setup |
| 106 |
frontend_setup |
| 107 |
;; |
| 108 |
compute|node) |
| 109 |
TYPE=node |
| 110 |
common_setup |
| 111 |
node_setup |
| 112 |
;; |
| 113 |
demo) |
| 114 |
common_setup |
| 115 |
server_setup |
| 116 |
frontend_setup |
| 117 |
node_setup |
| 118 |
;; |
| 119 |
*) |
| 120 |
echo "$0: The type is not valid (could be server|frontend|node|demo)" |
| 121 |
exit 1 |
| 122 |
;; |
| 123 |
esac |
| 124 |
|
| 125 |
touch /root/oar-$TYPE |