Revert of Remove OneClickSigninHelper since it is no longer used. (patchset #5 id...
[chromium-blink-merge.git] / remoting / host / installer / linux / debian / chrome-remote-desktop.init
blob2fc0d0deeb39ea862286ded38df7b1ba11a1eef5
1 #!/bin/bash
3 ### BEGIN INIT INFO
4 # Provides: chrome-remote-desktop
5 # Required-Start: $remote_fs $syslog
6 # Required-Stop: $remote_fs $syslog
7 # Default-Start: 2 3 4 5
8 # Default-Stop: 0 1 6
9 # Short-Description: Chrome Remote Desktop service
10 ### END INIT INFO
12 # /etc/init.d/chrome-remote-desktop: Start and stop Chrome Remote Desktop host daemon.
14 HOST_PATH=/opt/google/chrome-remote-desktop/chrome-remote-desktop
16 # Group of users for which Chrome Remote Desktop is enabled. Users are added
17 # to that group when they start the host for the first time.
18 CHROME_REMOTING_GROUP=chrome-remote-desktop
20 test -x $HOST_PATH || exit 0
22 . /lib/lsb/init-functions
24 if [ "$(whoami)" = "root" ]; then
25 # Extract list of users in the chrome-remoting group.
26 USERS=$(getent group $CHROME_REMOTING_GROUP |
27 awk -F ':' '{ gsub(",", " ", $4); print $4 }')
28 else
29 USERS=$(whoami)
32 # Tries to wait for 10 seconds until specified command exits and then kills it.
33 run_with_timeout() {
34 "$@" &
35 pid=$!
36 local time_left=10
37 while [ $time_left -gt 0 ]; do
38 (kill -0 $pid 2>/dev/null) || return `wait $pid`
39 sleep 1
40 time_left=$((time_left - 1))
41 done
42 (kill -0 $pid 2>/dev/null) || return `wait $pid`
44 echo command \"$@\" has timed out >&2
45 kill $pid
46 return 1
49 # Usage: run_and_ignore_error [--login] user program [args...]
50 # --login:
51 # Run program in a clean login shell. This requires backgrounding, since
52 # the user's .profile or .login script might be run, which might contain
53 # blocking commands.
54 run_and_ignore_error() {
55 login_options=""
56 if [ "$1" = "--login" ]; then
57 login_options="-b -i"
58 shift
61 user=$1
62 shift
64 set +e
65 if [ "$(whoami)" = "$user" ]; then
66 "$@"
67 else
68 sudo -u "$user" $login_options "$@"
72 do_start() {
73 log_begin_msg "Starting Chrome Remote Desktop host for $1..."
74 run_and_ignore_error --login $1 "$HOST_PATH" --start
75 log_end_msg $?
78 do_stop() {
79 log_begin_msg "Stopping Chrome Remote Desktop host for $1..."
80 run_with_timeout run_and_ignore_error $1 "$HOST_PATH" --stop
81 log_end_msg $?
84 do_reload() {
85 log_begin_msg "Reloading Chrome Remote Desktop host configuration for $1..."
86 run_and_ignore_error $1 "$HOST_PATH" --reload
87 log_end_msg $?
90 do_restart() {
91 log_begin_msg "Restarting Chrome Remote Desktop host for $1..."
92 run_and_ignore_error $1 "$HOST_PATH" --stop
93 run_and_ignore_error --login $1 "$HOST_PATH" --start
94 log_end_msg $?
97 for_each_user() {
98 for user in $USERS; do
99 $1 $user
100 done
103 case "$1" in
104 start)
105 for_each_user do_start
108 stop)
109 for_each_user do_stop
112 reload|force-reload)
113 for_each_user do_reload
116 restart)
117 for_each_user do_restart
121 log_success_msg "Usage: /etc/init.d/chrome-remote-desktop" \
122 "{start|stop|reload|force-reload|restart}"
123 exit 1
124 esac
126 exit 0