Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: bin/cros_copy_upgrade_server.sh

Issue 2724009: Create a remote upgrade server to serve up images as a "proxy devserver". (Closed) Base URL: ssh://gitrw.chromium.org/chromiumos
Patch Set: Moved over to the crosutils.git repository Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/sh
2
3 # Load common constants. This should be the first executable line.
4 # The path to common.sh should be relative to your script's location.
5 . "$(dirname "$0")/common.sh"
6
7 # Flags
8 DEFINE_string upgrade_server "" "SSH-capable host for upgrade server install"
9 DEFINE_string dest_path "" "Directory on host to do install"
10 DEFINE_string client_address "" "IP Address of netbook to update"
11 DEFINE_string server_address "" "IP Address of upgrade server"
12 DEFINE_boolean start_server ${FLAGS_TRUE} "Start up the server"
13 DEFINE_boolean stop_server ${FLAGS_FALSE} "Start up the server"
14 DEFINE_string from "" "Image directory to upload to server"
15
16 # Parse command line
17 FLAGS "$@" || exit 1
18 eval set -- "${FLAGS_ARGV}"
19
20 set -e
21
22 # Make sure dev server argument has been set
23 require_upgrade_server () {
24 if [ -z "${FLAGS_upgrade_server}" ] ; then
25 echo "The --upgrade-server= argument is mandatory"
26 exit 1
27 fi
28 }
29
30 # Make sure a pointer to the latest image has been created
31 require_latest_image () {
32 [ -n "$latest_image" ] && return
33 if [ -n "${FLAGS_from}" ] ; then
34 latest_image=$(readlink -f ${FLAGS_from})
35 else
36 latest_image=$(env CHROMEOS_BUILD_ROOT=${SCRIPTS_DIR}/../build \
37 ${SCRIPTS_DIR}/get_latest_image.sh)
38 fi
39 }
40
41 validate_devserver_path () {
42 if [ $(expr "${FLAGS_dest_path}" : '\.\.') != 0 ]; then
43 echo "Error: --dest_path argument (${FLAGS_dest_path}) must not be relative"
44 exit 1
45 fi
46 FLAGS_dest_path=/tmp/devserver/${FLAGS_dest_path##/tmp/devserver/}
47 }
48
49 # Copy the various bits of the dev server scripts over to our remote host
50 create_devserver () {
51 FLAGS_dest_path=$1
52 validate_devserver_path
53
54 echo "Creating dev server in ${FLAGS_upgrade_server}:${FLAGS_dest_path}..."
55
56 require_upgrade_server
57 # Create new empty directory to hold server components
58 ssh "${FLAGS_upgrade_server}" rm -rf "${FLAGS_dest_path}" || true
59 ssh "${FLAGS_upgrade_server}" mkdir -p "${FLAGS_dest_path}/python"
60
61 # Copy server components into place
62 (cd ${SCRIPTS_DIR}/../.. && \
63 tar zcf - --exclude=.git --exclude=.svn \
64 src/scripts/start_devserver \
65 src/scripts/{common,get_latest_image,mk_memento_images}.sh \
66 src/third_party/shflags src/platform/dev) | \
67 ssh ${FLAGS_upgrade_server} "cd ${FLAGS_dest_path} && tar zxf -"
68
69 # Copy Python web library into place out of the chroot
70 (cd ${SCRIPTS_DIR}/../../chroot/usr/lib/python*/site-packages && \
71 tar zcf - web*) | \
72 ssh ${FLAGS_upgrade_server} "cd ${FLAGS_dest_path}/python && tar zxf -"
73 }
74
75 # Copy the latest image over to archive server
76 create_archive_dir () {
77 archive_dir=$1
78
79 echo "Creating archive dir in ${FLAGS_upgrade_server}:${archive_dir}..."
80
81 require_upgrade_server
82 require_latest_image
83
84 # Copy the latest image into the newly created archive
85 ssh "${FLAGS_upgrade_server}" "mkdir -p ${archive_dir}"
86
87 image_path=${latest_image##*build/}
88
89 (cd ${SCRIPTS_DIR}/../build && tar zcf - ${image_path}) | \
90 ssh ${FLAGS_upgrade_server} "cd ${archive_dir} && tar zxf -"
91
92 # unpack_partitions.sh lies in its hashbang. It really wants bash
93 unpack_script=${archive_dir}/${image_path}/unpack_partitions.sh
94 ssh ${FLAGS_upgrade_server} "sed -e 's/^#!\/bin\/sh/#!\/bin\/bash/' < ${unpack _script} > ${unpack_script}.new && chmod 755 ${unpack_script}.new && mv ${unpack _script}.new ${unpack_script}"
95
96 # Since we are in static-only mode, we need to create a few links
97 for file in update.gz stateful.image.gz ; do
98 ssh ${FLAGS_upgrade_server} "cd ${archive_dir} && ln -sf ${image_path}/$file ."
99 ssh ${FLAGS_upgrade_server} "ln -sf ${archive_dir}/$file ${FLAGS_dest_path}/ src/platform/dev/static"
100 done
101 }
102
103 stop_server () {
104 require_upgrade_server
105 echo "Stopping remote devserver..."
106 echo "(Fast restart using \"$0 --upgrade_server=${FLAGS_upgrade_server} --dest _path=${FLAGS_dest_path} --archive_dir=${archive_dir}\")"
107 ssh ${FLAGS_upgrade_server} pkill -f ${archive_dir} || /bin/true
108 }
109
110 # Start remote server
111 start_server () {
112 require_upgrade_server
113 echo "Starting remote devserver..."
114 server_logfile=/tmp/devserver_log.$$
115 portlist=/tmp/devserver_portlist.$$
116 echo "Server will be logging locally to $server_logfile"
117
118 # Find a TCP listen socket that is not in use
119 ssh ${FLAGS_upgrade_server} "netstat -lnt" | awk '{ print $4 }' > $portlist
120 server_port=8081
121 while grep -q ":${port}$" $portlist; do
122 server_port=$[server_port + 1]
123 done
124 rm -f $portlist
125
126 ssh ${FLAGS_upgrade_server} "cd ${FLAGS_dest_path}/src/scripts && env PYTHONPA TH=${remote_root}${FLAGS_dest_path}/python CHROMEOS_BUILD_ROOT=${archive_dir} ./ start_devserver --archive_dir ${archive_dir} $server_port" > $server_logfile 2>& 1 &
127 server_pid=$!
128
129 trap server_cleanup 2
130
131 # Wait for server to startup
132 while sleep 1; do
133 if fgrep -q 'Serving images from' $server_logfile; then
134 echo "Server is ready"
135 break
136 elif kill -0 ${server_pid}; then
137 continue
138 else
139 echo "Server failed to startup"
140 exit 1
141 fi
142 done
143 }
144
145 server_cleanup () {
146 trap '' 2
147 stop_server
148 exit 0
149 }
150
151 # If destination path wasn't set on command line, create one from scratch
152 if [ -z "${FLAGS_dest_path}" -a ${FLAGS_stop_server} -eq ${FLAGS_FALSE} ] ; then
153 require_latest_image
154 hostname=$(uname -n)
155 hostname=${hostname%%.*}
156 image_name=${latest_image##*/}
157 create_devserver ${hostname}_${image_name}
158 FLAGS_start_server=${FLAGS_TRUE}
159 else
160 validate_devserver_path
161 fi
162
163 if [ ${FLAGS_stop_server} -eq ${FLAGS_FALSE} ] ; then
164 create_archive_dir "${FLAGS_dest_path}/archive"
165 FLAGS_start_server=${FLAGS_TRUE}
166 else
167 archive_dir="${FLAGS_dest_path}/archive"
168 fi
169
170 if [ "${FLAGS_stop_server}" -eq ${FLAGS_TRUE} ] ; then
171 stop_server
172 exit 0
173 fi
174
175 # Make sure old devserver is dead, then restart it
176 if [ "${FLAGS_start_server}" -eq ${FLAGS_TRUE} ] ; then
177 stop_server
178 start_server
179
180 tail -f ${server_logfile} &
181
182 # Now tell the client to load from the server
183 if [ -n "${FLAGS_client_address}" ] ; then
184 if [ -z "${FLAGS_server_address}" ] ; then
185 FLAGS_server_address=${FLAGS_upgrade_server}
186 fi
187 live_args="--update_url=http://${FLAGS_server_address}:${server_port}/update \
188 --remote=${FLAGS_client_address}"
189 echo "Running ${SCRIPTS_DIR}/image_to_live.sh $live_args"
190 ${SCRIPTS_DIR}/image_to_live.sh $live_args &
191 fi
192
193 wait ${server_pid}
194 fi
195
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698