| OLD | NEW | 
|    1 #!/bin/bash |    1 #!/bin/bash | 
|    2  |    2  | 
|    3 ### BEGIN INIT INFO |    3 ### BEGIN INIT INFO | 
|    4 # Provides:             chrome-remote-desktop |    4 # Provides:             chrome-remote-desktop | 
|    5 # Required-Start:       $remote_fs $syslog |    5 # Required-Start:       $remote_fs $syslog | 
|    6 # Required-Stop:        $remote_fs $syslog |    6 # Required-Stop:        $remote_fs $syslog | 
|    7 # Default-Start:        2 3 4 5 |    7 # Default-Start:        2 3 4 5 | 
|    8 # Default-Stop:         0 1 6 |    8 # Default-Stop:         0 1 6 | 
|    9 # Short-Description:    Chrome Remote Desktop service |    9 # Short-Description:    Chrome Remote Desktop service | 
|   10 ### END INIT INFO |   10 ### END INIT INFO | 
|   11  |   11  | 
|   12 # /etc/init.d/chrome-remote-desktop: Start and stop Chrome Remote Desktop host d
     aemon. |   12 # /etc/init.d/chrome-remote-desktop: Start and stop Chrome Remote Desktop host d
     aemon. | 
|   13  |   13  | 
|   14 HOST_PATH=/opt/google/chrome-remote-desktop/chrome-remote-desktop |   14 HOST_PATH=/opt/google/chrome-remote-desktop/chrome-remote-desktop | 
 |   15 USER_SESSION_PATH=/opt/google/chrome-remote-desktop/user-session | 
|   15  |   16  | 
|   16 # Group of users for which Chrome Remote Desktop is enabled. Users are added |   17 # 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 # to that group when they start the host for the first time. | 
|   18 CHROME_REMOTING_GROUP=chrome-remote-desktop |   19 CHROME_REMOTING_GROUP=chrome-remote-desktop | 
|   19  |   20  | 
|   20 test -x $HOST_PATH || exit 0 |   21 test -x $HOST_PATH || exit 0 | 
|   21  |   22  | 
|   22 . /lib/lsb/init-functions |   23 . /lib/lsb/init-functions | 
|   23  |   24  | 
|   24 if [ "$(whoami)" = "root" ]; then |   25 if [ "$(whoami)" = "root" ]; then | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   39     sleep 1 |   40     sleep 1 | 
|   40     time_left=$((time_left - 1)) |   41     time_left=$((time_left - 1)) | 
|   41   done |   42   done | 
|   42   (kill -0 $pid 2>/dev/null) || return `wait $pid` |   43   (kill -0 $pid 2>/dev/null) || return `wait $pid` | 
|   43  |   44  | 
|   44   echo command \"$@\" has timed out >&2 |   45   echo command \"$@\" has timed out >&2 | 
|   45   kill $pid |   46   kill $pid | 
|   46   return 1 |   47   return 1 | 
|   47 } |   48 } | 
|   48  |   49  | 
|   49 # Usage: run_and_ignore_error [--login] user program [args...] |   50 # Usage: run_and_ignore_error user action | 
|   50 #   --login: |   51 # Carries out the specified action, ignoring any errors. | 
|   51 #     Run program in a clean login shell. This requires backgrounding, since |   52 #   action: | 
|   52 #     the user's .profile or .login script might be run, which might contain |   53 #     --start is handled specially using the user-session wrapper to start a | 
|   53 #     blocking commands. |   54 #     clean log-in session. In any other case, the host script is called through | 
 |   55 #     sudo with the specified action flag. | 
|   54 run_and_ignore_error() { |   56 run_and_ignore_error() { | 
|   55   login_options="" |   57   user="$1" | 
|   56   if [ "$1" = "--login" ]; then |   58   action="$2" | 
|   57     login_options="-b -i" |  | 
|   58     shift |  | 
|   59   fi |  | 
|   60  |  | 
|   61   user=$1 |  | 
|   62   shift |  | 
|   63  |   59  | 
|   64   set +e |   60   set +e | 
|   65   sudo -u "$user" $login_options "$@" |   61   if [ "$action" = "--start" ]; then | 
 |   62     "$USER_SESSION_PATH" --user="$user" --me2me-script="$HOST_PATH" | 
 |   63   else | 
 |   64     sudo -u "$user" "$HOST_PATH" "$action" | 
 |   65   fi | 
|   66 } |   66 } | 
|   67  |   67  | 
|   68 do_start() { |   68 do_start() { | 
|   69   log_begin_msg "Starting Chrome Remote Desktop host for $1..." |   69   log_begin_msg "Starting Chrome Remote Desktop host for $1..." | 
|   70   run_and_ignore_error --login $1 "$HOST_PATH" --start |   70   run_and_ignore_error $1 --start | 
|   71   log_end_msg $? |   71   log_end_msg $? | 
|   72 } |   72 } | 
|   73  |   73  | 
|   74 do_stop() { |   74 do_stop() { | 
|   75   log_begin_msg "Stopping Chrome Remote Desktop host for $1..." |   75   log_begin_msg "Stopping Chrome Remote Desktop host for $1..." | 
|   76   run_with_timeout run_and_ignore_error $1 "$HOST_PATH" --stop |   76   run_with_timeout run_and_ignore_error $1 --stop | 
|   77   log_end_msg $? |   77   log_end_msg $? | 
|   78 } |   78 } | 
|   79  |   79  | 
|   80 do_reload() { |   80 do_reload() { | 
|   81   log_begin_msg "Reloading Chrome Remote Desktop host configuration for $1..." |   81   log_begin_msg "Reloading Chrome Remote Desktop host configuration for $1..." | 
|   82   run_and_ignore_error $1 "$HOST_PATH" --reload |   82   run_and_ignore_error $1 --reload | 
|   83   log_end_msg $? |   83   log_end_msg $? | 
|   84 } |   84 } | 
|   85  |   85  | 
|   86 do_restart() { |   86 do_restart() { | 
|   87   log_begin_msg "Restarting Chrome Remote Desktop host for $1..." |   87   log_begin_msg "Restarting Chrome Remote Desktop host for $1..." | 
|   88   run_and_ignore_error $1 "$HOST_PATH" --stop |   88   run_and_ignore_error $1 --stop | 
|   89   run_and_ignore_error --login $1 "$HOST_PATH" --start |   89   run_and_ignore_error $1 --start | 
|   90   log_end_msg $? |   90   log_end_msg $? | 
|   91 } |   91 } | 
|   92  |   92  | 
|   93 for_each_user() { |   93 for_each_user() { | 
|   94   for user in $USERS; do |   94   for user in $USERS; do | 
|   95     $1 $user |   95     $1 $user | 
|   96   done |   96   done | 
|   97 } |   97 } | 
|   98  |   98  | 
|   99 case "$1" in |   99 case "$1" in | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  113     for_each_user do_restart |  113     for_each_user do_restart | 
|  114     ;; |  114     ;; | 
|  115  |  115  | 
|  116   *) |  116   *) | 
|  117     log_success_msg "Usage: /etc/init.d/chrome-remote-desktop" \ |  117     log_success_msg "Usage: /etc/init.d/chrome-remote-desktop" \ | 
|  118         "{start|stop|reload|force-reload|restart}" |  118         "{start|stop|reload|force-reload|restart}" | 
|  119     exit 1 |  119     exit 1 | 
|  120 esac |  120 esac | 
|  121  |  121  | 
|  122 exit 0 |  122 exit 0 | 
| OLD | NEW |