1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/usr/bin/python3
#
# Copyright 2014 Canonical Ltd.
#
# Author: Tony Espy <espy@canonical.com>
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3.
# touch-reboot-online-test is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Description - this test script is meant to be executed by a post-script
# command in ofono's system upstart job. It reads a current boot number
# from a local file, then attempts to determine if indicator-network is
# running, which rough indicator that the unity has started. It next checks
# the status of the modem. If Online, the status is written to the local
# file boot.#, and the device rebooted. If Offline, the status is written
# to the same file, and the test stops. Note, the upper bounds of the number
# of reboots is hard-coded in the script.
#
#
import subprocess
import time
if __name__ == '__main__':
boot_count = 0
with open('/home/phablet/boot-count', mode='r') as a_file:
boot_count_str = a_file.read()
try:
boot_count = int(boot_count_str)
except ValueError as e:
exit
output_file = '/home/phablet/boot.{0}'.format(boot_count_str)
with open('/home/phablet/boot-count', mode='w') as a_file:
boot_count = boot_count + 1
boot_count_str = str(boot_count)
a_file.write(str(boot_count_str));
while True:
time.sleep(5)
ps = ''
try:
ps = subprocess.check_output('ps -ale | grep indicator-net', shell=True)
except subprocess.CalledProcessError as e:
ps = ''
if ps == '':
continue
online = subprocess.check_output('/usr/share/ofono/scripts/list-modems | grep Online', shell=True)
# online = subprocess.check_output('ls | grep reboot2', shell=True)
print(online)
with open(output_file, mode='w') as out_file:
if online == b' Online = 1\n':
out_file.write('Online')
if boot_count < 100:
subprocess.check_output('reboot')
else:
out_file.write('OFFLINE')
break
exit()
|