Skip to content

Commit

Permalink
Updates for windows
Browse files Browse the repository at this point in the history
Roll app version
  • Loading branch information
Daniel Slosky committed Apr 16, 2019
1 parent fc314d7 commit 6ea058f
Show file tree
Hide file tree
Showing 25 changed files with 524 additions and 99 deletions.
27 changes: 4 additions & 23 deletions admin/Windows/env_setup.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ echo off
SET location=%~dp0
cd %location%

cd ..\..\..\python\Python27

SET pythonLoc=%cd%

:: Create symbolic link to shrink path length
mklink /D C:\scPython %pythonLoc%
SET pythonLoc="C:\Python27"

:: only add new paths if they aren't already in PATH
SET newPath=C:\scPython;C:\scPython\Scripts;C:\scPython\Lib\site-packages\pywin32_system32;C:\scPython\Lib\site-packages\win32
SET newPath=C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages\pywin32_system32;C:\Python27\Lib\site-packages\win32
(echo ";%PATH%;" | find /C /I ";%newPath%;")>tmp.txt

SET /P var=<tmp.txt
Expand All @@ -27,24 +22,10 @@ del tmp.txt

echo Installing required libraries...

cd ..\..\site-packages

"%pythonLoc%\python.exe" -m pip install --no-deps wheel-0.26.0-py2.py3-none-any.whl
"%pythonLoc%\python.exe" -m pip install --no-deps click-6.6-py2.py3-none-any.whl
"%pythonLoc%\python.exe" -m pip install --no-deps itsdangerous-0.24.tar.gz
"%pythonLoc%\python.exe" -m pip install --no-deps Jinja2-2.8-py2.py3-none-any.whl
"%pythonLoc%\python.exe" -m pip install --no-deps Werkzeug-0.11.10-py2.py3-none-any.whl
"%pythonLoc%\python.exe" -m pip install --no-deps MarkupSafe-0.23.tar.gz

"%pythonLoc%\python.exe" -m easy_install --no-deps Flask-0.10.1.tar.gz
"%pythonLoc%\python.exe" -m easy_install --no-deps Flask-Login-0.3.2.tar.gz
"%pythonLoc%\python.exe" -m easy_install --no-deps Flask-Uploads-0.2.0.tar.gz

"%pythonLoc%\python.exe" -m pip install --no-deps PySocks-1.5.7.tar.gz
"%pythonLoc%\python.exe" -m pip install --no-deps SQLAlchemy-1.0.14.tar.gz
"%pythonLoc%\python.exe" -m pip install --no-deps xmltodict-0.10.2.tar.gz
cd ..\..\

"%pythonLoc%\python.exe" -m pip install --no-deps pypiwin32-219-cp27-none-win32.whl
"%pythonLoc%\python.exe" -m pip install usgs-shakecast

cd %location%

Expand Down
10 changes: 7 additions & 3 deletions admin/Windows/server_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
if app_dir not in sys.path:
sys.path += [app_dir]

from app.server import Server
from ui import UI
from app.util import SC
from shakecast.app.server import Server
from shakecast.ui import UI
from shakecast.app.util import SC

path += ['logs', 'sc-service.log']
sc = SC()
Expand Down Expand Up @@ -85,5 +85,9 @@ def main():
text))
return

def start():
argvals = ['server_service.py', 'start']
win32serviceutil.HandleCommandLine(ShakecastServer, argv=argvals)

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(ShakecastServer)
27 changes: 27 additions & 0 deletions installer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Application]
name=ShakeCast
version=4.0.6
entry_point=shakecast:start
# Yuck, pywin32 stores modules in odd places, so we need this to get them loaded
# correctly
extra_preamble=./shakecast/windows/set_paths.py

[Python]
version=2.7
bitness=32
format=bundled

[Include]
pypi_wheels = click==6.6
Flask==0.12.3
Flask-Login==0.4.1
Flask-Uploads==0.2.1
fpdf==1.7.2
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
PySocks==1.5.7
shakecast-aebm==0.0b1
SQLAlchemy==1.0.14
Werkzeug==0.11.10
xmltodict==0.10.2
101 changes: 101 additions & 0 deletions nsis.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
!include LogicLib.nsh

# define the name of installer
OutFile "dist\Shakecast_Installer.exe"

# define default installation directory
InstallDir "$PROFILE\Shakecast"

# Get admin level
RequestExecutionLevel admin

!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
messageBox mb_iconstop "Administrator rights required!"
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
quit
${EndIf}
!macroend

function .onInit
setShellVarContext all
!insertmacro VerifyUserIsAdmin
functionEnd

# start default section
Section "Install ShakeCast" IDOK

# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR

# set environment variable for shakecast home
EnVar::AddValue "SC_HOME" "$PROFILE/.shakecast"

DetailPrint "Extracting Files into Installation Directory"

# specify files to go into the installation directory path
File /r "*"

# Uninstaller - See function un.onInit and section "uninstall" for configuration
writeUninstaller "$INSTDIR\uninstall.exe"

SectionEnd

Section "Python Installation"

# run the python installer and wait for it to finish
File "..\requirements\python-2.7.13.msi"
ExecWait '"$SYSDIR\msiExec" /i "$INSTDIR\python-2.7.13.msi" /qb TARGETDIR=C:\Python27 ALLUSERS=1'

# install the windows extensions
File "..\requirements\pywin32-224.win32-py2.7.exe"
ExecWait 'C:\Python27\Scripts\easy_install.exe "$INSTDIR\pywin32-224.win32-py2.7.exe"'


SectionEnd

Section "ShakeCast installation"
DetailPrint "Installing ShakeCast"

ExecWait "C:\Python27\python.exe -m pip install usgs-shakecast"
ExecWait "C:\Python27\python.exe -m shakecast.app.windows.set_paths"
ExecWait "C:\Python27\python.exe -m shakecast start"
DetailPrint "Finishing up Installation"
SectionEnd

# Uninstaller

function un.onInit
SetShellVarContext all

#Verify the uninstaller - last chance to back out
MessageBox MB_OKCANCEL "Permanantly remove ShakeCast?" IDOK next
Abort
next:
!insertmacro VerifyUserIsAdmin
functionEnd

section "uninstall"

ExecWait "c:\python27\python.exe -m shakecast stop"
ExecWait "c:\python27\python.exe -m shakecast uninstall"
ExecWait '"$SYSDIR\msiExec" /x "$INSTDIR\python-2.7.13.msi"'

# Remove files
delete $INSTDIR\*

# Remove ShakeCast directories safely
rmDir /r $INSTDIR\admin
rmDir /r $INSTDIR\shakecast
rmDir /r $INSTDIR\appveyor
rmDir /r $INSTDIR\.git

# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe

# Try to remove the install directory
rmDir /r $INSTDIR

sectionEnd
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='4.0.6',
version='4.0.7',

description='Real time facility monitoring and notifications for earthquake impacts',
long_description=long_description,
Expand Down
1 change: 0 additions & 1 deletion shakecast/.status

This file was deleted.

2 changes: 1 addition & 1 deletion shakecast/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import app
from . import app
61 changes: 26 additions & 35 deletions shakecast/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
from .app.startup import pip_init
pip_init()

from .admin.server_service import ShakecastServer
from .admin.web_server_service import ShakecastWebServer
from .app.util import SC, sc_dir
from .app.util import SC, sc_dir, on_windows
import app.windows as winControls
import app.linux as controls

if on_windows():
# use windows controls if we're in that OS
controls = winControls

def check_running():
##### replace with actual server health checks #####
Expand All @@ -34,14 +38,17 @@ def invalid():
stop - Stops the ShakeCast servers
'''

def install_windows():
main('start')

def main(command = None):
sc = SC()
uid = 0
if sc.dict['web_port'] < 1024:
uid = os.getuid()
try:
uid = os.getuid()
except Exception as e:
# this will error in Windows, but that doesn't mean the
# user isn't an admin... just try to install and let it
# error if the user doesn't have privileges
pass

if uid == 0:
if len(sys.argv) == 2:
Expand All @@ -52,6 +59,7 @@ def main(command = None):

elif command == 'stop':
shutdown()

else:
invalid()

Expand All @@ -75,42 +83,25 @@ def sudo_required():
def start():
status = 'running'
write_status(status)
controls.start()

start_services()
while status == 'running':
status = read_status()
if check_running() is False and status == 'running':
restart_services()
if not on_windows():
# keep alive on linux to watch the services
while status == 'running':
status = read_status()
if check_running() is False and status == 'running':
restart_services()

time.sleep(10)
time.sleep(10)

def restart_services():
stop_services()
controls.stop()
time.sleep(10)
start_services()
controls.start()

def shutdown():
write_status('stopped')
stop_services()

def start_services():
server = ShakecastServer()
p = Process(target=server.start)
p.name = 'ShakeCast-Server'
p.daemon = True
p.start()

server = ShakecastWebServer()
p = Process(target=server.start)
p.name = 'ShakeCast-Web-Server'
p.daemon = True
p.start()

def stop_services():
server = ShakecastServer()
server.stop()
server = ShakecastWebServer()
server.stop()
controls.stop()

def write_status(status):
file_name = os.path.join(sc_dir(), '.status')
Expand Down
1 change: 1 addition & 0 deletions shakecast/app/linux/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from controls import start, stop
File renamed without changes.
17 changes: 17 additions & 0 deletions shakecast/app/linux/controls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

from server_service import ShakecastServer
from web_server_service import ShakecastWebServer

def start():
server = ShakecastServer()
web_server = ShakecastWebServer()

server.start_daemon()
web_server.start_daemon()

def stop():
server = ShakecastServer()
web_server = ShakecastWebServer()

server.stop()
web_server.stop()
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import socket
import logging
from multiprocessing import Process
import os, sys
import traceback

from ..app.server import Server
from ..app.util import SC, get_logging_dir
from ..ui import UI
from shakecast.app.server import Server
from shakecast.app.util import SC, get_logging_dir
from shakecast.ui import UI

sc = SC()
if sc.dict['Logging']['level'] == 'info':
Expand Down Expand Up @@ -41,6 +42,12 @@ def start(self):
else:
logging.info('Startup Failed -- ShakeCast Server is already started')

def start_daemon(self):
p = Process(target=self.start)
p.name = 'ShakeCast-Server'
p.daemon = True
p.start()

@staticmethod
def main():
logging.info(' ** Starting ShakeCast Server ** ')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import socket
import logging
from multiprocessing import Process
import os, sys
import traceback
import urllib2

from ..app.util import SC, get_logging_dir
from ..web_server import start as start_web_server
from shakecast.app.util import SC, get_logging_dir
from shakecast.web_server import start as start_web_server

logs_dir = get_logging_dir()
log_file = os.path.join(logs_dir, 'sc-web-server.log')
Expand Down Expand Up @@ -37,6 +38,12 @@ def stop():
def start(self):
self.main()

def start_daemon(self):
p = Process(target=self.start)
p.name = 'ShakeCast-Web-Server'
p.daemon = True
p.start()

@staticmethod
def main():
logging.info(' ** Starting ShakeCast Web Server ** ')
Expand Down
Loading

0 comments on commit 6ea058f

Please sign in to comment.