diff --git a/postservice/30-one-mng b/postservice/30-one-mng index 05386c3..41fb52b 100755 --- a/postservice/30-one-mng +++ b/postservice/30-one-mng @@ -433,7 +433,7 @@ function init_ha() { # server 0 not displayed with onezone SERVER=$(CreoleGet one_master) DOMAIN=$(CreoleGet nom_domaine_machine) - FOLLOWER=$(CreoleGet one_follower_servername) + FOLLOWER=$(CreoleGet one_followers_domain) onezone server-add 0 --name $SERVER --rpc http://$DOMAIN:2633/RPC2 for $follower in $FOLLOWER; do onezone server-add 0 --name $follower --rpc http://$follower:2633/RPC2 @@ -441,26 +441,12 @@ function init_ha() { fi } -function to_mysql() { - if [ $(CreoleGet one_database_type) = "mysql" && $(CreoleGet one_ha_role leader) = "leader" ]; then - # do not recover db on follower - HOST=$(CreoleGet one_database_host) - DB=$(CreoleGet one_database_name) - USER=$(CreoleGet one_database_user) - PASS=$(CreoleGet one_database_pass) - onedb sqlite2mysql -s /var/lib/one/one.db -u $USER -p $PASS -d $DB -S $HOST - systemctl stop opennebula.service - systemctl start opennebula.service - fi -} - function main() { wait_true_retcode "Wait for oned to be started" "onecluster show 0 > /dev/null" if [ $(CreoleGet one_ha_role) = "leader" ]; then init_ha fi - to_mysql # # Rename default cluster clst_name=$(CreoleGet one_cluster_name) diff --git a/posttemplate/90-one-db b/posttemplate/90-one-db index dd2963a..f5f2ea5 100644 --- a/posttemplate/90-one-db +++ b/posttemplate/90-one-db @@ -9,36 +9,51 @@ function clean_backups() { - file=${1} - bcks=($(ls ${file}_*)) - nbbck=$(expr ${#bcks[@]} - 2) + file=${1} + bcks=($(ls ${file}_*)) + nbbck=$(expr ${#bcks[@]} - 2) - if [[ ${nbbck} -gt 1 ]] - then - EchoGras "Cleaning up old backups !" - for idx in `seq 0 ${nbbck}` - do - rm -f ${bcks[${idx}]} - done - fi + if [[ ${nbbck} -gt 1 ]] + then + EchoGras "Cleaning up old backups !" + for idx in `seq 0 ${nbbck}` + do + rm -f ${bcks[${idx}]} + done + fi } function updateDB() { - local dbfile='/var/lib/one/one.db' - local cmd="onedb" - local res=0 + local dbfile='/var/lib/one/one.db' + local cmd="onedb" + local res=0 - if [[ -f ${dbfile} ]] - then - $cmd upgrade -f -s ${dbfile} - res=${?} - clean_backups ${dbfile} - return ${res} - else - return 0 - fi + if [[ -f ${dbfile} ]] + then + $cmd upgrade -f -s ${dbfile} + res=${?} + clean_backups ${dbfile} + return ${res} + else + return 0 + fi +} + +function to_mysql() { + if [ $(CreoleGet one_database_type) = "mysql" ] && [ $(CreoleGet one_ha_role leader) = "leader" ]; then + Question_ouinon "Voulez-vous migrer de SQLite à Mysql ?" "True" "non" "warn" + rep=$(echo "$?") + if [ "$rep" == "0" ]; then + # do not recover db on follower + HOST=$(CreoleGet one_database_host) + DB=$(CreoleGet one_database_name) + USER=$(CreoleGet one_database_user) + PASS=$(CreoleGet one_database_pass) + onedb sqlite2mysql -s /var/lib/one/one.db -u $USER -p $PASS -d $DB -S $HOST + fi + fi } echo @@ -46,4 +61,5 @@ EchoGras "Mise à jour de la base de données ONE" echo updateDB echo +to_mysql exit ${?} diff --git a/preservice/30-one-auth b/preservice/30-one-auth index dc5ddb0..5c54019 100644 --- a/preservice/30-one-auth +++ b/preservice/30-one-auth @@ -8,3 +8,8 @@ if [ -z "${auth_mode}" ]; then else ln -s /var/lib/one/remotes/auth/{${auth_mode},default} fi + +# creation de la base /var/lib/one/one.db +systemctl daemon-reload +systemctl start opennebula.service +exit 0