mirror of
https://github.com/openplotter/openplotter-maiana.git
synced 2025-05-16 07:00:17 -07:00
make service openplotter managed
This commit is contained in:
parent
c9b3e94e29
commit
1aaffe8fda
@ -27,6 +27,12 @@ def main():
|
|||||||
package = 'openplotter-maiana'
|
package = 'openplotter-maiana'
|
||||||
language.Language(currentdir, package, currentLanguage)
|
language.Language(currentdir, package, currentLanguage)
|
||||||
|
|
||||||
|
print(_('Installing python packages...'))
|
||||||
|
try:
|
||||||
|
subprocess.call(['pip3', 'install', 'websocket-client', '-U'])
|
||||||
|
print(_('DONE'))
|
||||||
|
except Exception as e: print(_('FAILED: ')+str(e))
|
||||||
|
|
||||||
print(_('Checking access to Signal K server...'))
|
print(_('Checking access to Signal K server...'))
|
||||||
try:
|
try:
|
||||||
from openplotterSignalkInstaller import connections
|
from openplotterSignalkInstaller import connections
|
||||||
@ -36,16 +42,6 @@ def main():
|
|||||||
else: print(_('DONE'))
|
else: print(_('DONE'))
|
||||||
except Exception as e: print(_('FAILED: ')+str(e))
|
except Exception as e: print(_('FAILED: ')+str(e))
|
||||||
|
|
||||||
#TODO switch from service to startup
|
|
||||||
print(_('Adding openplotter-maiana-read service...'))
|
|
||||||
try:
|
|
||||||
fo = open('/etc/systemd/system/openplotter-maiana-read.service', "w")
|
|
||||||
fo.write( '[Service]\nExecStart=openplotter-maiana-read\nStandardOutput=syslog\nStandardError=syslog\nUser='+conf2.user+'\nRestart=always\nRestartSec=5\n\n[Install]\nWantedBy=multi-user.target')
|
|
||||||
fo.close()
|
|
||||||
subprocess.call(['systemctl', 'daemon-reload'])
|
|
||||||
print(_('DONE'))
|
|
||||||
except Exception as e: print(_('FAILED: ')+str(e))
|
|
||||||
|
|
||||||
print(_('Setting version...'))
|
print(_('Setting version...'))
|
||||||
try:
|
try:
|
||||||
conf2.set('APPS', 'maiana', version)
|
conf2.set('APPS', 'maiana', version)
|
||||||
|
@ -26,13 +26,9 @@ def main():
|
|||||||
package = 'openplotter-maiana'
|
package = 'openplotter-maiana'
|
||||||
language.Language(currentdir, package, currentLanguage)
|
language.Language(currentdir, package, currentLanguage)
|
||||||
|
|
||||||
#TODO switch from service to startup
|
print(_('Stopping OpenPlotter MAIANA service...'))
|
||||||
print(_('Removing openplotter-maiana-read service...'))
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(['systemctl', 'disable', 'openplotter-maiana-read'])
|
subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
||||||
subprocess.call(['systemctl', 'stop', 'openplotter-maiana-read'])
|
|
||||||
subprocess.call(['rm', '-f', '/etc/systemd/system/openplotter-maiana-read.service'])
|
|
||||||
subprocess.call(['systemctl', 'daemon-reload'])
|
|
||||||
print(_('DONE'))
|
print(_('DONE'))
|
||||||
except Exception as e: print(_('FAILED: ')+str(e))
|
except Exception as e: print(_('FAILED: ')+str(e))
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#TODO add tx action
|
#TODO add tx action
|
||||||
#TODO parse bin file
|
#TODO parse bin file
|
||||||
|
|
||||||
import wx, os, webbrowser, subprocess, time, datetime, ujson, serial, requests, re
|
import wx, os, webbrowser, subprocess, time, datetime, ujson, serial, requests, re, sys
|
||||||
import wx.richtext as rt
|
import wx.richtext as rt
|
||||||
from openplotterSettings import conf
|
from openplotterSettings import conf
|
||||||
from openplotterSettings import language
|
from openplotterSettings import language
|
||||||
@ -137,6 +137,11 @@ class MyFrame(wx.Frame):
|
|||||||
url = self.platform.http+'localhost:'+self.platform.skPort+'/admin/#/serverConfiguration/connections/-'
|
url = self.platform.http+'localhost:'+self.platform.skPort+'/admin/#/serverConfiguration/connections/-'
|
||||||
webbrowser.open(url, new=2)
|
webbrowser.open(url, new=2)
|
||||||
|
|
||||||
|
def restartRead(self):
|
||||||
|
subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
||||||
|
subprocess.Popen('openplotter-maiana-read')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def onRead(self):
|
def onRead(self):
|
||||||
self.ShowStatusBarYELLOW(_('Reading MAIANA device settings...'))
|
self.ShowStatusBarYELLOW(_('Reading MAIANA device settings...'))
|
||||||
self.mmsi.SetValue('')
|
self.mmsi.SetValue('')
|
||||||
@ -217,6 +222,15 @@ class MyFrame(wx.Frame):
|
|||||||
self.SKconn.SetValue(self.connInit)
|
self.SKconn.SetValue(self.connInit)
|
||||||
self.ShowStatusBarRED(_('Select the Signal K connection for the MAIANA device'))
|
self.ShowStatusBarRED(_('Select the Signal K connection for the MAIANA device'))
|
||||||
|
|
||||||
|
if deviceOld != self.device:
|
||||||
|
if self.device: self.restartRead()
|
||||||
|
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
||||||
|
else:
|
||||||
|
if self.device:
|
||||||
|
test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding)
|
||||||
|
if not 'openplotter-maiana-read' in test: self.restartRead()
|
||||||
|
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
||||||
|
|
||||||
if self.device:
|
if self.device:
|
||||||
ser = serial.Serial(self.device, 38400)
|
ser = serial.Serial(self.device, 38400)
|
||||||
ser.write('sys?\r\n'.encode("utf-8"))
|
ser.write('sys?\r\n'.encode("utf-8"))
|
||||||
@ -235,6 +249,7 @@ class MyFrame(wx.Frame):
|
|||||||
ts2 = time.mktime(datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%fZ").timetuple())
|
ts2 = time.mktime(datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%fZ").timetuple())
|
||||||
if ts - ts2 > 3:
|
if ts - ts2 > 3:
|
||||||
self.ShowStatusBarRED(_('Cannot connect with the device, try again'))
|
self.ShowStatusBarRED(_('Cannot connect with the device, try again'))
|
||||||
|
print('#############################')
|
||||||
return
|
return
|
||||||
hardwareRevision = data['hardwareRevision']['value']
|
hardwareRevision = data['hardwareRevision']['value']
|
||||||
hardwareRevision = hardwareRevision.split('.')
|
hardwareRevision = hardwareRevision.split('.')
|
||||||
@ -391,17 +406,6 @@ class MyFrame(wx.Frame):
|
|||||||
if 'bowOffset' in data['station']: self.bowOffset.SetValue(str(data['station']['bowOffset']['value']))
|
if 'bowOffset' in data['station']: self.bowOffset.SetValue(str(data['station']['bowOffset']['value']))
|
||||||
if 'portOffset' in data['station']: self.portOffset.SetValue(str(data['station']['portOffset']['value']))
|
if 'portOffset' in data['station']: self.portOffset.SetValue(str(data['station']['portOffset']['value']))
|
||||||
|
|
||||||
if deviceOld != self.device:
|
|
||||||
if self.device:
|
|
||||||
subprocess.Popen([self.platform.admin, 'python3', self.currentdir+'/service.py', 'openplotter-maiana-read', 'restart'])
|
|
||||||
else:
|
|
||||||
subprocess.Popen([self.platform.admin, 'python3', self.currentdir+'/service.py', 'openplotter-maiana-read', 'stop'])
|
|
||||||
else:
|
|
||||||
if self.device:
|
|
||||||
try:
|
|
||||||
subprocess.check_output(['systemctl', 'is-active', 'openplotter-maiana-read']).decode(sys.stdin.encoding)
|
|
||||||
except:
|
|
||||||
subprocess.Popen([self.platform.admin, 'python3', self.currentdir+'/service.py', 'openplotter-maiana-read', 'restart'])
|
|
||||||
|
|
||||||
def onSKconn(self, event):
|
def onSKconn(self, event):
|
||||||
deviceOld = self.conf.get('MAIANA', 'device')
|
deviceOld = self.conf.get('MAIANA', 'device')
|
||||||
@ -426,18 +430,14 @@ class MyFrame(wx.Frame):
|
|||||||
self.conf.set('MAIANA', 'device', self.device)
|
self.conf.set('MAIANA', 'device', self.device)
|
||||||
except: pass
|
except: pass
|
||||||
if deviceOld != self.device:
|
if deviceOld != self.device:
|
||||||
if self.device:
|
if self.device: self.restartRead()
|
||||||
subprocess.Popen([self.platform.admin, 'python3', self.currentdir+'/service.py', 'openplotter-maiana-read', 'restart'])
|
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
subprocess.Popen([self.platform.admin, 'python3', self.currentdir+'/service.py', 'openplotter-maiana-read', 'stop'])
|
|
||||||
else:
|
else:
|
||||||
if self.device:
|
if self.device:
|
||||||
try:
|
test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding)
|
||||||
subprocess.check_output(['systemctl', 'is-active', 'openplotter-maiana-read']).decode(sys.stdin.encoding)
|
if not 'openplotter-maiana-read' in test: self.restartRead()
|
||||||
except:
|
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
||||||
subprocess.Popen([self.platform.admin, 'python3', self.currentdir+'/service.py', 'openplotter-maiana-read', 'restart'])
|
|
||||||
time.sleep(1)
|
|
||||||
self.onRead()
|
self.onRead()
|
||||||
|
|
||||||
def pageSettings(self):
|
def pageSettings(self):
|
||||||
|
@ -37,7 +37,6 @@ def main():
|
|||||||
sock = False
|
sock = False
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
#TODO switch from service to startup
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
server_address = ('localhost', 10110)
|
server_address = ('localhost', 10110)
|
||||||
sock.connect(server_address)
|
sock.connect(server_address)
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# This file is part of Openplotter.
|
|
||||||
# Copyright (C) 2021 by Sailoog <https://github.com/openplotter/openplotter-maiana>
|
|
||||||
#
|
|
||||||
# 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 sys, subprocess
|
|
||||||
|
|
||||||
#TODO remove
|
|
||||||
|
|
||||||
if sys.argv[1]=='openplotter-maiana-read':
|
|
||||||
if sys.argv[2]=='start':
|
|
||||||
subprocess.call(['systemctl', 'enable', 'openplotter-maiana-read'])
|
|
||||||
subprocess.call(['systemctl', 'start', 'openplotter-maiana-read'])
|
|
||||||
if sys.argv[2]=='stop':
|
|
||||||
subprocess.call(['systemctl', 'disable', 'openplotter-maiana-read'])
|
|
||||||
subprocess.call(['systemctl', 'stop', 'openplotter-maiana-read'])
|
|
||||||
if sys.argv[2]=='restart':
|
|
||||||
subprocess.call(['systemctl', 'enable', 'openplotter-maiana-read'])
|
|
||||||
subprocess.call(['systemctl', 'restart', 'openplotter-maiana-read'])
|
|
@ -25,15 +25,17 @@ class Start():
|
|||||||
currentdir = os.path.dirname(os.path.abspath(__file__))
|
currentdir = os.path.dirname(os.path.abspath(__file__))
|
||||||
language.Language(currentdir,'openplotter-maiana',currentLanguage)
|
language.Language(currentdir,'openplotter-maiana',currentLanguage)
|
||||||
|
|
||||||
self.initialMessage = ''
|
self.initialMessage = _('Starting MAIANA transponder...')
|
||||||
|
|
||||||
#TODO run read from here
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
green = ''
|
green = ''
|
||||||
black = ''
|
black = ''
|
||||||
red = ''
|
red = ''
|
||||||
|
|
||||||
|
subprocess.call(['pkill', '-f', 'openplotter-maiana-read'])
|
||||||
|
subprocess.Popen('openplotter-maiana-read')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
return {'green': green,'black': black,'red': red}
|
return {'green': green,'black': black,'red': red}
|
||||||
|
|
||||||
class Check():
|
class Check():
|
||||||
@ -73,27 +75,26 @@ class Check():
|
|||||||
if not green: green = msg
|
if not green: green = msg
|
||||||
else: green+= ' | '+msg
|
else: green+= ' | '+msg
|
||||||
|
|
||||||
#service
|
# check service
|
||||||
|
test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding)
|
||||||
if device and (result[0] == 'approved' or result[0] == 'validated'):
|
if device and (result[0] == 'approved' or result[0] == 'validated'):
|
||||||
try:
|
if 'openplotter-maiana-read' in test:
|
||||||
subprocess.check_output(['systemctl', 'is-active', 'openplotter-maiana-read']).decode(sys.stdin.encoding)
|
msg = _('running')
|
||||||
msg = _('OpenPlotter MAIANA service is running')
|
|
||||||
if not green: green = msg
|
if not green: green = msg
|
||||||
else: green+= ' | '+msg
|
else: green+= ' | '+msg
|
||||||
except:
|
else:
|
||||||
msg = _('OpenPlotter MAIANA service is not running')
|
msg = _('not running')
|
||||||
if not red: red = msg
|
if red: red += '\n '+msg
|
||||||
else: red+= '\n '+msg
|
else: red = msg
|
||||||
else:
|
else:
|
||||||
try:
|
if 'openplotter-maiana-read' in test:
|
||||||
subprocess.check_output(['systemctl', 'is-active', 'openplotter-maiana-read']).decode(sys.stdin.encoding)
|
msg = _('running')
|
||||||
msg = _('OpenPlotter MAIANA service is running')
|
if red: red += '\n '+msg
|
||||||
if not red: red = msg
|
else: red = msg
|
||||||
else: red+= '\n '+msg
|
else:
|
||||||
except:
|
msg = _('not running')
|
||||||
msg = _('OpenPlotter MAIANA service is not running')
|
if not black: black = msg
|
||||||
if not green: green = msg
|
else: black+= ' | '+msg
|
||||||
else: green+= ' | '+msg
|
|
||||||
|
|
||||||
return {'green': green,'black': black,'red': red}
|
return {'green': green,'black': black,'red': red}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user