fix windows restart
This commit is contained in:
parent
d0c19737f9
commit
d32e1527a8
3 changed files with 64 additions and 10 deletions
|
@ -2,11 +2,12 @@
|
|||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
|
||||
import subprocess
|
||||
from os.path import join, exists, dirname
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import settings
|
||||
from utils import run, get
|
||||
|
@ -55,7 +56,35 @@ def command_stop(*args):
|
|||
"""
|
||||
Stop Open Media Libary
|
||||
"""
|
||||
pass
|
||||
if sys.platform == 'win32':
|
||||
from utils import check_pid
|
||||
if args:
|
||||
pid = args[0]
|
||||
else:
|
||||
pid = os.path.join(settings.data_path, 'openmedialibrary.pid')
|
||||
try:
|
||||
with open(pid) as fd:
|
||||
pid = int(fd.read())
|
||||
except:
|
||||
return
|
||||
if check_pid(pid):
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
|
||||
def command_restart(*args):
|
||||
"""
|
||||
Restart Open Media Libary
|
||||
"""
|
||||
if sys.platform == 'win32':
|
||||
from utils import check_pid, ctl
|
||||
pidfile = os.path.join(settings.data_path, 'openmedialibrary.pid')
|
||||
try:
|
||||
with open(pidfile) as fd:
|
||||
pid = int(fd.read())
|
||||
except:
|
||||
pid = None
|
||||
if pid and check_pid(pid):
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
ctl('server', pidfile)
|
||||
|
||||
def command_install_launcher(*args):
|
||||
"""
|
||||
|
|
|
@ -19,8 +19,8 @@ import OpenSSL.crypto
|
|||
import ox
|
||||
from oxtornado import actions
|
||||
|
||||
import state
|
||||
import settings
|
||||
import utils
|
||||
import db
|
||||
|
||||
import logging
|
||||
|
@ -206,12 +206,7 @@ def update_available():
|
|||
def restart_oml(update=False):
|
||||
if update:
|
||||
get_latest_release()
|
||||
if sys.platform == 'win32':
|
||||
subprocess.Popen([os.path.join(settings.base_dir, 'ctl.bat'), 'restart'],
|
||||
start_new_session=True)
|
||||
else:
|
||||
subprocess.Popen([os.path.join(settings.base_dir, 'ctl'), 'restart'],
|
||||
close_fds=True, start_new_session=True)
|
||||
utils.ctl('restart')
|
||||
|
||||
def get_app_version(app):
|
||||
plist = app + '/Contents/Info.plist'
|
||||
|
|
30
oml/utils.py
30
oml/utils.py
|
@ -433,3 +433,33 @@ def update_static():
|
|||
for file in files
|
||||
])
|
||||
)
|
||||
|
||||
def check_pid(pid):
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def check_pidfile(pid):
|
||||
try:
|
||||
with open(pid) as fd:
|
||||
pid = int(fd.read())
|
||||
except:
|
||||
return False
|
||||
return check_pid(pid)
|
||||
|
||||
def ctl(*args):
|
||||
if sys.platform == 'win32':
|
||||
import settings
|
||||
platform_win32 = os.path.normpath(os.path.join(settings.base_dir, '..', 'platform_win32'))
|
||||
python = os.path.join(platform_win32, 'pythonw.exe')
|
||||
cmd = [python, 'oml'] + list(args)
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
startupinfo.wShowWindow = subprocess.SW_HIDE
|
||||
subprocess.Popen(cmd, cwd=settings.base_dir, start_new_session=True, startupinfo=startupinfo)
|
||||
else:
|
||||
subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args),
|
||||
close_fds=True, start_new_session=True)
|
||||
|
|
Loading…
Reference in a new issue