Jump to content
Sign in to follow this  
hawihoney

Coordinated start/stop of VM/Docker thru User Scripts

1 post in this topic Last Reply

Recommended Posts

Would please somebody so kind and check these two script sniplets? I want to coordinate the Start and Stop of VMs and Dockers within a Start and Stop script. Is this how it should be done? Am I using the correct syntax and command options? Anything else I need to take into account?

 

I'm running additional Unraid arrays each in it's own VM. So the VMs need to be started first, I want to wait some time for them to complete. After that I want to create the required mount points and after that I want to start a docker.

 

Both scripts are User Scripts and applied to array start/stop.

 

May thanks in advance.

 

#!/bin/bash

# Start both VMs first
virsh start TowerVM01
virsh start TowerVM02

# Wait some time
sleep 5m

# Create base Mount Point
mkdir -p /mnt/hawi

# Create Mount Points for first VM
mkdir -p /mnt/hawi/192.168.178.101_disk1
# ...

# Create Mount Points for second VM
mkdir -p /mnt/hawi/192.168.178.102_disk1
# ...

# Mount Shares of first VM
mount -t cifs -o rw,nounix,iocharset=utf8,_netdev,file_mode=0777,dir_mode=0777,vers=3.0,username=hawi,password=****** '//192.168.178.101/disk1' '/mnt/hawi/192.168.178.101_disk1'
# ...

# Mount Shares of second VM
# mount -t cifs -o rw,nounix,iocharset=utf8,_netdev,file_mode=0777,dir_mode=0777,vers=3.0,username=hawi,password=****** '//192.168.178.102/disk1' '/mnt/hawi/192.168.178.102_disk1'

# Start Docker
docker start plex
#!/bin/bash

# Stop Docker
docker stop plex

# Unmount Shares of second VM
umount -l '/mnt/hawi/192.168.178.102_disk7'
# ...

# Unmount Shares of first VM
umount -l '/mnt/hawi/192.168.178.101_disk21'
# ...

# Remove Mount Points to second VM
rmdir '/mnt/hawi/192.168.178.102_disk7'
# ...

# Remove Mount Points to first VM
rmdir '/mnt/hawi/192.168.178.101_disk21'
# ...

# Remove base Mount Point
rmdir '/mnt/hawi'

# Stop VMs
virsh shutdown TowerVM02
virsh shutdown TowerVM01

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this