qubes-updates-proxy 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. #
  3. # tinyproxy Startup script for the tinyproxy server as Qubes updates proxy
  4. #
  5. # chkconfig: 345 85 15
  6. # description: small, efficient HTTP/SSL proxy daemon
  7. #
  8. # processname: tinyproxy
  9. # config: /etc/tinyproxy/tinyproxy-updates.conf
  10. # config: /etc/sysconfig/tinyproxy-updates
  11. # pidfile: /var/run/tinyproxy/tinyproxy-updates.pid
  12. #
  13. # Note: pidfile is created by tinyproxy in its config
  14. # see PidFile in the configuration file.
  15. # Source function library.
  16. # shellcheck disable=SC1091
  17. . /etc/rc.d/init.d/functions
  18. # Source Qubes library.
  19. # shellcheck source=init/functions
  20. . /usr/lib/qubes/init/functions
  21. # Source networking configuration.
  22. # shellcheck disable=SC1091
  23. . /etc/sysconfig/network
  24. # Check that networking is up.
  25. [ "$NETWORKING" = "no" ] && exit 0
  26. exec="$(command -v tinyproxy)"
  27. prog=$(basename "$exec")
  28. config="/etc/tinyproxy/tinyproxy-updates.conf"
  29. pidfile="/var/run/tinyproxy-updates/tinyproxy.pid"
  30. # shellcheck disable=SC1091
  31. [ -e /etc/sysconfig/tinyproxy-updates ] && . /etc/sysconfig/tinyproxy-updates
  32. lockfile=/var/lock/subsys/tinyproxy-updates
  33. start() {
  34. have_qubesdb || return
  35. if qsvc qubes-updates-proxy ; then
  36. # Yum proxy disabled
  37. exit 0
  38. fi
  39. [ -x "$exec" ] || exit 5
  40. [ -f $config ] || exit 6
  41. # setup network redirection
  42. /sbin/iptables -I INPUT -i vif+ -p tcp --dport 8082 -j ACCEPT
  43. /sbin/iptables -t nat -A PR-QBS-SERVICES -i vif+ -d 10.137.255.254 -p tcp --dport 8082 -j REDIRECT
  44. echo -n $"Starting $prog (as Qubes updates proxy): "
  45. daemon "$exec" -c $config
  46. retval=$?
  47. echo
  48. [ $retval -eq 0 ] && touch $lockfile
  49. return $retval
  50. }
  51. stop() {
  52. echo -n $"Stopping $prog: "
  53. killproc -p $pidfile "$prog"
  54. retval=$?
  55. echo
  56. /sbin/iptables -t nat -D PR-QBS-SERVICES -i vif+ -d 10.137.255.254 -p tcp --dport 8082 -j REDIRECT
  57. /sbin/iptables -D INPUT -i vif+ -p tcp --dport 8082 -j ACCEPT
  58. [ $retval -eq 0 ] && rm -f "$lockfile"
  59. return $retval
  60. }
  61. restart() {
  62. stop
  63. start
  64. }
  65. reload() {
  66. echo -n $"Reloading $prog: "
  67. killproc -p $pidfile "$prog" -HUP
  68. echo
  69. }
  70. force_reload() {
  71. restart
  72. }
  73. rh_status() {
  74. status "$prog"
  75. }
  76. rh_status_q() {
  77. rh_status >/dev/null 2>&1
  78. }
  79. case "$1" in
  80. start)
  81. rh_status_q && exit 0
  82. $1
  83. ;;
  84. stop)
  85. rh_status_q || exit 0
  86. $1
  87. ;;
  88. restart)
  89. $1
  90. ;;
  91. reload)
  92. rh_status_q || exit 7
  93. $1
  94. ;;
  95. force-reload)
  96. force_reload
  97. ;;
  98. status)
  99. rh_status
  100. ;;
  101. condrestart|try-restart)
  102. rh_status_q || exit 0
  103. restart
  104. ;;
  105. *)
  106. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  107. exit 2
  108. esac
  109. exit $?