| 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 | |
| 16 | 15 |
| 17 # Group of users for which Chrome Remote Desktop is enabled. Users are added | 16 # Group of users for which Chrome Remote Desktop is enabled. Users are added |
| 18 # to that group when they start the host for the first time. | 17 # to that group when they start the host for the first time. |
| 19 CHROME_REMOTING_GROUP=chrome-remote-desktop | 18 CHROME_REMOTING_GROUP=chrome-remote-desktop |
| 20 | 19 |
| 21 test -x $HOST_PATH || exit 0 | 20 test -x $HOST_PATH || exit 0 |
| 22 | 21 |
| 23 . /lib/lsb/init-functions | 22 . /lib/lsb/init-functions |
| 24 | 23 |
| 25 if [ "$(whoami)" = "root" ]; then | 24 if [ "$(whoami)" = "root" ]; then |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 sleep 1 | 39 sleep 1 |
| 41 time_left=$((time_left - 1)) | 40 time_left=$((time_left - 1)) |
| 42 done | 41 done |
| 43 (kill -0 $pid 2>/dev/null) || return `wait $pid` | 42 (kill -0 $pid 2>/dev/null) || return `wait $pid` |
| 44 | 43 |
| 45 echo command \"$@\" has timed out >&2 | 44 echo command \"$@\" has timed out >&2 |
| 46 kill $pid | 45 kill $pid |
| 47 return 1 | 46 return 1 |
| 48 } | 47 } |
| 49 | 48 |
| 50 # Usage: run_and_ignore_error user action | 49 # Usage: run_and_ignore_error [--login] user program [args...] |
| 51 # Carries out the specified action, ignoring any errors. | 50 # --login: |
| 52 # action: | 51 # Run program in a clean login shell. This requires backgrounding, since |
| 53 # --start is handled specially using the user-session wrapper to start a | 52 # the user's .profile or .login script might be run, which might contain |
| 54 # clean log-in session. In any other case, the host script is called through | 53 # blocking commands. |
| 55 # sudo with the specified action flag. | |
| 56 run_and_ignore_error() { | 54 run_and_ignore_error() { |
| 57 user="$1" | 55 login_options="" |
| 58 action="$2" | 56 if [ "$1" = "--login" ]; then |
| 57 login_options="-b -i" |
| 58 shift |
| 59 fi |
| 60 |
| 61 user=$1 |
| 62 shift |
| 59 | 63 |
| 60 set +e | 64 set +e |
| 61 if [ "$action" = "--start" ]; then | 65 sudo -u "$user" $login_options "$@" |
| 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 $1 --start | 70 run_and_ignore_error --login $1 "$HOST_PATH" --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 --stop | 76 run_with_timeout run_and_ignore_error $1 "$HOST_PATH" --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 --reload | 82 run_and_ignore_error $1 "$HOST_PATH" --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 --stop | 88 run_and_ignore_error $1 "$HOST_PATH" --stop |
| 89 run_and_ignore_error $1 --start | 89 run_and_ignore_error --login $1 "$HOST_PATH" --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 |