Skip to content

Commit edf9130

Browse files
rancher-sy-botniusmallnan
authored andcommitted
Embed subscriber service
1 parent 204f889 commit edf9130

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

config/schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ var schema = `{
101101
"properties": {
102102
"url": {"type": "string"},
103103
"image": {"type": "string"},
104-
"rollback": {"type": "string"}
104+
"rollback": {"type": "string"},
105+
"policy": {"type": "string"}
105106
}
106107
},
107108

config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ type UpgradeConfig struct {
158158
URL string `yaml:"url,omitempty"`
159159
Image string `yaml:"image,omitempty"`
160160
Rollback string `yaml:"rollback,omitempty"`
161+
Policy string `yaml:"policy,omitempty"`
161162
}
162163

163164
type EngineOpts struct {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -e -x
3+
4+
gateway_address="http://ros.rancher.io/gateway"
5+
6+
_sigProcess() {
7+
echo "SIGINT/SIGTERM signal..."
8+
kill -9 $$
9+
}
10+
11+
trap _sigProcess SIGINT SIGKILL SIGTERM
12+
13+
__read_policy() {
14+
policy=`ros c get rancher.upgrade.policy`
15+
if [ -z $policy ]; then
16+
echo "can not read upgrade.policy"
17+
exit 1
18+
fi
19+
return $(($policy))
20+
}
21+
22+
__report_activity() {
23+
arch=`uname -m`
24+
uuid=`cat /sys/class/dmi/id/product_uuid`
25+
release=`ros -v | awk '{print $2}'`
26+
response=`wget --server-response ${gateway_address}/report --header 'Accept: application/json' --header 'Content-type: application/json' --header "arch: $arch" --header "uuid: $uuid" --header "release: $release" 2>&1 | awk '/^ HTTP/{print $2}'`
27+
if [ $response -ge 200 -a $response -le 300 ]; then
28+
echo "report activity success"
29+
else
30+
echo "report activity failed"
31+
fi
32+
}
33+
34+
__upgrade_operate() {
35+
recommend_version=`wget ${gateway_address}/version -q -O -`
36+
case $policy in
37+
download)
38+
echo "upgrade.policy is 'download'"
39+
__report_activity
40+
system-docker pull $recommend_version
41+
;;
42+
auto)
43+
echo "upgrade.policy is 'auto'"
44+
__report_activity
45+
ros os upgrade -i $recommend_version -f
46+
;;
47+
none)
48+
echo "upgrade.policy is 'none'"
49+
;;
50+
*)
51+
echo "upgrade.policy is 'illegal'"
52+
;;
53+
esac
54+
}
55+
56+
__read_policy
57+
58+
__upgrade_operate

os-config.tpl.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ rancher:
381381
volumes:
382382
- /sys:/host/sys
383383
- /var/lib/system-docker:/var/lib/system-docker:shared
384+
subscriber:
385+
image: {{.OS_REPO}}/os-base:{{.VERSION}}{{.SUFFIX}}
386+
command: os-subscriber
387+
environment:
388+
- IN_DOCKER=true
389+
labels:
390+
io.rancher.os.scope: system
391+
io.rancher.os.after: console
392+
cron.schedule: "0 0 3 * * ?"
393+
privileged: true
394+
pid: host
395+
ipc: host
396+
net: host
397+
uts: host
398+
volumes_from:
399+
- command-volumes
400+
- system-volumes
401+
volumes:
402+
- /sys:/host/sys
384403
system_docker:
385404
exec: true
386405
storage_driver: overlay2
@@ -399,6 +418,7 @@ rancher:
399418
upgrade:
400419
url: {{.OS_RELEASES_YML}}/releases{{.SUFFIX}}.yml
401420
image: {{.OS_REPO}}/os
421+
policy: download
402422
docker:
403423
{{if eq "amd64" .ARCH -}}
404424
engine: {{.USER_DOCKER_ENGINE_VERSION}}

0 commit comments

Comments
 (0)