Advertisement
Marionumber1

recycle.sh

Apr 23rd, 2020
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ct_num=$1
  4.  
  5. # Kill currently running tail process
  6. kill -9 $(ps aux | grep "tail -n 0 -F /var/lib/lxc/$ct_num/rootfs/var/log/auth.log" | awk '{print $2}')
  7.  
  8. sleep 10
  9.  
  10. # Unmount the container
  11. pct unmount $ct_num
  12.  
  13. # Stop the container
  14. pct unlock $ct_num
  15. pct stop $ct_num --skiplock 1
  16.  
  17. # Unmount container again
  18. # (it’s silly, but we need to do this because of pct’s inconsistency)
  19. pct unmount $ct_num
  20.  
  21. # Destroy the container
  22. pct destroy $ct_num
  23.  
  24.  
  25. # Prepare template for cloneing
  26. pct unlock 201
  27.  
  28. # We want to repeatedly try the clone process until it succeeds
  29. while ! pct clone 201 $ct_num --experimental false; do
  30.     # Wait for 30 seconds before trying again
  31.     sleep 30;
  32. done
  33.  
  34. pct unlock 201
  35.  
  36. # Update networking configuration for container 201
  37. if [ $ct_num -eq "102" ]; then
  38.     pct set 102 --net0 name=eth0,bridge=vmbr0,ip=172.20.0.3/16,gw=172.20.0.1
  39. fi
  40.  
  41. # Restart desired container
  42. pct start $ct_num
  43.  
  44. # Mount the container
  45. pct unlock $ct_num
  46. rm -f /run/lock/lxc/pve-config-$ct_num.lock
  47. pct mount $ct_num
  48.  
  49. echo "Recycled container $ct_num"
  50.  
  51. # Restart monitor script
  52. tail -n 0 -F /var/lib/lxc/$ct_num/rootfs/var/log/auth.log | ~/monitor.sh $ct_num &
  53. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement