fixed: on linux, daemon not start with system boot.

pull/32/merge
Apex Liu 2017-01-27 00:20:03 +08:00
parent c6f0b24680
commit faa5887e25
20 changed files with 227 additions and 450 deletions

2
.gitignore vendored
View File

@ -38,8 +38,6 @@ __pycache__
/external/openssl
/external/python
/build/config.py
# for dist folder
/dist/*.zip
/dist/*.tar.gz

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/builder" />
<orderEntry type="jdk" jdkName="py34-x86" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="3.4 x64" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">

View File

@ -14,10 +14,10 @@ ROOT_PATH = utils.cfg.ROOT_PATH
PATH_EXTERNAL = os.path.join(ROOT_PATH, 'external')
PATH_DOWNLOAD = os.path.join(PATH_EXTERNAL, '_download_')
OPENSSL_VER = utils.cfg.OPENSSL_VER
LIBUV_VER = utils.cfg.LIBUV_VER
MBEDTLS_VER = utils.cfg.MBEDTLS_VER
SQLITE_VER = utils.cfg.SQLITE_VER
OPENSSL_VER = utils.cfg.ver.openssl
LIBUV_VER = utils.cfg.ver.libuv
MBEDTLS_VER = utils.cfg.ver.mbedtls
SQLITE_VER = utils.cfg.ver.sqlite
class BuilderBase:

View File

@ -24,155 +24,30 @@ class BuilderBase:
def build_installer(self):
pass
def _build_web_backend(self, base_path, dist, target_path):
cc.n('make Teleport Backend package...')
src_path = os.path.join(ROOT_PATH, 'web', 'site', 'backend')
pkg_path = os.path.join(ROOT_PATH, 'web', 'packages')
tmp_path = os.path.join(base_path, '_tmp_backend_')
tmp_app_path = os.path.join(tmp_path, 'app')
if os.path.exists(tmp_path):
utils.remove(tmp_path)
cc.n(' - make pyo and pack to zip...')
shutil.copytree(os.path.join(src_path, 'app'), tmp_app_path)
comm_path = os.path.join(pkg_path, 'common')
comm_dir = os.listdir(comm_path)
for d in comm_dir:
s = os.path.join(comm_path, d)
t = os.path.join(tmp_app_path, d)
if os.path.isdir(s):
shutil.copytree(s, t)
else:
shutil.copy(s, t)
makepyo.make(tmp_app_path)
shutil.make_archive(os.path.join(tmp_path, 'app'), 'zip', tmp_app_path)
utils.remove(tmp_app_path)
cc.n(' - copy packages...')
pkgs = ['packages-common', 'packages-{}'.format(dist)]
for d in pkgs:
s = os.path.join(pkg_path, d)
t = os.path.join(tmp_path, 'packages', d)
if os.path.isdir(s):
shutil.copytree(s, t)
else:
shutil.copy(s, t)
makepyo.remove_cache(tmp_path)
cc.n(' - copy static and view...')
miscs = ['static', 'view', 'res', 'tools']
for d in miscs:
s = os.path.join(src_path, d)
t = os.path.join(tmp_path, d)
if os.path.isdir(s):
shutil.copytree(s, t)
else:
shutil.copy(s, t)
# self._create_start_file(os.path.join(tmp_path, 'eom_bootstrap.py'), 'ts-backend')
shutil.copytree(tmp_path, os.path.join(target_path, 'www', 'backend'))
utils.remove(tmp_path)
# def _create_start_file(self, fname, name):
# f = open(fname, 'w')
# f.write('# -*- coding: utf-8 -*-\n')
# f.write('import os\n')
# f.write('import sys\n')
# f.write('p = os.path.abspath(os.path.dirname(__file__))\n')
# f.write('_p = os.path.join(p, "app.zip")\n')
# f.write('sys.path.insert(0, _p)\n')
# # f.write('_p = os.path.join(p, "{}", "app", "common.zip")\n'.format(name))
# # f.write('sys.path.insert(0, _p)\n')
# f.write('def main():\n')
# f.write(' try:\n')
# f.write(' import eom_main\n')
# f.write(' return eom_main.main()\n')
# f.write(' except:\n')
# f.write(' print("can not start {}.")\n'.format(name))
# f.write(' raise\n')
# f.write('if __name__ == "__main__":\n')
# f.write(' sys.exit(main())\n')
#
# f.close()
# def _build_web_frontend(self, base_path, dist, target_path):
# cc.n('make Teleport Frontend package...')
# src_path = os.path.join(ROOT_PATH, 'web', 'site', 'frontend')
# pkg_path = os.path.join(ROOT_PATH, 'web', 'packages')
# tmp_path = os.path.join(base_path, '_tmp_frontend_')
#
# if os.path.exists(tmp_path):
# utils.remove(tmp_path)
#
# shutil.copytree(os.path.join(src_path, 'app'), os.path.join(tmp_path, 'app'))
#
# pkg_common = os.path.join(pkg_path, 'common')
# _s_path = os.listdir(pkg_common)
# for d in _s_path:
# s = os.path.join(pkg_common, d)
# t = os.path.join(tmp_path, 'app', d)
# if os.path.isdir(s):
# shutil.copytree(s, t)
# else:
# shutil.copy(s, t)
#
# cc.n(' - copy packages...')
# pkgs = ['packages-common', 'packages-{}'.format(dist)]
# for d in pkgs:
# s = os.path.join(pkg_path, d)
# t = os.path.join(tmp_path, 'packages', d)
# if os.path.isdir(s):
# shutil.copytree(s, t)
# else:
# shutil.copy(s, t)
#
# makepyo.remove_cache(tmp_path)
#
# cc.n(' - copy static and view...')
# miscs = ['static', 'view', 'res']
# for d in miscs:
# s = os.path.join(src_path, d)
# t = os.path.join(tmp_path, d)
# if os.path.isdir(s):
# shutil.copytree(s, t)
# else:
# shutil.copy(s, t)
#
# # if not os.path.exists(os.path.join(tmp_path, 'static', 'download')):
# # utils.makedirs(os.path.join(tmp_path, 'static', 'download'))
# # utils.copy_file(os.path.join(ROOT_PATH, 'dist'), os.path.join(tmp_path, 'static', 'download'), 'teleport-assist-win.zip')
#
# shutil.copytree(tmp_path, os.path.join(target_path, 'www', 'frontend'))
# utils.remove(tmp_path)
def _build_web(self, base_path, dist, target_path):
cc.n('make Teleport Web package...')
src_path = os.path.join(ROOT_PATH, 'web', 'site', 'teleport')
pkg_path = os.path.join(ROOT_PATH, 'web', 'packages')
# src_path = os.path.join(ROOT_PATH, 'server', 'www', 'teleport')
# pkg_path = os.path.join(ROOT_PATH, 'server', 'www', 'packages')
src_path = os.path.join(ROOT_PATH, 'server', 'www')
pkg_path = os.path.join(src_path, 'packages')
tmp_path = os.path.join(base_path, '_tmp_web_')
if os.path.exists(tmp_path):
utils.remove(tmp_path)
shutil.copytree(os.path.join(src_path, 'app'), os.path.join(tmp_path, 'app'))
# shutil.copytree(os.path.join(src_path, 'app'), os.path.join(tmp_path, 'app'))
shutil.copytree(os.path.join(src_path, 'teleport'), os.path.join(tmp_path, 'teleport'))
utils.remove(os.path.join(tmp_path, 'teleport', '.idea'))
pkg_common = os.path.join(pkg_path, 'common')
_s_path = os.listdir(pkg_common)
for d in _s_path:
s = os.path.join(pkg_common, d)
t = os.path.join(tmp_path, 'app', d)
if os.path.isdir(s):
shutil.copytree(s, t)
else:
shutil.copy(s, t)
# pkg_common = os.path.join(pkg_path, 'common')
# _s_path = os.listdir(pkg_common)
# for d in _s_path:
# s = os.path.join(pkg_common, d)
# t = os.path.join(tmp_path, 'app', d)
# if os.path.isdir(s):
# shutil.copytree(s, t)
# else:
# shutil.copy(s, t)
cc.n(' - copy packages...')
pkgs = ['packages-common', 'packages-{}'.format(dist)]
@ -186,21 +61,21 @@ class BuilderBase:
makepyo.remove_cache(tmp_path)
cc.n(' - copy static and view...')
miscs = ['static', 'view', 'res', 'tools']
for d in miscs:
s = os.path.join(src_path, d)
t = os.path.join(tmp_path, d)
if os.path.isdir(s):
shutil.copytree(s, t)
else:
shutil.copy(s, t)
# cc.n(' - copy static and view...')
# miscs = ['static', 'view', 'res', 'tools']
# for d in miscs:
# s = os.path.join(src_path, d)
# t = os.path.join(tmp_path, d)
# if os.path.isdir(s):
# shutil.copytree(s, t)
# else:
# shutil.copy(s, t)
# if not os.path.exists(os.path.join(tmp_path, 'static', 'download')):
# utils.makedirs(os.path.join(tmp_path, 'static', 'download'))
# utils.copy_file(os.path.join(ROOT_PATH, 'dist'), os.path.join(tmp_path, 'static', 'download'), 'teleport-assist-win.zip')
shutil.copytree(tmp_path, os.path.join(target_path, 'www', 'teleport'))
shutil.copytree(tmp_path, os.path.join(target_path, 'www'))
utils.remove(tmp_path)
@ -287,7 +162,8 @@ class BuilderLinux(BuilderBase):
# self.name = 'teleport-server-linux-{}-{}'.format(ctx.bits_path, _ver)
self.name = 'teleport-server-linux-{}-{}'.format(ctx.bits_path, VER_TELEPORT_SERVER)
self.base_path = os.path.join(ROOT_PATH, 'dist', 'installer', ctx.dist, 'server')
self.dist_path = os.path.join(ROOT_PATH, 'dist', ctx.dist, 'server')
self.base_path = os.path.join(ROOT_PATH, 'out', 'installer', 'server')
self.base_tmp = os.path.join(self.base_path, '_tmp_')
self.tmp_path = os.path.join(self.base_tmp, self.name, 'data', 'teleport')
@ -309,27 +185,29 @@ class BuilderLinux(BuilderBase):
# utils.copy_file(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'web-frontend.conf')
self._build_web(self.base_path, 'linux', self.tmp_path)
utils.copy_file(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'web.conf')
utils.copy_file(os.path.join(ROOT_PATH, 'server', 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
utils.copy_file(os.path.join(ROOT_PATH, 'server', 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
# out_path = os.path.join(ROOT_PATH, 'out', 'eom_ts', ctx.target_path, ctx.dist_path)
# out_path = os.path.join(ROOT_PATH, 'out', 'eom_ts', ctx.bits_path, 'bin')
# bin_path = os.path.join(self.tmp_path, 'bin')
# utils.copy_file(out_path, bin_path, 'eom_ts')
out_path = os.path.join(ROOT_PATH, 'out', 'eom_ts', ctx.bits_path, 'bin')
out_path = os.path.join(ROOT_PATH, 'out', 'server', ctx.bits_path, 'bin')
bin_path = os.path.join(self.tmp_path, 'bin')
utils.copy_ex(out_path, bin_path, 'eom_ts')
utils.copy_ex(out_path, bin_path, 'tp_web')
utils.copy_ex(out_path, bin_path, 'tp_core')
utils.copy_ex(out_path, bin_path, 'libtpssh.so')
# utils.copy_ex(out_path, bin_path, 'pysrt')
utils.copy_ex(os.path.join(ROOT_PATH, 'dist', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))
utils.copy_ex(os.path.join(ROOT_PATH, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))
utils.copy_file(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'eom_ts.ini')
# utils.copy_file(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'eom_ts.ini')
# utils.copy_file(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'license.key')
utils.copy_file(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'ts_ssh_server.key')
utils.copy_ex(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'ssl')
utils.copy_file(os.path.join(ROOT_PATH, 'server', 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'tp_ssh_server.key')
# utils.copy_ex(os.path.join(ROOT_PATH, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'ssl')
# utils.copy_ex(os.path.join(ROOT_PATH, 'share', 'data'), os.path.join(self.tmp_path, 'tmp', 'data'), ('ts_db_release.db', 'ts_db.db'))
utils.copy_ex(os.path.join(ROOT_PATH, 'share', 'data'), os.path.join(self.tmp_path, 'tmp', 'data'), 'main.sql')
utils.copy_ex(os.path.join(ROOT_PATH, 'server', 'share', 'data'), os.path.join(self.tmp_path, 'tmp', 'data'), 'main.sql')
# utils.make_zip(self.tmp_path, os.path.join(self.tmp_path, '..', 'eom_ts.zip'))
utils.make_targz(os.path.join(self.tmp_path, '..'), 'teleport', 'teleport.tar.gz')
@ -338,16 +216,17 @@ class BuilderLinux(BuilderBase):
# make final installer.
cc.n('pack final server installer...')
# out_file = os.path.join(ROOT_PATH, 'dist', '{}.zip'.format(self.name))
out_file = os.path.join(ROOT_PATH, 'dist', '{}.tar.gz'.format(self.name))
out_file = os.path.join(ROOT_PATH, 'out', 'installer', '{}.tar.gz'.format(self.name))
if os.path.exists(out_file):
utils.remove(out_file)
# # copy installer scripts.
for i in ['daemon', 'start.sh', 'stop.sh', 'status.sh']:
shutil.copy(os.path.join(self.base_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', i)))
for i in ['install.sh']:
shutil.copy(os.path.join(self.base_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', '..', i)))
# for i in ['daemon_web', 'daemon_core', 'teleport.sh']:
shutil.copy(os.path.join(self.dist_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', i)))
for i in ['install.sh', 'uninst.sh']:
shutil.copy(os.path.join(self.dist_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', '..', i)))
# utils.make_zip(os.path.join(self.base_tmp, self.name), out_file)
utils.make_targz(self.base_tmp, self.name, out_file)

View File

@ -28,7 +28,7 @@ PY_LIB_REMOVE_LINUX = ['ctypes/test', 'curses', 'config-3.4m-x86_64-linux-gnu',
class PYSBase:
def __init__(self):
self.base_path = os.path.join(ROOT_PATH, 'out', 'pysrt')#, ctx.dist_path)
self.base_path = os.path.join(ROOT_PATH, 'out', 'pysrt', ctx.dist_path)
self.py_dll_path = ''
self.py_lib_path = ''

View File

@ -83,11 +83,12 @@ class ConfigFile(AttrDict):
self['ver'][k] = _tmp[k]
_tmp = _cfg['toolchain']
self['toolchain'] = AttrDict()
if self.is_win:
self['nsis'] = _tmp.get('nsis', None)
self['msbuild'] = None # msbuild always read from register.
self['toolchain']['nsis'] = _tmp.get('nsis', None)
self['toolchain']['msbuild'] = None # msbuild always read from register.
else:
self['cmake'] = _tmp.get('cmake', '/usr/bin/cmake')
self['toolchain']['cmake'] = _tmp.get('cmake', '/usr/bin/cmake')
return True

View File

@ -17,7 +17,7 @@ try:
if not cfg.init(CONFIG_FILE):
sys.exit(1)
except:
cc.e('can not load configuration.\n\nplease copy `config.py.in` into `config.py` and modify it to fit your condition and try again.')
cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
sys.exit(1)
if cfg.is_py2:
@ -340,14 +340,16 @@ def nsis_build(nsi_file, _define=''):
def cmake(work_path, target, force_rebuild, cmake_define=''):
# because cmake v2.8 shipped with Ubuntu 14.04LTS, but we need 3.5.
# so we copy a v3.5 cmake from CLion and put to $WORK/eomsoft/toolchain/cmake.
# CMAKE = os.path.abspath(os.path.join(root_path(), 'toolchain', 'cmake', 'bin', 'cmake'))
if 'cmake' not in cfg:
# I copy a v3.5 cmake from CLion.
print(cfg)
if 'cmake' not in cfg.toolchain:
raise RuntimeError('please set `cmake` path.')
if not os.path.exists(cfg['cmake']):
raise RuntimeError('`cmake` does not exists, please check your config.py and try again.')
CMAKE = cfg['cmake']
print(cfg.toolchain.cmake)
if not os.path.exists(cfg.toolchain.cmake):
raise RuntimeError('`cmake` does not exists, please check your configuration and try again.')
CMAKE = cfg.toolchain.cmake
cc.n('make by cmake', target, sep=': ')
old_p = os.getcwd()

View File

@ -160,7 +160,7 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
}
#else
vswprintf(szTmp+offset, 4095-offset, fmt, valist);
wprintf(L"%s", szTmp);
wprintf(L"%ls", szTmp);
fflush(stdout);
#endif

View File

@ -4,10 +4,10 @@
#============================================
# if not set nsis path, default to get it by register.
#nsis = "C:\Program Files (x86)\NSIS\Unicode\makensis.exe"
#nsis = C:\Program Files (x86)\NSIS\Unicode\makensis.exe
# if not set msbuild path, default to get it by register.
#msbuild = "C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe"
#msbuild = C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe
# ============================================
@ -15,11 +15,11 @@
# ============================================
# if not set cmake path, default to '/usr/bin/cmake'
cmake = "/opt/cmake/bin/cmake"
cmake = /opt/cmake/bin/cmake
[external_ver]
# openssl = 1.0.2h
openssl = 1.0.2h
libuv = 1.9.1
mbedtls = 2.3.0
sqlite = 3160200

View File

@ -1,9 +1,9 @@
#!/bin/sh
#!/bin/bash
### BEGIN INIT INFO
# Provides: eomsoft
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Provides: teleport
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the teleport daemon

View File

@ -17,24 +17,28 @@ PATH_TARGET=/usr/local/eom
if [ ! -d "${PATH_TARGET}" ]; then
mkdir -p "${PATH_TARGET}"
else
if [ -f /etc/init.d/eom_ts ]; then
service eom_ts stop
rm -rf /etc/init.d/eom_ts
fi
if [ -f /etc/rc2.d/S50eom_ts ]; then
rm -rf /etc/rc2.d/S50eom_ts
fi
if [ -f /etc/init.d/teleport ]; then
service teleport stop
rm -rf /etc/init.d/teleport
fi
if [ -f /etc/rc2.d/S50teleport ]; then
rm -rf /etc/rc2.d/S50teleport
fi
fi
if [ -f /etc/init.d/eom_ts ]; then
service eom_ts stop
rm -rf /etc/init.d/eom_ts
fi
rm -rf /etc/rc2.d/S50eom_ts
rm -rf /etc/rc3.d/S50eom_ts
rm -rf /etc/rc4.d/S50eom_ts
rm -rf /etc/rc5.d/S50eom_ts
if [ -f /etc/init.d/teleport ]; then
service teleport stop
rm -rf /etc/init.d/teleport
fi
rm -rf /etc/rc2.d/S50teleport
rm -rf /etc/rc3.d/S50teleport
rm -rf /etc/rc4.d/S50teleport
rm -rf /etc/rc5.d/S50teleport
sleep 1
echo ""
echo "Installing EOM Teleport Server..."
@ -72,10 +76,10 @@ chmod +x "${PATH_TARGET}/teleport/status.sh"
cp "${PATH_ROOT}/data/daemon" /etc/init.d/teleport
chmod +x /etc/init.d/teleport
if [ -f /etc/rc2.d/S50teleport ]; then
rm -rf /etc/rc2.d/S50teleport
fi
ln -s /etc/init.d/teleport /etc/rc2.d/S50teleport
ln -s /etc/init.d/teleport /etc/rc3.d/S50teleport
ln -s /etc/init.d/teleport /etc/rc4.d/S50teleport
ln -s /etc/init.d/teleport /etc/rc5.d/S50teleport
# Upgrade database...
"${PATH_TARGET}/teleport/bin/tp_web" --py "${PATH_TARGET}/teleport/www/teleport/app/eom_upgrade.py"

View File

@ -19,17 +19,20 @@ if [ -f /etc/init.d/eom_ts ]; then
service eom_ts stop
rm -rf /etc/init.d/eom_ts
fi
if [ -f /etc/rc2.d/S50eom_ts ]; then
rm -rf /etc/rc2.d/S50eom_ts
fi
rm -rf /etc/rc2.d/S50eom_ts
rm -rf /etc/rc3.d/S50eom_ts
rm -rf /etc/rc4.d/S50eom_ts
rm -rf /etc/rc5.d/S50eom_ts
if [ -f /etc/init.d/teleport ]; then
service teleport stop
rm -rf /etc/init.d/teleport
fi
if [ -f /etc/rc2.d/S50teleport ]; then
rm -rf /etc/rc2.d/S50teleport
fi
rm -rf /etc/rc2.d/S50teleport
rm -rf /etc/rc3.d/S50teleport
rm -rf /etc/rc4.d/S50teleport
rm -rf /etc/rc5.d/S50teleport
if [ -d /usr/local/eom/teleport ]; then

View File

@ -88,8 +88,8 @@ bool TsEnv::init(void)
EXLOG_LEVEL(log_level);
}
EXLOGI("==============================\n");
EXLOGI("[tpweb] start...\n");
// EXLOGI("==============================\n");
// EXLOGI("[tpweb] start...\n");
return true;
}

View File

@ -11,11 +11,11 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="py34-x86" jdkType="Python SDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="myDocStringFormat" value="Google" />
<option name="myDocStringFormat" value="Epytext" />
</component>
<component name="TemplatesService">
<option name="templateFileTypes">

View File

@ -10,10 +10,14 @@ def run(options):
log.initialize()
# log.set_attribute(min_level=LOG_VERBOSE, log_datetime=False, trace_error=TRACE_ERROR_NONE)
# log.set_attribute(min_level=LOG_VERBOSE, trace_error=TRACE_ERROR_NONE)
log.set_attribute(min_level=LOG_DEBUG, trace_error=TRACE_ERROR_FULL)
# log.set_attribute(min_level=LOG_DEBUG, trace_error=TRACE_ERROR_FULL)
_app = SwxCore()
if not _app.init(options):
return 1
log.i('\n')
log.i('###############################################################\n')
log.i('Teleport Web Server starting ...\n')
return _app.run()

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
import os
import sys
# import sys
import configparser
from eom_common.eomcore.logger import log
from eom_common.eomcore.logger import *
__all__ = ['app_cfg']
@ -25,23 +25,6 @@ class AttrDict(dict):
self[name] = val
# def attr_dict(obj):
# """
# 将一个对象中的dict转变为AttrDict类型
# """
# if isinstance(obj, dict):
# ret = AttrDict()
# for k in obj:
# # ret[k] = obj[k]
# if isinstance(obj[k], dict):
# ret[k] = attr_dict(obj[k])
# else:
# ret[k] = obj[k]
# else:
# ret = obj
# return ret
class ConfigFile(AttrDict):
def __init__(self, **kwargs):
super().__init__(**kwargs)
@ -51,17 +34,17 @@ class ConfigFile(AttrDict):
def load(self, cfg_file):
if not os.path.exists(cfg_file):
log.e('configuration file does not exists.')
log.e('configuration file does not exists: [{}]\n'.format(cfg_file))
return False
try:
_cfg = configparser.ConfigParser()
_cfg.read(cfg_file)
except:
log.e('can not load configuration file.')
log.e('can not load configuration file: [{}]\n'.format(cfg_file))
return False
if 'common' not in _cfg:
log.e('invalid configuration file.')
log.e('invalid configuration file: [{}]\n'.format(cfg_file))
return False
_comm = _cfg['common']
@ -70,59 +53,23 @@ class ConfigFile(AttrDict):
if self['log_file'] is not None:
self['log_path'] = os.path.dirname(self['log_file'])
return True
_level = _comm.getint('log-level', 2)
if _level == 0:
self['log_level'] = LOG_DEBUG
elif _level == 1:
self['log_level'] = LOG_VERBOSE
elif _level == 2:
self['log_level'] = LOG_INFO
elif _level == 3:
self['log_level'] = LOG_WARN
elif _level == 4:
self['log_level'] = LOG_ERROR
else:
self['log_level'] = LOG_VERBOSE
# def load_str(self, module, code):
# m = type(sys)(module)
# m.__module_class__ = type(sys)
# m.__file__ = module
#
# try:
# exec(compile(code, module, 'exec'), m.__dict__)
# except Exception as e:
# log.e('%s\n' % str(e))
# # print(str(e))
# # if eom_dev_conf.debug:
# # raise
# return False
#
# for y in m.__dict__:
# if '__' == y[:2]:
# continue
# if isinstance(m.__dict__[y], dict):
# self[y] = AttrDict()
# self._assign_dict(m.__dict__[y], self[y])
# else:
# self[y] = m.__dict__[y]
#
# return True
#
# def _load(self, full_path, must_exists=True):
# try:
# f = open(full_path, encoding='utf8')
# code = f.read()
# f.close()
# self.__loaded = True
# except IOError:
# if must_exists:
# log.e('Can not load config file: %s\n' % full_path)
# return False
#
# module = os.path.basename(full_path)
# if not self.load_str(module, code):
# return False
#
# self.__file_name = full_path
# return True
#
# def _assign_dict(self, _from, _to):
# for y in _from:
# if isinstance(_from[y], dict):
# _to[y] = AttrDict()
# self._assign_dict(_from[y], _to[y])
# else:
# _to[y] = _from[y]
#
log.set_attribute(min_level=self['log_level'])
return True
_g_cfg = ConfigFile()
del ConfigFile

View File

@ -234,17 +234,16 @@ class SwxCore:
# else:
# log.set_attribute(console=False, filename='/var/log/eom_ts/ts-backend.log')
log.v('Web Server start on http://127.0.0.1:{}\n'.format(cfg.server_port))
server = tornado.httpserver.HTTPServer(web_app)
try:
server.listen(cfg.server_port)
log.i('works on [http://127.0.0.1:{}]\n'.format(cfg.server_port))
except:
log.e('Can not listen on port {}, maybe it been used by another application.\n'.format(cfg.server_port))
return 0
# if not cfg.dev_mode:
# log_file = os.path.join(cfg.log_path, 'ts-web.log')
# log_file = os.path.join(cfg.log_path, 'tpweb.log')
# log.set_attribute(console=False, filename=log_file)
tornado.ioloop.IOLoop.instance().start()

View File

@ -5,7 +5,7 @@ import platform
import atexit
import sys
import threading
import time
# import time
import traceback
__all__ = ['log',
@ -107,7 +107,6 @@ class EomLogger:
self._trace_error = TRACE_ERROR_NONE # 记录错误信息时,是否追加记录调用栈
self._log_datetime = True # 是否记录日志时间
self._file_handle = None # 日志文件的句柄为None时表示不记录到文件
self._log_console = self._console_default # 输出到控制台的方式为None时表示不输出到控制台
self._win_color = None
@ -186,31 +185,6 @@ class EomLogger:
self._log_console = self._log_pass
return
# if sys.platform == 'linux' or sys.platform == 'darwin':
# self._log_console = self._console_linux
# elif sys.platform == 'win32':
#
# if sys.stdout is None:
# self._dbg_view = Win32DebugView()
# if self._dbg_view.available():
# self._log_console = self._dbg_view.output
#
# self.log('use DebugView as logger output.\n')
# # self._log_console = self._func_pass
#
#
# else:
# # if 'TERM' in os.environ and 'emacs' != os.environ['TERM']:
# # self._log_console = self._console_linux
#
# # self._win_color = Win32ColorConsole()
# # if self._win_color.available():
# # self._log_console = self._console_win
# # else:
# # self._log_console = self._console_linux
#
# self._log_console = self._console_linux
# python2.7 on Ubuntu, sys.platform is 'linux2', so we use platform.system() instead.
_platform = platform.system().lower()
@ -219,7 +193,6 @@ class EomLogger:
self._console_set_color = self._console_set_color_linux
self._console_restore_color = self._console_restore_color_linux
elif _platform == 'windows':
# print(os.environ)
if 'TERM' in os.environ and os.environ['TERM'] in ['xterm', 'emacs']:
self._console_set_color = self._console_set_color_linux
self._console_restore_color = self._console_restore_color_linux
@ -281,9 +254,7 @@ class EomLogger:
def _log_error(self, *args, **kwargs):
self._console_set_color(CR_ERROR)
# self._do_log(LOG_ERROR, *args, **kwargs)
self._do_log(LOG_ERROR, '[ERROR] ', *args, **kwargs)
self._do_log(LOG_ERROR, *args, **kwargs)
if self._trace_error == TRACE_ERROR_NONE:
return
@ -315,7 +286,7 @@ class EomLogger:
# if not first:
# tpweb.log_output(level, sep)
first = False
# first = False
if isinstance(x, str):
tpweb.log_output(level, x)
continue
@ -329,14 +300,7 @@ class EomLogger:
if level < self._min_level:
return
# sep = kwargs['sep'] if 'sep' in kwargs else self._sep
# end = kwargs['end'] if 'end' in kwargs else self._end
# first = True
for x in args:
# if not first:
# sys.stdout.writelines(sep)
first = False
if isinstance(x, str):
sys.stdout.writelines(x)
continue
@ -344,20 +308,17 @@ class EomLogger:
else:
sys.stdout.writelines(x.__str__())
# sys.stdout.writelines(end)
# sys.stdout.flush()
def _console_set_color_win(self, cr=None):
if cr is None:
if cr is None or USE_TPWEB_LOG:
return
self._win_color.set_color(COLORS[cr][1])
sys.stdout.flush()
def _console_set_color_linux(self, cr=None):
if cr is None:
return
sys.stdout.writelines('\x1B')
sys.stdout.writelines(COLORS[cr][0])
if not USE_TPWEB_LOG:
sys.stdout.writelines('\x1B')
sys.stdout.writelines(COLORS[cr][0])
sys.stdout.flush()
def _console_restore_color_win(self):
@ -461,79 +422,79 @@ class EomLogger:
# except IOError:
# pass
def _console_default(self, msg, color=None):
"""
Log to console without color.
"""
if not self._log_console:
return
if msg is None:
return
# def _console_default(self, msg, color=None):
# """
# Log to console without color.
# """
# if not self._log_console:
# return
# if msg is None:
# return
#
# sys.stdout.writelines(msg)
# sys.stdout.flush()
sys.stdout.writelines(msg)
sys.stdout.flush()
def _console_win(self, msg, color=None):
if not self._log_console:
return
if msg is None:
msg = ''
# 这里的问题很复杂,日常使用没有问题,但是当在工作机上使用时,部分内容是捕获另一个脚本执行的结果再输出
# 如果结果中有中文,这里就会显示乱码。如果尝试编码转换,会抛出异常。目前暂时采用显示乱码的方式了。
# if CONSOLE_WIN_CMD == self.console_type:
# try:
# _msg = unicode(msg, 'utf-8')
# except:
# _msg = msg
# else:
# _msg = msg
# _msg = None
# if isinstance(msg, unicode):
# _msg = msg
# else:
# # _msg = unicode(msg, 'utf-8')
# try:
# _msg = unicode(msg, 'utf-8')
# except:
# _msg = unicode(msg, 'gb2312')
# # _msg = msg
#
# # if CONSOLE_WIN_CMD == self.console_type:
# # sys.stdout.writelines(msg.encode('gb2312'))
# # else:
# # sys.stdout.writelines(msg.encode('utf-8'))
#
#
# # try:
# # _msg = unicode(msg, 'utf-8')
# # except:
# _msg = msg
if color is None:
sys.stdout.writelines(msg)
else:
self._win_color.set_color(COLORS[color][1])
sys.stdout.writelines(msg)
sys.stdout.flush()
self._win_color.set_color(COLORS[CR_NORMAL][1])
sys.stdout.flush()
def _console_linux(self, msg, cr=None):
if not self._log_console:
return
if msg is None:
return
if cr is None:
sys.stdout.writelines(msg)
else:
sys.stdout.writelines('\x1B%s%s\x1B[0m' % (COLORS[cr][0], msg))
# sys.stdout.writelines('\[%s%s\[[0m' % (COLORS[cr][0], msg))
sys.stdout.flush()
# def _console_win(self, msg, color=None):
# if not self._log_console:
# return
# if msg is None:
# msg = ''
#
# # 这里的问题很复杂,日常使用没有问题,但是当在工作机上使用时,部分内容是捕获另一个脚本执行的结果再输出
# # 如果结果中有中文,这里就会显示乱码。如果尝试编码转换,会抛出异常。目前暂时采用显示乱码的方式了。
#
# # if CONSOLE_WIN_CMD == self.console_type:
# # try:
# # _msg = unicode(msg, 'utf-8')
# # except:
# # _msg = msg
# # else:
# # _msg = msg
# # _msg = None
# # if isinstance(msg, unicode):
# # _msg = msg
# # else:
# # # _msg = unicode(msg, 'utf-8')
# # try:
# # _msg = unicode(msg, 'utf-8')
# # except:
# # _msg = unicode(msg, 'gb2312')
# # # _msg = msg
# #
# # # if CONSOLE_WIN_CMD == self.console_type:
# # # sys.stdout.writelines(msg.encode('gb2312'))
# # # else:
# # # sys.stdout.writelines(msg.encode('utf-8'))
# #
# #
# # # try:
# # # _msg = unicode(msg, 'utf-8')
# # # except:
# # _msg = msg
#
# if color is None:
# sys.stdout.writelines(msg)
# else:
# self._win_color.set_color(COLORS[color][1])
# sys.stdout.writelines(msg)
# sys.stdout.flush()
# self._win_color.set_color(COLORS[CR_NORMAL][1])
#
# sys.stdout.flush()
#
# def _console_linux(self, msg, cr=None):
# if not self._log_console:
# return
# if msg is None:
# return
#
# if cr is None:
# sys.stdout.writelines(msg)
# else:
# sys.stdout.writelines('\x1B%s%s\x1B[0m' % (COLORS[cr][0], msg))
# # sys.stdout.writelines('\[%s%s\[[0m' % (COLORS[cr][0], msg))
#
# sys.stdout.flush()
def _log_file(self, msg):
if self._file_handle is None:
@ -544,7 +505,7 @@ class EomLogger:
self._file_handle.write(msg)
self._file_handle.flush()
def _log_print(self, *args, **kwargs):
def log_print(self, *args, **kwargs):
sep = kwargs['sep'] if 'sep' in kwargs else ' '
end = kwargs['end'] if 'end' in kwargs else '\n'
@ -668,4 +629,4 @@ del EomLogger
import builtins
builtins.__dict__['print'] = log._log_print
builtins.__dict__['print'] = log.log_print

View File

@ -33,10 +33,14 @@ path_of_this_file = os.path.abspath(os.path.dirname(__file__))
PATH_APP_ROOT = os.path.abspath(os.path.join(path_of_this_file, '..'))
# 如果没有打包,可能是开发版本,也可能是发布源代码版本,需要进一步判断
if os.path.exists(os.path.join(PATH_APP_ROOT, '..', 'packages', 'packages-common')):
if os.path.exists(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'etc')):
DEV_MODE = True
else:
elif os.path.exists(os.path.join(PATH_APP_ROOT, '..', '..', 'etc')):
DEV_MODE = False
else:
print('invalid installation.\n')
sys.exit(1)
if DEV_MODE:
# 开发调试模式
@ -54,39 +58,14 @@ if DEV_MODE:
PATH_DATA = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'data'))
else:
# 未打包的发布路径(发布源代码)
# web_root
# |- app
# | |- eom_common
# | \- eom_app
# |- static
# |- view
# \- packages
# |- packages-common
# \- packages-windows or packages-linux
# --------------------------------------------------------------
# 打包后的发布路径
# web_root
# |- app.zip
# |- static
# |- view
# \- packages
# |- packages-common
# \- packages-windows or packages-linux
_ext_path = os.path.abspath(os.path.join(PATH_APP_ROOT, 'packages', 'packages-common'))
_ext_path = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', 'packages', 'packages-common'))
if _ext_path not in sys.path:
sys.path.append(_ext_path)
# print('add path: ', _ext_path)
_ext_path = os.path.abspath(os.path.join(PATH_APP_ROOT, 'packages', 'packages-{}'.format(PLATFORM), BITS))
_ext_path = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', 'packages', 'packages-{}'.format(PLATFORM), BITS))
if _ext_path not in sys.path:
sys.path.append(_ext_path)
# print('add path: ', _ext_path)
PATH_LOG = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'log'))
PATH_CONF = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'etc'))
PATH_DATA = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'data'))
# if PLATFORM == 'linux':
# PATH_LOG = '/var/log/eom/teleport'

View File

@ -4,9 +4,9 @@ import os
import sys
from eom_env import *
import eom_app.app as app
from eom_common.eomcore.logger import *
# from eom_common.eomcore.logger import *
log.set_attribute(min_level=LOG_DEBUG, trace_error=TRACE_ERROR_FULL)
# log.set_attribute(min_level=LOG_INFO, trace_error=TRACE_ERROR_NONE)
def main():