dbus-1 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: dbus
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 1
  8. # Short-Description: D-Bus systemwide message bus
  9. # Description: D-Bus is a simple interprocess messaging system, used
  10. # for sending messages between applications.
  11. ### END INIT INFO
  12. #
  13. # -*- coding: utf-8 -*-
  14. # Debian init.d script for D-BUS
  15. # Copyright © 2003 Colin Walters <walters@debian.org>
  16. # set -e
  17. # Source function library.
  18. . /etc/init.d/functions
  19. DAEMON=/usr/bin/dbus-daemon
  20. NAME=dbus
  21. DAEMONUSER=messagebus # must match /etc/dbus-1/system.conf
  22. PIDFILE=/var/run/messagebus.pid # must match /etc/dbus-1/system.conf
  23. UUIDDIR=/var/lib/dbus
  24. DESC="system message bus"
  25. EVENTDIR=/etc/dbus-1/event.d
  26. test -x $DAEMON || exit 0
  27. # Source defaults file; edit that file to configure this script.
  28. ENABLED=1
  29. PARAMS=""
  30. if [ -e /etc/default/dbus ]; then
  31. . /etc/default/dbus
  32. fi
  33. test "$ENABLED" != "0" || exit 0
  34. start_it_up()
  35. {
  36. mkdir -p "`dirname $PIDFILE`"
  37. if [ -e $PIDFILE ]; then
  38. PIDDIR=/proc/$(cat $PIDFILE)
  39. if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then
  40. echo "$DESC already started; not starting."
  41. else
  42. echo "Removing stale PID file $PIDFILE."
  43. rm -f $PIDFILE
  44. fi
  45. fi
  46. if [ ! -d $UUIDDIR ]; then
  47. mkdir -p $UUIDDIR
  48. chown $DAEMONUSER $UUIDDIR
  49. chgrp $DAEMONUSER $UUIDDIR
  50. fi
  51. dbus-uuidgen --ensure
  52. echo -n "Starting $DESC: "
  53. start-stop-daemon -o --start --quiet --pidfile $PIDFILE \
  54. --user $DAEMONUSER --exec $DAEMON -- --system $PARAMS
  55. echo "$NAME."
  56. if [ -d $EVENTDIR ]; then
  57. run-parts --arg=start $EVENTDIR
  58. fi
  59. }
  60. shut_it_down()
  61. {
  62. if [ -d $EVENTDIR ]; then
  63. # TODO: --reverse when busybox supports it
  64. run-parts --arg=stop $EVENTDIR
  65. fi
  66. echo -n "Stopping $DESC: "
  67. start-stop-daemon -o --stop --quiet --pidfile $PIDFILE \
  68. --user $DAEMONUSER
  69. # We no longer include these arguments so that start-stop-daemon
  70. # can do its job even given that we may have been upgraded.
  71. # We rely on the pidfile being sanely managed
  72. # --exec $DAEMON -- --system $PARAMS
  73. echo "$NAME."
  74. rm -f $PIDFILE
  75. }
  76. reload_it()
  77. {
  78. echo -n "Reloading $DESC config: "
  79. dbus-send --print-reply --system --type=method_call \
  80. --dest=org.freedesktop.DBus \
  81. / org.freedesktop.DBus.ReloadConfig > /dev/null
  82. # hopefully this is enough time for dbus to reload it's config file.
  83. echo "done."
  84. }
  85. case "$1" in
  86. start)
  87. start_it_up
  88. ;;
  89. stop)
  90. shut_it_down
  91. ;;
  92. status)
  93. status $DAEMON
  94. exit $?
  95. ;;
  96. reload|force-reload)
  97. reload_it
  98. ;;
  99. restart)
  100. shut_it_down
  101. sleep 1
  102. start_it_up
  103. ;;
  104. *)
  105. echo "Usage: /etc/init.d/$NAME {start|stop|status|restart|reload|force-reload}" >&2
  106. exit 1
  107. ;;
  108. esac
  109. exit 0