os-subscriber 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. set -e -x
  3. gateway_address="http://ros.rancher.io/gateway"
  4. _sigProcess() {
  5. echo "SIGINT/SIGTERM signal..."
  6. kill -9 $$
  7. }
  8. trap _sigProcess SIGINT SIGKILL SIGTERM
  9. __read_policy() {
  10. policy=`ros c get rancher.upgrade.policy`
  11. if [ -z $policy ]; then
  12. echo "can not read upgrade.policy"
  13. exit 1
  14. fi
  15. return $(($policy))
  16. }
  17. __report_activity() {
  18. arch=`uname -m`
  19. uuid=`cat /sys/class/dmi/id/product_uuid || true`
  20. release=`ros -v | awk '{print $2}'`
  21. response=`wget --server-response ${gateway_address}/report --header 'Accept: application/json' --header 'Content-type: application/json' --header "arch: $arch" --header "uuid: $uuid" --header "release: $release" 2>&1 | awk '/^ HTTP/{print $2}'`
  22. if [ $response -ge 200 -a $response -le 300 ]; then
  23. echo "report activity success"
  24. else
  25. echo "report activity failed"
  26. fi
  27. }
  28. __upgrade_operate() {
  29. recommend_version=`wget ${gateway_address}/version -q -O -`
  30. case $policy in
  31. download)
  32. echo "upgrade.policy is 'download'"
  33. __report_activity
  34. system-docker pull $recommend_version
  35. ;;
  36. auto)
  37. echo "upgrade.policy is 'auto'"
  38. __report_activity
  39. ros os upgrade -i $recommend_version -f
  40. ;;
  41. none)
  42. echo "upgrade.policy is 'none'"
  43. ;;
  44. *)
  45. echo "upgrade.policy is 'illegal'"
  46. ;;
  47. esac
  48. }
  49. __read_policy
  50. __upgrade_operate