forked from sailoog/openplotter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup
More file actions
executable file
·583 lines (503 loc) · 21.9 KB
/
startup
File metadata and controls
executable file
·583 lines (503 loc) · 21.9 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#!/usr/bin/python
# This file is part of Openplotter.
# Copyright (C) 2015 by sailoog <https://github.com/sailoog/openplotter>
# e-sailing <https://github.com/e-sailing/openplotter>
# Openplotter 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, either version 2 of the License, or
# any later version.
# Openplotter 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 Openplotter. If not, see <http://www.gnu.org/licenses/>.
import wx, subprocess, time, os, threading, sys, platform, requests, ConfigParser, io, re, ujson
from shutil import copyfile
from classes.conf import Conf
from classes.language import Language
from classes.SK_settings import SK_settings
from classes.opencpnSettings import opencpnSettings
class MyFrame(wx.Frame):
def __init__(self):
self.conf = Conf()
self.home = self.conf.home
self.op_folder = self.conf.op_folder
self.conf_folder = self.conf.conf_folder
try:
sk_defaults_file = self.home+'/.signalk/defaults.json'
if os.path.isfile(sk_defaults_file):
with open(sk_defaults_file) as data_file:
data = ujson.load(data_file)
if 'vessels' in data:
if 'self' in data['vessels']:
if 'uuid' in data['vessels']['self']:
if data['vessels']['self']['uuid'] == 'urn:mrn:signalk:uuid:00000000-0000-0000-0000-000000000000':
data['vessels']['self']['uuid'] = 'urn:mrn:signalk:uuid:'+subprocess.check_output('uuid')
data2 = ujson.dumps(data, indent=4, sort_keys=True)
try:
with open(sk_defaults_file, 'w') as defile:
data2.write(defile)
except: pass
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.service'])
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.socket'])
subprocess.call(['sudo', 'systemctl', 'start', 'signalk.socket'])
subprocess.call(['sudo', 'systemctl', 'start', 'signalk.service'])
else: print 'Error: file ~/.signalk/defaults.json does not exist'
except: pass
try:
private_unit_file_path = self.conf_folder+'/private_unit.json'
if not os.path.isfile(private_unit_file_path):
copyfile(self.op_folder+'/classes/private_unit.json', private_unit_file_path)
except: pass
try:
if not os.path.exists(self.conf_folder+'/tools/demo_tool'):
os.makedirs(self.conf_folder+'/tools/demo_tool')
demo_tool_file_path = self.conf_folder+'/tools/demo_tool/demo_tool.py'
if not os.path.isfile(demo_tool_file_path):
copyfile(self.op_folder+'/tools/demo_tool/demo_tool.py', demo_tool_file_path)
readme_tool_file_path = self.conf_folder+'/tools/README.md'
if not os.path.isfile(readme_tool_file_path):
copyfile(self.op_folder+'/tools/README.md', readme_tool_file_path)
except: pass
try:
if not os.path.exists(self.conf_folder+'/tools'):
os.makedirs(self.conf_folder+'/tools')
analog_file_path = self.conf_folder+'/tools/openplotter_analog.conf'
if not os.path.isfile(analog_file_path):
copyfile(self.op_folder+'/tools/openplotter_analog.conf', analog_file_path)
install_analog_file_path = self.conf_folder+'/tools/install_analog.txt'
if not os.path.isfile(install_analog_file_path):
copyfile(self.op_folder+'/tools/install_analog.txt', install_analog_file_path)
except: pass
Language(self.conf)
self.ttimer=100
self.logger_data=''
self.warnings_data=''
self.warnings_flag=False
self.autoclose=0
wx.Frame.__init__(self, None, title=_('Starting OpenPlotter'), style=wx.STAY_ON_TOP, size=(650,435))
self.Bind(wx.EVT_CLOSE, self.OnClose)
panel = wx.Panel(self, wx.ID_ANY)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.refresh, self.timer)
self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.icon = wx.Icon(self.op_folder+'/static/icons/openplotter.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
self.logger = wx.TextCtrl(panel, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP|wx.LC_SORT_ASCENDING)
self.warnings = wx.TextCtrl(panel, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP|wx.LC_SORT_ASCENDING|wx.TE_RICH)
self.warnings.SetForegroundColour(wx.RED)
self.button_close =wx.Button(panel, label=_('Close'), pos=(555, 160))
self.button_close.Bind(wx.EVT_BUTTON, self.OnClose_button)
self.button_close.Disable()
htextbox = wx.BoxSizer(wx.HORIZONTAL)
htextbox.Add(self.logger, 1, wx.ALL|wx.EXPAND, 5)
hwarnbox = wx.BoxSizer(wx.HORIZONTAL)
hwarnbox.Add(self.warnings, 1, wx.ALL|wx.EXPAND, 5)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.button_close, 0, wx.RIGHT|wx.LEFT, 5)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(htextbox, 1, wx.ALL|wx.EXPAND, 0)
vbox.Add(hwarnbox, 1, wx.ALL|wx.EXPAND, 0)
vbox.Add(hbox, 0, wx.ALL|wx.EXPAND, 0)
panel.SetSizer(vbox)
self.CreateStatusBar()
font_statusBar = self.GetStatusBar().GetFont()
font_statusBar.SetWeight(wx.BOLD)
self.GetStatusBar().SetFont(font_statusBar)
self.SetStatusText(_('Starting OpenPlotter. Please wait for all services to start.'))
self.Centre()
self.Show(True)
self.thread1=threading.Thread(target=self.starting)
if not self.thread1.isAlive(): self.thread1.start()
self.timer.Start(self.ttimer)
def refresh(self,event):
if self.logger_data:
self.logger.AppendText(self.logger_data)
self.logger_data=''
if self.warnings_data:
self.warnings_flag=True
self.warnings.AppendText(self.warnings_data)
self.warnings_data=''
if self.autoclose>0:
if self.autoclose<time.time():
self.destroy_window()
if not self.thread1.isAlive():
if not self.warnings_flag: self.destroy_window()
else:
self.button_close.Enable()
self.GetStatusBar().SetForegroundColour(wx.RED)
self.SetStatusText(_('There are some warnings. Please close this window and check your system.'))
def add_logger_data(self, msg):
while self.logger_data:
time.sleep(0.1)
self.logger_data=msg
def add_warnings_data(self, msg):
while self.warnings_data:
time.sleep(0.1)
self.warnings_data=msg
def starting(self):
delay=float(self.conf.get('STARTUP', 'delay'))
screensaver=self.conf.get('STARTUP', 'screensaver')
opencpn=self.conf.get('STARTUP', 'opencpn')
opencpn_no=self.conf.get('STARTUP', 'opencpn_no_opengl')
opencpn_fullscreen=self.conf.get('STARTUP', 'opencpn_fullscreen')
play=self.conf.get('STARTUP', 'play')
sound=self.conf.get('STARTUP', 'sound')
d800x480=self.conf.get('STARTUP', '800x480')
ais_enable = self.conf.get('AIS-SDR', 'enable')
ppm = self.conf.get('AIS-SDR', 'ppm')
pypilot_mode = self.conf.get('PYPILOT', 'mode')
webapp = self.conf.get('PYPILOT', 'webapp')
webapp_port = self.conf.get('PYPILOT', 'webapp_port')
N2K_output=self.conf.get('N2K', 'output')
i2c = self.conf.get('I2C', 'sensors')
onewire = self.conf.get('1W', 'ds18b20')
spi = self.conf.get('SPI', 'mcp')
tools_py=[]
if self.conf.has_section('TOOLS'):
if self.conf.has_option('TOOLS', 'py'):
data=self.conf.get('TOOLS', 'py')
try:
temp_list=eval(data)
except:temp_list=[]
if type(temp_list) is list: pass
else: temp_list=[]
for ii in temp_list:
tools_py.append(ii)
#######################################################
subprocess.call(['pkill', '-f', '/openplotter/openplotter'])
#TODO cada vegada comprovem que existeixen tots els nodes de les credencials
######################################
try:
out = subprocess.check_output(['more','product'],cwd='/proc/device-tree/hat')
except: pass
else:
if 'Moitessier' in out:
self.add_logger_data(_('\nChecking Moitessier HAT setup...'))
if not os.path.isfile(self.home+'/moitessier/app/moitessier_ctrl/moitessier_ctrl'):
self.add_warnings_data(_('\n\nMoitessier HAT package is not installed!'))
self.add_logger_data(_(' See warning.'))
else:
package = subprocess.check_output(['dpkg','-s','moitessier'])
kernel = subprocess.check_output(['uname','-r'])
kernel = kernel.split('-')
kernel = kernel[0]
package = package.split('\n')
for i in package:
if 'Version:' in i:
version = i.split(':')
version = version[1]
version = version.strip()
version = version.split('-')
version = version[2]
if kernel != version:
self.add_warnings_data(_('\n\nThe installed Moitessier HAT package does not match the kernel version.'))
self.add_logger_data(_(' See warning.'))
else: self.add_logger_data(_(' Done.'))
######################################
if platform.machine()[0:3]=='arm':
self.add_logger_data(_('\nChecking pi password...'))
out = subprocess.check_output(['sudo', '-n', 'grep', '-E', '^pi:', '/etc/shadow'])
tmp = out.split(':')
passw_a = tmp[1]
tmp = passw_a.split('$')
salt = tmp[2]
passw_b = subprocess.check_output(['mkpasswd', '-msha-512', 'raspberry', salt])
if passw_a.rstrip() == passw_b.rstrip():
self.add_warnings_data(_('\n\nSecurity warning: You are using the default password for "pi" user (raspberry).\nPlease change password in Menu > Preferences > Raspberry Pi Configuration.'))
self.add_logger_data(_(' See warning.'))
else: self.add_logger_data(_(' Done.'))
######################################
wifi_default = self.conf_folder + '/Network/default'
if not os.path.isdir(wifi_default):
self.add_logger_data(_('\nChecking WIFI Access Point password...'))
wifi_pass = ''
try:
hostapd = open('/etc/hostapd/hostapd.conf', 'r')
data = hostapd.read()
hostapd.close()
i=data.find("wpa_passphrase")
if i>=0:
j=data[i:].find("\n")
if j==0:j=data[i:].length
line = data[i:i+j]
sline = line.split('=')
if len(sline)>1:
wifi_pass=sline[1]
except: pass
if wifi_pass == '12345678':
self.add_warnings_data(_('\n\nSecurity warning: You are using the default WIFI Access Point password.\nPlease change password in OpenPlotter > Network.'))
self.add_logger_data(_(' See warning.'))
else:
self.add_logger_data(_(' Done.'))
######################################
if screensaver == '1':
subprocess.call(['xset', 's', 'noblank'])
subprocess.call(['xset', 's', 'off'])
subprocess.call(['xset', '-dpms'])
self.add_logger_data(_('\nScreen saver disabled.').decode('utf8'))
else:
subprocess.call(['xset', 's', 'blank'])
subprocess.call(['xset', 's', 'on'])
subprocess.call(['xset', '+dpms'])
self.add_logger_data(_('\nScreen saver enabled.').decode('utf8'))
######################################
if delay!=0:
self.add_logger_data(_('\nApplying ').decode('utf8')+str(delay)+_(' seconds of delay...').decode('utf8'))
time.sleep(delay)
self.add_logger_data(_(' Done.'))
######################################
subprocess.call(['pkill', '-f', 'diagnostic-N2K-output.py'])
subprocess.call(['pkill', '-f', 'diagnostic-N2K-input.py'])
subprocess.call(['pkill', '-f', 'N2K-server_d.py'])
subprocess.call(['pkill', '-f', 'SK-base_d.py'])
if N2K_output == '1':
self.add_logger_data(_('\nStarting N2K server...'))
subprocess.Popen(['python', self.op_folder+'/N2K-server_d.py'])
self.check_start('N2K-server_d.py')
self.add_logger_data(_('\nStarting N2K generator...'))
subprocess.Popen(['python', self.op_folder+'/SK-base_d.py'])
self.check_start('SK-base_d.py')
######################################
subprocess.call(['pkill', '-f', 'read_sensors_d.py'])
spiEnabled = False
try:
temp_list = eval(spi)
except:
temp_list = []
for i in temp_list:
if i[0] == 1: spiEnabled = True
if i2c: i2c = eval(i2c)
if spiEnabled or i2c or pypilot_mode == 'imu' or pypilot_mode == 'basic autopilot':
self.add_logger_data(_('\nStarting I2C, SPI or pypilot sensors...'))
subprocess.Popen(['python', self.op_folder+'/read_sensors_d.py'], cwd=self.home + '/.pypilot')
self.check_start('read_sensors_d.py')
######################################
subprocess.call(['pkill', '-f', 'pypilot_webapp'])
if webapp == '1' and pypilot_mode == 'basic autopilot':
self.add_logger_data(_('\nStarting pypilot Web App...'))
try: subprocess.Popen(['pypilot_webapp', webapp_port])
except: pass
self.check_start('pypilot_webapp')
######################################
subprocess.call(['pkill', '-f', '1w_d.py'])
if onewire: onewire = eval(onewire)
if onewire:
self.add_logger_data(_('\nStarting 1W sensors...'))
subprocess.Popen(['python', self.op_folder+'/1w_d.py'])
self.check_start('1w_d.py')
######################################
subprocess.call(['pkill', '-15', 'rtl_ais'])
subprocess.call(['pkill', '-f', 'SDR_AIS_fine_cal.py'])
subprocess.call(['pkill', '-15', 'rtl_test'])
subprocess.call(['pkill', '-15', 'kal'])
subprocess.call(['pkill', '-15', 'gqrx'])
if ais_enable == '1':
self.add_logger_data(_('\nStarting SDR AIS reception...'))
subprocess.Popen(['rtl_ais', '-R', '-p', ppm])
self.check_start('rtl_ais')
######################################
if d800x480 == '1':
self.add_logger_data(_('\nChecking 800x480 display...'))
subprocess.call(['sudo', 'python', self.op_folder+'/display800x480.py'])
self.add_logger_data(_(' Done.'))
######################################
subprocess.call(['pkill', '-15', 'opencpn'])
if opencpn=='1':
self.add_logger_data(_('\nStarting OpenCPN...'))
opencpn_commands = ['opencpn']
if opencpn_no=='1': opencpn_commands.append('-no_opengl')
if opencpn_fullscreen=='1': opencpn_commands.append('-fullscreen')
if len(opencpn_commands)>1: subprocess.Popen(opencpn_commands)
if len(opencpn_commands)==1: subprocess.Popen('opencpn')
self.check_start('opencpn')
######################################
self.add_logger_data(_('\nStarting Tools...'))
index=0
for i in tools_py:
folder = tools_py[index][2]
file = folder+'.py'
if i[3]=='1':
subprocess.call(['pkill', '-9', file])
if os.path.isfile(self.conf_folder+'/tools/'+folder+'/'+file):
subprocess.Popen(['python',self.conf_folder+'/tools/'+folder+'/'+file])
else:
subprocess.Popen(['python',self.op_folder+'/tools/'+folder+'/'+file])
index+=1
self.add_logger_data(_(' Done.'))
######################################
self.add_logger_data(_('\nChecking Signal K connections...'))
self.SK_settings = SK_settings(self.conf)
if self.SK_settings.setSKsettings():
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.service'])
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.socket'])
subprocess.call(['sudo', 'systemctl', 'start', 'signalk.socket'])
subprocess.call(['sudo', 'systemctl', 'start', 'signalk.service'])
self.check_start('signalk-server')
######################################
self.add_logger_data(_('\nChecking OpenCPN connections...'))
self.opencpnSettings = opencpnSettings()
opencpnConnection = self.opencpnSettings.getConnectionState()
if not opencpnConnection:
self.add_warnings_data(_('\n\nThe default OpenCPN connection is missing: input TCP localhost:10110.\nSome features may not work as expected.'))
self.add_logger_data(_(' See warning.'))
elif opencpnConnection == 'disabled':
self.add_warnings_data(_('\n\nThe default OpenCPN connection is disabled: input TCP localhost:10110.\nSome features may not work as expected.'))
self.add_logger_data(_(' See warning.'))
else: self.add_logger_data(_(' Done.'))
######################################
subprocess.call(['pkill', '-f', 'diagnostic-NMEA.py'])
subprocess.call(['pkill', '-f', 'kplex.py'])
subprocess.call(['pkill', '-15', 'kplex'])
startKplex = False
try:
file = open(self.home + '/.kplex.conf', 'r')
data = file.readlines()
file.close()
for item in data:
if re.search('\[*\]', item):
if not '#[' in item: startKplex = True
except: pass
if startKplex:
self.add_logger_data(_('\nStarting kplex...'))
subprocess.Popen('kplex')
self.check_start('kplex')
######################################
self.add_logger_data(_('\nChecking OpenPlotter updates...'))
vl = self.conf.get('GENERAL', 'version')
sl = self.conf.get('GENERAL', 'state')
vl_list = vl.split('.')
local_xxx = int(vl_list[0])
local_oxx = int(vl_list[1])
local_oox = int(vl_list[2])
master_github_repositories = self.conf.get('UPDATE', 'master_github_repositories')
stable_branch = self.conf.get('UPDATE', 'stable_branch')
beta_branch = self.conf.get('UPDATE', 'beta_branch')
try:
r_stable = requests.get('https://raw.githubusercontent.com/'+master_github_repositories+'/openplotter/'+stable_branch+'/openplotter.conf')
r_beta = requests.get('https://raw.githubusercontent.com/'+master_github_repositories+'/openplotter/'+beta_branch+'/openplotter.conf')
except:
self.add_logger_data(_(' It was not possible to connect to Github.'))
else:
try:
data_conf = ConfigParser.SafeConfigParser()
data_conf.readfp(io.StringIO(r_stable.text))
vr = data_conf.get('GENERAL','version')
sr = data_conf.get('GENERAL','state')
vr_list = vr.split('.')
remote_xxx = int(vr_list[0])
remote_oxx = int(vr_list[1])
remote_oox = int(vr_list[2])
except:
self.add_logger_data(_(' Error reading versions.'))
else:
check_beta = True
if remote_xxx > local_xxx: check_beta = False
elif remote_xxx == local_xxx and remote_oxx > local_oxx: check_beta = False
elif remote_xxx == local_xxx and remote_oxx == local_oxx and remote_oox > local_oox: check_beta = False
if check_beta:
try:
data_conf = ConfigParser.SafeConfigParser()
data_conf.readfp(io.StringIO(r_beta.text))
vr = data_conf.get('GENERAL','version')
sr = data_conf.get('GENERAL','state')
vr_list = vr.split('.')
#print vr_list
remote_xxx = int(vr_list[0])
remote_oxx = int(vr_list[1])
remote_oox = int(vr_list[2])
#print 'remote '+str(remote_xxx)
#print 'local '+str(local_xxx)
except:
self.add_logger_data(_(' Error reading versions.'))
if sr == 'stable': branch = stable_branch
else: branch = beta_branch
if remote_xxx > local_xxx:
self.add_logger_data(_(' Done.'))
self.add_warnings_data(_('\n\nThere is a major Raspbian upgrade, you have to download\nthe new OpenPlotter image: v').decode('utf8')+str(remote_xxx)+'.x.x '+sr+'.')
self.add_warnings_data(_('\nSee CHANGELOG:'))
self.add_warnings_data('\nhttps://raw.githubusercontent.com/'+master_github_repositories+'/openplotter/'+branch+'/CHANGELOG.md\n')
elif remote_xxx == local_xxx and remote_oxx > local_oxx:
self.add_logger_data(_(' Done.'))
self.add_warnings_data(_('\n\nThere is a major OpenPlotter update: ').decode('utf8')+vl+' '+sl+' --> '+vr+' '+sr+'.')
self.add_warnings_data(_('\nSee CHANGELOG:'))
self.add_warnings_data('\nhttps://raw.githubusercontent.com/'+master_github_repositories+'/openplotter/'+branch+'/CHANGELOG.md\n')
elif remote_xxx == local_xxx and remote_oxx == local_oxx and remote_oox > local_oox:
self.add_logger_data(_(' Done.'))
self.add_warnings_data(_('\n\nThere is a minor OpenPlotter update: ').decode('utf8')+vl+' '+sl+' --> '+vr+' '+sr+'.')
self.add_warnings_data(_('\nSee CHANGELOG:'))
self.add_warnings_data('\nhttps://raw.githubusercontent.com/'+master_github_repositories+'/openplotter/'+branch+'/CHANGELOG.md\n')
else:
self.add_logger_data(' OpenPlotter '+vl+' '+sl+_(' is up to date.').decode('utf8'))
######################################
subprocess.call(['pkill', '-9', 'omxplayer'])
if play == '1':
if sound: subprocess.Popen(['omxplayer', sound])
######################################
self.autoclose=time.time() + 60
def OnClose(self, event):
pass
def OnClose_button(self, event):
self.destroy_window()
def destroy_window(self):
self.timer.Stop()
self.Destroy()
def check_start(self,process):
time.sleep(2)
if util_process_exist(process):
self.add_logger_data(_(' Done.'))
else:
self.add_logger_data(_(' Not Started.'))
def util_process_exist(process_name):
pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
exist = False
for pid in pids:
try:
if process_name in open(os.path.join('/proc', pid, 'cmdline'), 'rb').read():
exist = True
except IOError: # proc has already terminated
continue
return exist
def print_help():
print('This is a part of OpenPlotter software')
print('It starts all needed server/services/background processes')
print('Options are:')
print('startup start (does only run on X display desktop)')
print('startup restart (does only run on X display desktop)')
print('startup stop')
print('this: startup -h')
if len(sys.argv)>1:
if sys.argv[1]=='stop':
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.service'])
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.socket'])
subprocess.call(['pkill', '-15', 'opencpn'])
subprocess.call(['pkill', '-15', 'kplex'])
#SDR
subprocess.call(['pkill', '-15', 'rtl_ais'])
subprocess.call(['pkill', '-f', 'SDR_AIS_fine_cal.py'])
subprocess.call(['pkill', '-15', 'rtl_test'])
subprocess.call(['pkill', '-15', 'kal'])
subprocess.call(['pkill', '-15', 'gqrx'])
subprocess.call(['pkill', '-f', '1w_d.py'])
subprocess.call(['pkill', '-f', 'read_sensors_d.py'])
subprocess.call(['pkill', '-f', 'pypilot_webapp'])
subprocess.call(['pkill', '-f', 'SK-base_d.py'])
subprocess.call(['pkill', '-f', 'N2K-server_d.py'])
subprocess.call(['pkill', '-f', '/openplotter/openplotter'])
subprocess.call(['killall', 'diagnostic-'])
elif sys.argv[1]=='restart':
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.service'])
subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.socket'])
subprocess.call(['sudo', 'systemctl', 'start', 'signalk.socket'])
subprocess.call(['sudo', 'systemctl', 'start', 'signalk.service'])
app = wx.App()
MyFrame().Show()
app.MainLoop()
elif sys.argv[1]=='start':
app = wx.App()
MyFrame().Show()
app.MainLoop()
elif sys.argv[1]=='-h': print_help()
else: print_help()