1) Hello I want to make a script to run a script to start vagrant from different directory and when i log in to it i want to start few commands inside vagrant, is it possible?
call ng build
call node copy.js
sudo /etc/init.d/httpd start
sudo /etc/init.d/postgresql start
java -jar /opt/app/app-0.0.1-SNAPSHOT.jar
You can either
do vagrant shell provisioning that can be run always so add something like in your Vagrantfile
config.vm.provision "shell", privileged: false, run: "always", inline: <<-SHELL sudo /etc/init.d/httpd start sudo /etc/init.d/postgresql start java -jar /opt/app/app-0.0.1-SNAPSHOT.jar SHELL
so that will run those commands each time you run
run the commands from
vagrant ssh from the script.bat file, something like
call ng build call node copy.js cd \b\ vagrant up vagrant ssh -c "sudo /etc/init.d/httpd start" vagrant ssh -c "sudo /etc/init.d/postgresql start" vagrant ssh -c "java -jar /opt/app/app-0.0.1-SNAPSHOT.jar"
To asnwer 2nd point
Also do you know a command that I could use to stay in my directory after I exit from vagrant. I originally run this script from directory C:/a and I want to run these commands inside C:/b folder and want to stay inside C:/a after exiting
vagrant will return to the current directory it was running.
Lets say you run from c:/a your script, inside your script you're running to c:/b, when you exit from vagrant, it will return from c:/b. If you want to exit and return to c:/a, make sure to initiate a
cd c:/a before executing vagrant command
3) Also do is it possible to not run vagrant up when I do exit from vagrant but it is still up?
Its not clear -
vagrant up means you boot a VM and it is running - after this you can ssh to get inside the VM but you exit the VM at this point, the VM is still up and running until you run vagrant halt.
You might have some confusion between how vagrant is running and how it runs within your script. Make sure you get familiar to the way vagrant is running and then after you can script it.