merge of '6af5be50367621ab5838c9f4dc4e831a81c1d225'
[openembedded.git] / packages / dbus / dbus-0.94 / dbus-1.init
1 #! /bin/sh
2 # -*- coding: utf-8 -*-
3 # Debian init.d script for D-BUS
4 # Copyright © 2003 Colin Walters <walters@debian.org>
5
6 set -e
7
8 DAEMON=/usr/bin/dbus-daemon
9 NAME=dbus
10 DAEMONUSER=messagebus
11 PIDDIR=/var/run/dbus
12 PIDFILE=$PIDDIR/pid
13 DESC="system message bus"
14 EVENTDIR=/etc/dbus-1/event.d
15
16 test -x $DAEMON || exit 0
17
18 # Source defaults file; edit that file to configure this script.
19 ENABLED=1
20 PARAMS=""
21 if [ -e /etc/default/dbus ]; then
22   . /etc/default/dbus
23 fi
24
25 test "$ENABLED" != "0" || exit 0
26
27 start_it_up()
28 {
29   if [ ! -d $PIDDIR ]; then
30     mkdir -p $PIDDIR
31     chown $DAEMONUSER $PIDDIR
32     chgrp $DAEMONUSER $PIDDIR
33   fi
34   if [ -e $PIDFILE ]; then
35     PIDDIR=/proc/$(cat $PIDFILE)
36     if [ -d ${PIDDIR} -a  "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then 
37       echo "$DESC already started; not starting."
38     else
39       echo "Removing stale PID file $PIDFILE."
40       rm -f $PIDFILE
41     fi
42   fi
43   echo -n "Starting $DESC: "
44   start-stop-daemon --start --quiet --pidfile $PIDFILE \
45     --user $DAEMONUSER --exec $DAEMON -- --system $PARAMS
46   echo "$NAME."
47   if [ -d $EVENTDIR ]; then
48       run-parts --arg=start $EVENTDIR
49   fi
50 }
51
52 shut_it_down()
53 {
54   if [ -d $EVENTDIR ]; then
55       run-parts --reverse --arg=stop $EVENTDIR
56   fi
57   echo -n "Stopping $DESC: "
58   start-stop-daemon --stop  --quiet --pidfile $PIDFILE \
59     --user $DAEMONUSER
60   # We no longer include these arguments so that start-stop-daemon
61   # can do its job even given that we may have been upgraded.
62   # We rely on the pidfile being sanely managed
63   # --exec $DAEMON -- --system $PARAMS
64   echo "$NAME."
65   rm -f $PIDFILE
66 }
67
68 case "$1" in
69   start)
70     start_it_up
71   ;;
72   stop)
73     shut_it_down
74   ;;
75   restart|force-reload)
76     shut_it_down
77     sleep 1
78     start_it_up
79   ;;
80   *)
81     echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
82     exit 1
83   ;;
84 esac
85
86 exit 0