Process stops after inline script is done via Vagr

2019-08-22 11:30发布

问题:

In Vagrant, I run an inline script that starts up Weblogic and NodeManager

/opt/weblogic/user_projects/domains/custom/startWeblogic.sh &
/opt/weblogic/user_proejcts/domains/custom/bin/startNodeManager &

ps -ef shows that both processes are running when running the inline script. But if I were to ssh in the guest machine and run ps -ef, neither processes are to be found. Is there a way to keep the processes running after the inline script?

回答1:

Currently you running the script but its executed as root user so all the lines are added for this user only. You want to use the privileged option

privileged (boolean) - Specifies whether to execute the shell script as a privileged user or not (sudo). By default this is "true".

you will want to run the script with the vagrant user so you can change to

config.vm.provision "shell", inline: "/vagrant/scripts/install.sh",  privileged: false

You should then use nohup to keep the script running after the session is stopped

nohup /opt/weblogic/user_projects/domains/custom/startWeblogic.sh  &> /home/vagrant/startWeblogic.out&
nohup /opt/weblogic/user_proejcts/domains/custom/bin/startNodeManager  &> /home/vagrant/startNodeManager.out&