mirror of
https://github.com/openplotter/openplotter-maiana.git
synced 2025-05-19 00:20:10 -07:00
new rescue management
This commit is contained in:
parent
45d95a0a1b
commit
d1775dbdf9
@ -56,6 +56,15 @@ def main():
|
|||||||
print(_('DONE'))
|
print(_('DONE'))
|
||||||
except Exception as e: print(_('FAILED: ')+str(e))
|
except Exception as e: print(_('FAILED: ')+str(e))
|
||||||
|
|
||||||
|
print(_('Creating services...'))
|
||||||
|
try:
|
||||||
|
fo = open('/etc/systemd/system/openplotter-maiana-read.service', "w")
|
||||||
|
fo.write( '[Service]\nEnvironment=OPrescue=0\nEnvironmentFile=/boot/firmware/config.txt\nExecStart=openplotter-maiana-read $OPrescue\nUser='+conf2.user+'\nRestart=always\nRestartSec=3\n\n[Install]\nWantedBy=local-fs.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)
|
||||||
|
@ -28,12 +28,6 @@ def main():
|
|||||||
language.Language(currentdir, package, currentLanguage)
|
language.Language(currentdir, package, currentLanguage)
|
||||||
platform2 = platform.Platform()
|
platform2 = platform.Platform()
|
||||||
|
|
||||||
print(_('Stopping OpenPlotter MAIANA service...'))
|
|
||||||
try:
|
|
||||||
subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
|
||||||
print(_('DONE'))
|
|
||||||
except Exception as e: print(_('FAILED: ')+str(e))
|
|
||||||
|
|
||||||
print(_('Removing connection to Signal K server for MAIANA commands...'))
|
print(_('Removing connection to Signal K server for MAIANA commands...'))
|
||||||
try:
|
try:
|
||||||
data = {}
|
data = {}
|
||||||
@ -57,6 +51,14 @@ def main():
|
|||||||
print(_('DONE'))
|
print(_('DONE'))
|
||||||
except Exception as e: print(_('FAILED: ')+str(e))
|
except Exception as e: print(_('FAILED: ')+str(e))
|
||||||
|
|
||||||
|
print(_('Removing services...'))
|
||||||
|
try:
|
||||||
|
subprocess.call(['systemctl', 'disable', 'openplotter-maiana-read'])
|
||||||
|
subprocess.call(['systemctl', 'stop', 'openplotter-maiana-read'])
|
||||||
|
subprocess.call(['systemctl', 'daemon-reload'])
|
||||||
|
print(_('DONE'))
|
||||||
|
except Exception as e: print(_('FAILED: ')+str(e))
|
||||||
|
|
||||||
print(_('Removing version...'))
|
print(_('Removing version...'))
|
||||||
try:
|
try:
|
||||||
conf2.set('APPS', 'maiana', '')
|
conf2.set('APPS', 'maiana', '')
|
||||||
|
@ -122,8 +122,11 @@ class MyFrame(wx.Frame):
|
|||||||
webbrowser.open(url, new=2)
|
webbrowser.open(url, new=2)
|
||||||
|
|
||||||
def restartRead(self):
|
def restartRead(self):
|
||||||
subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
subprocess.call([self.platform.admin, 'python3', self.currentdir+'/service.py', 'enable'])
|
||||||
subprocess.Popen('openplotter-maiana-read')
|
time.sleep(1)
|
||||||
|
|
||||||
|
def stopRead(self):
|
||||||
|
subprocess.call([self.platform.admin, 'python3', self.currentdir+'/service.py', 'disable'])
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def onRead(self):
|
def onRead(self):
|
||||||
@ -191,12 +194,10 @@ class MyFrame(wx.Frame):
|
|||||||
|
|
||||||
if deviceOld != self.device:
|
if deviceOld != self.device:
|
||||||
if self.device: self.restartRead()
|
if self.device: self.restartRead()
|
||||||
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
else: self.stopRead()
|
||||||
else:
|
else:
|
||||||
if self.device:
|
if self.device: self.restartRead()
|
||||||
test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding)
|
else: self.stopRead()
|
||||||
if not 'openplotter-maiana-read' in test: self.restartRead()
|
|
||||||
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
|
||||||
|
|
||||||
if self.device:
|
if self.device:
|
||||||
self.sock.sendto(b'sys?\r\n',(self.UDP_IP,self.UDP_PORT))
|
self.sock.sendto(b'sys?\r\n',(self.UDP_IP,self.UDP_PORT))
|
||||||
@ -213,7 +214,7 @@ class MyFrame(wx.Frame):
|
|||||||
ts = datetime.datetime.utcnow().timestamp()
|
ts = datetime.datetime.utcnow().timestamp()
|
||||||
timestamp = data['hardwareRevision']['timestamp']
|
timestamp = data['hardwareRevision']['timestamp']
|
||||||
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 > 5:
|
||||||
self.ShowStatusBarRED(_('Cannot connect with the device, try again by pressing "Refresh"'))
|
self.ShowStatusBarRED(_('Cannot connect with the device, try again by pressing "Refresh"'))
|
||||||
return
|
return
|
||||||
hardwareRevision = data['hardwareRevision']['value']
|
hardwareRevision = data['hardwareRevision']['value']
|
||||||
@ -424,12 +425,10 @@ class MyFrame(wx.Frame):
|
|||||||
|
|
||||||
if deviceOld != self.device:
|
if deviceOld != self.device:
|
||||||
if self.device: self.restartRead()
|
if self.device: self.restartRead()
|
||||||
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
else: self.stopRead()
|
||||||
else:
|
else:
|
||||||
if self.device:
|
if self.device: self.restartRead()
|
||||||
test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding)
|
else: self.stopRead()
|
||||||
if not 'openplotter-maiana-read' in test: self.restartRead()
|
|
||||||
else: subprocess.call(['pkill','-f','openplotter-maiana-read'])
|
|
||||||
|
|
||||||
self.onRead()
|
self.onRead()
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
|
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os, socket, time, ssl, json, datetime
|
import os, socket, time, ssl, json, datetime, sys
|
||||||
from openplotterSettings import conf
|
from openplotterSettings import conf
|
||||||
from openplotterSettings import platform
|
from openplotterSettings import platform
|
||||||
from openplotterSettings import language
|
from openplotterSettings import language
|
||||||
@ -23,6 +23,7 @@ from websocket import create_connection
|
|||||||
from openplotterSignalkInstaller import connections
|
from openplotterSignalkInstaller import connections
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if sys.argv[1] != '1':
|
||||||
platform2 = platform.Platform()
|
platform2 = platform.Platform()
|
||||||
conf2 = conf.Conf()
|
conf2 = conf.Conf()
|
||||||
currentdir = os.path.dirname(os.path.abspath(__file__))
|
currentdir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
@ -23,3 +23,10 @@ if sys.argv[1]=='sk':
|
|||||||
subprocess.call(['systemctl', 'stop', 'signalk.socket'])
|
subprocess.call(['systemctl', 'stop', 'signalk.socket'])
|
||||||
subprocess.call(['systemctl', 'start', 'signalk.socket'])
|
subprocess.call(['systemctl', 'start', 'signalk.socket'])
|
||||||
subprocess.call(['systemctl', 'start', 'signalk.service'])
|
subprocess.call(['systemctl', 'start', 'signalk.service'])
|
||||||
|
|
||||||
|
if sys.argv[1]=='enable':
|
||||||
|
subprocess.call(['systemctl', 'restart', 'openplotter-maiana-read.service'])
|
||||||
|
subprocess.call(['systemctl', 'enable', 'openplotter-maiana-read.service'])
|
||||||
|
elif sys.argv[1]=='disable':
|
||||||
|
subprocess.call(['systemctl', 'stop', 'openplotter-maiana-read.service'])
|
||||||
|
subprocess.call(['systemctl', 'disable', 'openplotter-maiana-read.service'])
|
@ -22,21 +22,12 @@ from openplotterSignalkInstaller import connections
|
|||||||
|
|
||||||
class Start():
|
class Start():
|
||||||
def __init__(self, conf, currentLanguage):
|
def __init__(self, conf, currentLanguage):
|
||||||
self.conf = conf
|
self.initialMessage = ''
|
||||||
currentdir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
language.Language(currentdir,'openplotter-maiana',currentLanguage)
|
|
||||||
|
|
||||||
self.initialMessage = _('Starting MAIANA transponder...')
|
|
||||||
|
|
||||||
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():
|
||||||
@ -157,24 +148,25 @@ class Check():
|
|||||||
if not black: black = msg
|
if not black: black = msg
|
||||||
else: black+= ' | '+msg
|
else: black+= ' | '+msg
|
||||||
|
|
||||||
# check service
|
#service
|
||||||
test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding)
|
if device and 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.service']).decode(sys.stdin.encoding)
|
||||||
msg = _('running')
|
msg = _('service running')
|
||||||
if not green: green = msg
|
if not green: green = msg
|
||||||
else: green+= ' | '+msg
|
else: green+= ' | '+msg
|
||||||
else:
|
except:
|
||||||
msg = _('not running')
|
msg = _('service not running')
|
||||||
if red: red += '\n '+msg
|
if red: red += '\n '+msg
|
||||||
else: red = msg
|
else: red = msg
|
||||||
else:
|
else:
|
||||||
if 'openplotter-maiana-read' in test:
|
try:
|
||||||
msg = _('running')
|
subprocess.check_output(['systemctl', 'is-active', 'openplotter-maiana-read.service']).decode(sys.stdin.encoding)
|
||||||
|
msg = _('service running')
|
||||||
if red: red += '\n '+msg
|
if red: red += '\n '+msg
|
||||||
else: red = msg
|
else: red = msg
|
||||||
else:
|
except:
|
||||||
msg = _('not running')
|
msg = _('service not running')
|
||||||
if not black: black = msg
|
if not black: black = msg
|
||||||
else: black+= ' | '+msg
|
else: black+= ' | '+msg
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user