5b86cc506816f1cdf0733cf898ab1642f1365db5
[profile/ivi/weston.git] / packaging / rc.weston
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          weston
4 # Required-Start:    $remote_fs $syslog
5 # Required-Stop:     $remote_fs $syslog
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Weston compositor boot script
9 # Description:       This script starts the Weston compositor at boot.
10 ### END INIT INFO
11
12 # Author: Ossama Othman
13 #
14 # Please remove the "Author" lines above and replace them
15 # with your own name if you copy and modify this script.
16
17 # Do NOT "set -e"
18
19
20 backend=
21
22 # Use the Weston DRM backend if $DISPLAY is set and X isn't running
23 #since Weston won't be able use the X11 backend.
24 #
25 # This allows this script to start Weston with either the X11 or DRM
26 #backends.
27 if [ -z `pidof Xorg` ] && [ -n "$DISPLAY" ]; then
28     backend="--backend=drm-backend.so"
29 fi
30
31 # PATH should only include /usr/* if it runs after the mountnfs.sh script
32 PATH=/sbin:/usr/sbin:/bin:/usr/bin
33 DESC="Weston compositor"
34 NAME=weston
35 DAEMON=/usr/bin/weston
36 DAEMON_ARGS="$backend --log=/var/log/weston.log"
37 PIDFILE=/var/run/$NAME.pid
38 SCRIPTNAME=/etc/init.d/$NAME
39
40 # Exit if the package is not installed
41 [ -x "$DAEMON" ] || exit 0
42
43 # Read configuration variable file if it is present
44 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
45
46 # Load the VERBOSE setting and other rcS variables
47 . /lib/init/vars.sh
48
49 # Define LSB log_* functions.
50 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
51 # and status_of_proc is working.
52 . /lib/lsb/init-functions
53
54 #
55 # Function that starts the daemon/service
56 #
57 do_start()
58 {
59         # Make sure we have a sane XDG_RUNTIME_DIR environment
60         # variable set.
61         if [ -z "${XDG_RUNTIME_DIR}" ]; then
62             . /etc/profile.d/weston.sh
63         fi
64
65         # Return
66         #   0 if daemon has been started
67         #   1 if daemon was already running
68         #   2 if daemon could not be started
69         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
70                 || return 1
71         # start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON -- \
72         #       $DAEMON_ARGS \
73         #       || return 2
74         $DAEMON $DAEMON_ARGS &
75         weston_pid=$!
76
77         if [ $weston_pid = 0 ]; then
78             return 2
79         else
80             echo $weston_pid > $PIDFILE
81         fi
82
83         # Add code here, if necessary, that waits for the process to be ready
84         # to handle requests from services started subsequently which depend
85         # on this one.  As a last resort, sleep for some time.
86
87         # ************************************************************
88         # HACK TO WORK AROUND INSUFFICIENT ACCESS PERMISSIONS FOR
89         # UNPRIVILEGED USERS.
90         #
91         # Ideally we should launch weston with weston-launch with the
92         # appropriate --user flag.  Unfortunately, weston-launch isn't
93         # available due to missing package dependencies.
94         # ************************************************************
95         chmod 777 $XDG_RUNTIME_DIR/wayland-0
96
97         # ***********************************************************
98         # HACK TO WORK AROUND BROKEN INFINITE LOOPS IN BOOT ANIMATION
99         # VIRTUAL KEYBOARD BOOT SCRIPTS.
100         # ***********************************************************
101         touch /tmp/.X0-lock
102         touch /tmp/.wm_ready
103         # ***********************************************************
104 }
105
106 #
107 # Function that stops the daemon/service
108 #
109 do_stop()
110 {
111         # Return
112         #   0 if daemon has been stopped
113         #   1 if daemon was already stopped
114         #   2 if daemon could not be stopped
115         #   other if a failure occurred
116         #start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
117         start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME
118         RETVAL="$?"
119         [ "$RETVAL" = 2 ] && return 2
120         # Wait for children to finish too if this is a daemon that forks
121         # and if the daemon is only ever run from this initscript.
122         # If the above conditions are not satisfied then add some other code
123         # that waits for the process to drop all resources that could be
124         # needed by services started subsequently.  A last resort is to
125         # sleep for some time.
126         #start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
127         start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
128         [ "$?" = 2 ] && return 2
129         # Many daemons don't delete their pidfiles when they exit.
130         rm -f $PIDFILE
131         return "$RETVAL"
132 }
133
134 #
135 # Function that sends a SIGHUP to the daemon/service
136 #
137 do_reload() {
138         #
139         # If the daemon can reload its configuration without
140         # restarting (for example, when it is sent a SIGHUP),
141         # then implement that here.
142         #
143         start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
144         return 0
145 }
146
147 case "$1" in
148   start)
149         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
150         do_start
151         case "$?" in
152                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
153                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
154         esac
155         ;;
156   stop)
157         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
158         do_stop
159         case "$?" in
160                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
161                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
162         esac
163         ;;
164   status)
165        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
166        ;;
167   #reload|force-reload)
168         #
169         # If do_reload() is not implemented then leave this commented out
170         # and leave 'force-reload' as an alias for 'restart'.
171         #
172         #log_daemon_msg "Reloading $DESC" "$NAME"
173         #do_reload
174         #log_end_msg $?
175         #;;
176   restart|force-reload)
177         #
178         # If the "reload" option is implemented then remove the
179         # 'force-reload' alias
180         #
181         log_daemon_msg "Restarting $DESC" "$NAME"
182         do_stop
183         case "$?" in
184           0|1)
185                 do_start
186                 case "$?" in
187                         0) log_end_msg 0 ;;
188                         1) log_end_msg 1 ;; # Old process is still running
189                         *) log_end_msg 1 ;; # Failed to start
190                 esac
191                 ;;
192           *)
193                 # Failed to stop
194                 log_end_msg 1
195                 ;;
196         esac
197         ;;
198   *)
199         #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
200         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
201         exit 3
202         ;;
203 esac
204
205 :