3

I am trying to script the installation of Gluu Server with Ansible. I have the following script at the end which is supposed to launch the final setup. The issue is that the script stops after the login and restarts if I exit:

#!/bin/bash
/etc/init.d/gluu-server-2.4.2 login
cd /install/community-edition-setup/
./setup.py -n -u  -a   -s -f setup.properties

EDIT

In fact the login command issues a chroot command which is the source of my challenge:

/usr/sbin/chroot /opt/gluu-server-2.4.2/ su -
curuba
  • 527
  • 1
  • 10
  • 29

1 Answers1

0

Your basic problem is that the chroot and su start up new processes, they don't affect the process that invokes them. The chroot creates a new process to run the su command in, and the su command ends up creating a new shell process. It's this new shell that has the changed root directory. When you exit that shell it resumes executing your script, which never had is root changed. The ./setup.py command is then executed in the wrong context.

The solution is to execute the commands in the process that su creates. Something like:

#!/bin/bash
/usr/sbin/chroot /opt/gluu-server-2.4.2/ su -l -c "
    cd /install/community-edition-setup/;
    ./setup.py -n -u  -a   -s -f setup.properties"

This may not work if ./setup.py needs to interact with the user or otherwise needs a controlling terminal. In that case you may need something like:

#!/bin/bash
/usr/sbin/chroot /opt/gluu-server-2.4.2/ /bin/bash -l -c "
    cd /install/community-edition-setup/;
    ./setup.py -n -u  -a   -s -f setup.properties"

In this case the script would already need to be running as root, but you normally need to be root invoke the chroot command anyways.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • The n flag is for non interactive so this should work fine. I check and come back to hopefully accept the answer. Thanks – curuba Apr 17 '16 at 11:05