services 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh -e
  2. #
  3. # services: show what services are running on this server (configurable)
  4. #
  5. # Copyright (C) 2009 Canonical Ltd.
  6. # Copyright (C) 2011-2014 Dustin Kirkland
  7. #
  8. # Authors: Dustin Kirkland <kirkland@byobu.org>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. __services_detail() {
  22. return
  23. }
  24. service_running() {
  25. if [ -f "/etc/init/$1.conf" ]; then
  26. # Use upstart
  27. case "$(status $1 2>/dev/null)" in
  28. *running*)
  29. true
  30. ;;
  31. *)
  32. false
  33. ;;
  34. esac
  35. elif [ -f "/etc/init.d/$1" ]; then
  36. # Fall back to sysvinit
  37. /etc/init.d/$1 status >/dev/null 2>&1
  38. else
  39. false
  40. fi
  41. }
  42. __services() {
  43. local services="$SERVICES"
  44. # Users can define a list of services to monitor in $BYOBU_CONFIG_DIR/status
  45. if [ -z "$services" ]; then
  46. if [ -f "/etc/eucalyptus/eucalyptus.conf" ]; then
  47. # If the user has not defined any services, but this system is a
  48. # UEC system, default to the list of Ubuntu Enterprise Cloud Services
  49. services="eucalyptus-cloud|CLC eucalyptus-walrus|WC eucalyptus-cc|CC eucalyptus-sc|SC eucalyptus-nc|NC"
  50. fi
  51. fi
  52. output=
  53. for i in $services; do
  54. service=${i%|*}
  55. nick=${i#*|}
  56. case "$service" in
  57. eucalyptus-nc)
  58. if service_running $service; then
  59. # This is a node controller, determine VM usage
  60. . /etc/eucalyptus/eucalyptus.conf
  61. count=$(pgrep -c -f /usr/bin/kvm || true)
  62. output="$output,NC:$count"
  63. fi
  64. ;;
  65. *)
  66. service_running $service && output="$output,$nick"
  67. ;;
  68. esac
  69. done
  70. [ -n "$output" ] || return
  71. color w c; printf "%s" ${output#,}; color --
  72. }
  73. # vi: syntax=sh ts=4 noexpandtab