Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

ambari-server upgrade + how to automate the question - have made a backup of the Ambari Server database

avatar

how to automate the question ( we need to set it as always yes )

 - have made a backup of the Ambari Server database [y/n] (y)

when performing ambari-server upgrade

we need to automate this because we use the ambari-server upgrade in bash script

ambari-server upgrade

Using python  /usr/bin/pythonUpgrading ambari-serverINFO: Upgrade Ambari ServerINFO: Updating Ambari Server properties in ambari.properties
...WARNING: Can not find ambari.properties.rpmsave file from
previous version, skipping import of settingsINFO: Updating Ambari Server properties in ambari-env.sh ...INFO: Can not find ambari-env.sh.rpmsave file from previous
version, skipping restore of environment settings. ambari-env.sh may not
include any user customization.INFO: Fixing database objects ownerAmbari Server configured for Embedded Postgres. Confirm you


have made a backup of the Ambari Server database [y/n] (y)?

INFO: Upgrading database schemaINFO: Return code from schema upgrade command, retcode = 0INFO: Console output from schema upgrade command:INFO: {"lzo_enabled":"false"}INFO: Schema upgrade completedAdjusting ambari-server permissions and ownership...Ambari Server 'upgrade' completed successfully.
Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Master Mentor

@Michael Bronson


You can use "expect" utility offered by Linux as following:
1. Install that package:

# yum install expect -y 


2. Create a file as following as "/tmp/test.sh"

#!/usr/bin/expect 
set timeout 20
spawn /usr/sbin/ambari-server upgrade
expect "Ambari Server configured for Postgres. Confirm you have made a backup of the Ambari Server database" { send "y\n" }
interact

Notice i am passing "y". here { send "y\n" } which means it will take my input as "yes"


3. Give execute permission to the script and then run it

# chmod 755 /tmp/test.sh
# /tmp/test.sh

OUTPUT:
---------

# /tmp/test.sh 
spawn /usr/sbin/ambari-server upgrade
Using python  /usr/bin/python
Upgrading ambari-server
INFO: Upgrade Ambari Server
INFO: Updating Ambari Server properties in ambari.properties ...
WARNING: Can not find ambari.properties.rpmsave file from previous version, skipping import of settings
INFO: Updating Ambari Server properties in ambari-env.sh ...
INFO: Can not find ambari-env.sh.rpmsave file from previous version, skipping restore of environment settings. ambari-env.sh may not include any user customization.
INFO: Fixing database objects owner
Ambari Server configured for Postgres. Confirm you have made a backup of the Ambari Server database [y/n] (y)? y
INFO: Upgrading database schema
INFO: Return code from schema upgrade command, retcode = 0
INFO: Schema upgrade completed
Adjusting ambari-server permissions and ownership...
Ambari Server 'upgrade' completed successfully.



Notice i am passing "y". here { send "y\n" } which means it will take my input as "yes"

.

View solution in original post

2 REPLIES 2

avatar
Master Mentor

@Michael Bronson


You can use "expect" utility offered by Linux as following:
1. Install that package:

# yum install expect -y 


2. Create a file as following as "/tmp/test.sh"

#!/usr/bin/expect 
set timeout 20
spawn /usr/sbin/ambari-server upgrade
expect "Ambari Server configured for Postgres. Confirm you have made a backup of the Ambari Server database" { send "y\n" }
interact

Notice i am passing "y". here { send "y\n" } which means it will take my input as "yes"


3. Give execute permission to the script and then run it

# chmod 755 /tmp/test.sh
# /tmp/test.sh

OUTPUT:
---------

# /tmp/test.sh 
spawn /usr/sbin/ambari-server upgrade
Using python  /usr/bin/python
Upgrading ambari-server
INFO: Upgrade Ambari Server
INFO: Updating Ambari Server properties in ambari.properties ...
WARNING: Can not find ambari.properties.rpmsave file from previous version, skipping import of settings
INFO: Updating Ambari Server properties in ambari-env.sh ...
INFO: Can not find ambari-env.sh.rpmsave file from previous version, skipping restore of environment settings. ambari-env.sh may not include any user customization.
INFO: Fixing database objects owner
Ambari Server configured for Postgres. Confirm you have made a backup of the Ambari Server database [y/n] (y)? y
INFO: Upgrading database schema
INFO: Return code from schema upgrade command, retcode = 0
INFO: Schema upgrade completed
Adjusting ambari-server permissions and ownership...
Ambari Server 'upgrade' completed successfully.



Notice i am passing "y". here { send "y\n" } which means it will take my input as "yes"

.

avatar
Contributor

You could make use of option "-s" or "--silent",

like in

ambari-server upgrade -s