mirror of https://github.com/midoks/mdserver-web
parent
e25804998d
commit
7c0d0f4a07
@ -0,0 +1,201 @@ |
||||
Apache License |
||||
Version 2.0, January 2004 |
||||
http://www.apache.org/licenses/ |
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
||||
1. Definitions. |
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, |
||||
and distribution as defined by Sections 1 through 9 of this document. |
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by |
||||
the copyright owner that is granting the License. |
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all |
||||
other entities that control, are controlled by, or are under common |
||||
control with that entity. For the purposes of this definition, |
||||
"control" means (i) the power, direct or indirect, to cause the |
||||
direction or management of such entity, whether by contract or |
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||
outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity |
||||
exercising permissions granted by this License. |
||||
|
||||
"Source" form shall mean the preferred form for making modifications, |
||||
including but not limited to software source code, documentation |
||||
source, and configuration files. |
||||
|
||||
"Object" form shall mean any form resulting from mechanical |
||||
transformation or translation of a Source form, including but |
||||
not limited to compiled object code, generated documentation, |
||||
and conversions to other media types. |
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or |
||||
Object form, made available under the License, as indicated by a |
||||
copyright notice that is included in or attached to the work |
||||
(an example is provided in the Appendix below). |
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object |
||||
form, that is based on (or derived from) the Work and for which the |
||||
editorial revisions, annotations, elaborations, or other modifications |
||||
represent, as a whole, an original work of authorship. For the purposes |
||||
of this License, Derivative Works shall not include works that remain |
||||
separable from, or merely link (or bind by name) to the interfaces of, |
||||
the Work and Derivative Works thereof. |
||||
|
||||
"Contribution" shall mean any work of authorship, including |
||||
the original version of the Work and any modifications or additions |
||||
to that Work or Derivative Works thereof, that is intentionally |
||||
submitted to Licensor for inclusion in the Work by the copyright owner |
||||
or by an individual or Legal Entity authorized to submit on behalf of |
||||
the copyright owner. For the purposes of this definition, "submitted" |
||||
means any form of electronic, verbal, or written communication sent |
||||
to the Licensor or its representatives, including but not limited to |
||||
communication on electronic mailing lists, source code control systems, |
||||
and issue tracking systems that are managed by, or on behalf of, the |
||||
Licensor for the purpose of discussing and improving the Work, but |
||||
excluding communication that is conspicuously marked or otherwise |
||||
designated in writing by the copyright owner as "Not a Contribution." |
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity |
||||
on behalf of whom a Contribution has been received by Licensor and |
||||
subsequently incorporated within the Work. |
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of |
||||
this License, each Contributor hereby grants to You a perpetual, |
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
copyright license to reproduce, prepare Derivative Works of, |
||||
publicly display, publicly perform, sublicense, and distribute the |
||||
Work and such Derivative Works in Source or Object form. |
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of |
||||
this License, each Contributor hereby grants to You a perpetual, |
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
(except as stated in this section) patent license to make, have made, |
||||
use, offer to sell, sell, import, and otherwise transfer the Work, |
||||
where such license applies only to those patent claims licensable |
||||
by such Contributor that are necessarily infringed by their |
||||
Contribution(s) alone or by combination of their Contribution(s) |
||||
with the Work to which such Contribution(s) was submitted. If You |
||||
institute patent litigation against any entity (including a |
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work |
||||
or a Contribution incorporated within the Work constitutes direct |
||||
or contributory patent infringement, then any patent licenses |
||||
granted to You under this License for that Work shall terminate |
||||
as of the date such litigation is filed. |
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the |
||||
Work or Derivative Works thereof in any medium, with or without |
||||
modifications, and in Source or Object form, provided that You |
||||
meet the following conditions: |
||||
|
||||
(a) You must give any other recipients of the Work or |
||||
Derivative Works a copy of this License; and |
||||
|
||||
(b) You must cause any modified files to carry prominent notices |
||||
stating that You changed the files; and |
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works |
||||
that You distribute, all copyright, patent, trademark, and |
||||
attribution notices from the Source form of the Work, |
||||
excluding those notices that do not pertain to any part of |
||||
the Derivative Works; and |
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its |
||||
distribution, then any Derivative Works that You distribute must |
||||
include a readable copy of the attribution notices contained |
||||
within such NOTICE file, excluding those notices that do not |
||||
pertain to any part of the Derivative Works, in at least one |
||||
of the following places: within a NOTICE text file distributed |
||||
as part of the Derivative Works; within the Source form or |
||||
documentation, if provided along with the Derivative Works; or, |
||||
within a display generated by the Derivative Works, if and |
||||
wherever such third-party notices normally appear. The contents |
||||
of the NOTICE file are for informational purposes only and |
||||
do not modify the License. You may add Your own attribution |
||||
notices within Derivative Works that You distribute, alongside |
||||
or as an addendum to the NOTICE text from the Work, provided |
||||
that such additional attribution notices cannot be construed |
||||
as modifying the License. |
||||
|
||||
You may add Your own copyright statement to Your modifications and |
||||
may provide additional or different license terms and conditions |
||||
for use, reproduction, or distribution of Your modifications, or |
||||
for any such Derivative Works as a whole, provided Your use, |
||||
reproduction, and distribution of the Work otherwise complies with |
||||
the conditions stated in this License. |
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, |
||||
any Contribution intentionally submitted for inclusion in the Work |
||||
by You to the Licensor shall be under the terms and conditions of |
||||
this License, without any additional terms or conditions. |
||||
Notwithstanding the above, nothing herein shall supersede or modify |
||||
the terms of any separate license agreement you may have executed |
||||
with Licensor regarding such Contributions. |
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade |
||||
names, trademarks, service marks, or product names of the Licensor, |
||||
except as required for reasonable and customary use in describing the |
||||
origin of the Work and reproducing the content of the NOTICE file. |
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or |
||||
agreed to in writing, Licensor provides the Work (and each |
||||
Contributor provides its Contributions) on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||
implied, including, without limitation, any warranties or conditions |
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
||||
PARTICULAR PURPOSE. You are solely responsible for determining the |
||||
appropriateness of using or redistributing the Work and assume any |
||||
risks associated with Your exercise of permissions under this License. |
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, |
||||
whether in tort (including negligence), contract, or otherwise, |
||||
unless required by applicable law (such as deliberate and grossly |
||||
negligent acts) or agreed to in writing, shall any Contributor be |
||||
liable to You for damages, including any direct, indirect, special, |
||||
incidental, or consequential damages of any character arising as a |
||||
result of this License or out of the use or inability to use the |
||||
Work (including but not limited to damages for loss of goodwill, |
||||
work stoppage, computer failure or malfunction, or any and all |
||||
other commercial damages or losses), even if such Contributor |
||||
has been advised of the possibility of such damages. |
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing |
||||
the Work or Derivative Works thereof, You may choose to offer, |
||||
and charge a fee for, acceptance of support, warranty, indemnity, |
||||
or other liability obligations and/or rights consistent with this |
||||
License. However, in accepting such obligations, You may act only |
||||
on Your own behalf and on Your sole responsibility, not on behalf |
||||
of any other Contributor, and only if You agree to indemnify, |
||||
defend, and hold each Contributor harmless for any liability |
||||
incurred by, or claims asserted against, such Contributor by reason |
||||
of your accepting any such warranty or additional liability. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
APPENDIX: How to apply the Apache License to your work. |
||||
|
||||
To apply the Apache License to your work, attach the following |
||||
boilerplate notice, with the fields enclosed by brackets "[]" |
||||
replaced with your own identifying information. (Don't include |
||||
the brackets!) The text should be enclosed in the appropriate |
||||
comment syntax for the file format. We also recommend that a |
||||
file or class name and description of purpose be included on the |
||||
same "printed page" as the copyright notice for easier |
||||
identification within third-party archives. |
||||
|
||||
Copyright [yyyy] [name of copyright owner] |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
@ -0,0 +1,6 @@ |
||||
# gorse |
||||
推荐系统 |
||||
|
||||
|
||||
# 脚本安装 |
||||
cd /www/server/mdserver-web/plugins && rm -rf gorse && git clone https://github.com/mw-plugin/gorse && cd gorse && rm -rf .git && cd /www/server/mdserver-web/plugins/gorse && bash install.sh install 0.4.15 |
@ -0,0 +1,90 @@ |
||||
[database] |
||||
cache_store = "{$CONFIG_REDIS}" |
||||
data_store = "mongodb://127.0.0.1:27017/gorse" |
||||
|
||||
table_prefix = "gorse_" |
||||
cache_table_prefix = "gorse_" |
||||
data_table_prefix = "gorse_" |
||||
|
||||
[master] |
||||
port = 8086 |
||||
host = "0.0.0.0" |
||||
http_port = 8088 |
||||
http_host = "0.0.0.0" |
||||
http_cors_domains = [] |
||||
http_cors_methods = [] |
||||
n_jobs = 1 |
||||
meta_timeout = "10s" |
||||
dashboard_user_name = "{$CONFIG_ADMIN}" |
||||
dashboard_password = "{$CONFIG_PASS}" |
||||
admin_api_key = "" |
||||
|
||||
[server] |
||||
default_n = 10 |
||||
api_key = "" |
||||
clock_error = "5s" |
||||
auto_insert_user = true |
||||
auto_insert_item = true |
||||
cache_expire = "10s" |
||||
|
||||
[recommend] |
||||
cache_size = 100 |
||||
cache_expire = "72h" |
||||
|
||||
[recommend.data_source] |
||||
positive_feedback_types = ["star","like"] |
||||
read_feedback_types = ["read"] |
||||
positive_feedback_ttl = 0 |
||||
item_ttl = 0 |
||||
|
||||
[recommend.popular] |
||||
popular_window = "720h" |
||||
|
||||
[recommend.user_neighbors] |
||||
neighbor_type = "similar" |
||||
enable_index = true |
||||
index_recall = 0.8 |
||||
index_fit_epoch = 3 |
||||
|
||||
[recommend.item_neighbors] |
||||
neighbor_type = "similar" |
||||
enable_index = true |
||||
index_recall = 0.8 |
||||
index_fit_epoch = 3 |
||||
|
||||
[recommend.collaborative] |
||||
enable_index = true |
||||
index_recall = 0.9 |
||||
index_fit_epoch = 3 |
||||
model_fit_period = "60m" |
||||
model_search_period = "360m" |
||||
model_search_epoch = 100 |
||||
model_search_trials = 10 |
||||
enable_model_size_search = false |
||||
|
||||
[recommend.replacement] |
||||
enable_replacement = false |
||||
positive_replacement_decay = 0.8 |
||||
read_replacement_decay = 0.6 |
||||
|
||||
[recommend.offline] |
||||
check_recommend_period = "1m" |
||||
refresh_recommend_period = "24h" |
||||
enable_latest_recommend = true |
||||
enable_popular_recommend = false |
||||
enable_user_based_recommend = true |
||||
enable_item_based_recommend = false |
||||
enable_collaborative_recommend = true |
||||
enable_click_through_prediction = true |
||||
explore_recommend = { popular = 0.1, latest = 0.2 } |
||||
|
||||
[recommend.online] |
||||
fallback_recommend = ["item_based", "latest"] |
||||
num_feedback_fallback_item_based = 10 |
||||
|
||||
[tracing] |
||||
enable_tracing = false |
||||
exporter = "jaeger" |
||||
collector_endpoint = "http://localhost:14268/api/traces" |
||||
sampler = "always" |
||||
ratio = 1 |
After Width: | Height: | Size: 6.3 KiB |
@ -0,0 +1,30 @@ |
||||
<style> |
||||
.overflow_hide { |
||||
overflow: hidden; |
||||
text-overflow: ellipsis; |
||||
white-space: nowrap; |
||||
vertical-align: middle; |
||||
} |
||||
</style> |
||||
|
||||
<div class="bt-form"> |
||||
<div class='plugin_version'></div> |
||||
<div class="bt-w-main"> |
||||
<div class="bt-w-menu"> |
||||
<p class="bgw" onclick="pluginService('gorse');">服务</p> |
||||
<p onclick="pluginInitD('gorse');">自启动</p> |
||||
<p onclick="pluginConfigTpl('gorse',$('.plugin_version').attr('version'));">配置修改</p> |
||||
<p onclick="pluginLogs('gorse','','run_log');">运行日志</p> |
||||
<p onclick="gorseReadme();">相关说明</p> |
||||
|
||||
</div> |
||||
<div class="bt-w-con pd15"> |
||||
<div class="soft-man-con" style="height: 520px; overflow: auto;"></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<script type="text/javascript"> |
||||
$.getScript( "/plugins/file?name=gorse&f=js/gorse.js", function(){ |
||||
pluginService('gorse', $('.plugin_version').attr('version')); |
||||
}); |
||||
</script> |
@ -0,0 +1,342 @@ |
||||
# coding:utf-8 |
||||
|
||||
import sys |
||||
import io |
||||
import os |
||||
import time |
||||
import re |
||||
|
||||
sys.path.append(os.getcwd() + "/class/core") |
||||
import mw |
||||
|
||||
app_debug = False |
||||
if mw.isAppleSystem(): |
||||
app_debug = True |
||||
|
||||
|
||||
def getPluginName(): |
||||
return 'gorse' |
||||
|
||||
|
||||
def getPluginDir(): |
||||
return mw.getPluginDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getServerDir(): |
||||
return mw.getServerDir() + '/' + getPluginName() |
||||
|
||||
|
||||
def getInitDFile(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return '/tmp/' + getPluginName() |
||||
|
||||
if current_os.startswith('freebsd'): |
||||
return '/etc/rc.d/' + getPluginName() |
||||
|
||||
return '/etc/init.d/' + getPluginName() |
||||
|
||||
|
||||
def getConf(): |
||||
path = getServerDir() + "/gorse.toml" |
||||
return path |
||||
|
||||
|
||||
def getConfTpl(): |
||||
path = getPluginDir() + "/config/gorse.toml" |
||||
return path |
||||
|
||||
|
||||
def getInitDTpl(): |
||||
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" |
||||
return path |
||||
|
||||
|
||||
def getArgs(): |
||||
args = sys.argv[3:] |
||||
tmp = {} |
||||
args_len = len(args) |
||||
|
||||
if args_len == 1: |
||||
t = args[0].strip('{').strip('}') |
||||
if t.strip() == '': |
||||
tmp = [] |
||||
else: |
||||
t = t.split(':',1) |
||||
tmp[t[0]] = t[1] |
||||
tmp[t[0]] = t[1] |
||||
elif args_len > 1: |
||||
for i in range(len(args)): |
||||
t = args[i].split(':',1) |
||||
tmp[t[0]] = t[1] |
||||
return tmp |
||||
|
||||
def checkArgs(data, ck=[]): |
||||
for i in range(len(ck)): |
||||
if not ck[i] in data: |
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) |
||||
return (True, mw.returnJson(True, 'ok')) |
||||
|
||||
def configTpl(): |
||||
path = getPluginDir() + '/tpl' |
||||
pathFile = os.listdir(path) |
||||
tmp = [] |
||||
for one in pathFile: |
||||
file = path + '/' + one |
||||
tmp.append(file) |
||||
return mw.getJson(tmp) |
||||
|
||||
|
||||
def readConfigTpl(): |
||||
args = getArgs() |
||||
data = checkArgs(args, ['file']) |
||||
if not data[0]: |
||||
return data[1] |
||||
|
||||
content = mw.readFile(args['file']) |
||||
content = contentReplace(content) |
||||
return mw.returnJson(True, 'ok', content) |
||||
|
||||
def getPidFile(): |
||||
file = getConf() |
||||
content = mw.readFile(file) |
||||
rep = r'pidfile\s*(.*)' |
||||
tmp = re.search(rep, content) |
||||
return tmp.groups()[0].strip() |
||||
|
||||
def status(): |
||||
# pid_file = getPidFile() |
||||
# if not os.path.exists(pid_file): |
||||
# return 'stop' |
||||
|
||||
cmd = "ps aux|grep gorse |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'" |
||||
data = mw.execShell(cmd) |
||||
|
||||
if data[0] == '': |
||||
return 'stop' |
||||
return 'start' |
||||
|
||||
|
||||
def initRedisConf(): |
||||
requirepass = "" |
||||
conf = mw.getServerDir() + '/redis/redis.conf' |
||||
content = mw.readFile(conf) |
||||
rep = r"^(requirepass" + r')\s*([.0-9A-Za-z_& ~]+)' |
||||
tmp = re.search(rep, content, re.M) |
||||
if tmp: |
||||
requirepass = tmp.groups()[1] |
||||
|
||||
port = "6379" |
||||
rep = r"^(port)\s*([.0-9A-Za-z_& ~]+)" |
||||
tmp = re.search(rep, content, re.M) |
||||
if tmp: |
||||
port = tmp.groups()[1] |
||||
|
||||
return 'redis://:'+requirepass+'@127.0.0.1:'+port+'/3' |
||||
|
||||
def contentReplace(content): |
||||
service_path = mw.getServerDir() |
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir()) |
||||
content = content.replace('{$SERVER_PATH}', service_path) |
||||
content = content.replace('{$CONFIG_ADMIN}', mw.getRandomString(6)) |
||||
content = content.replace('{$CONFIG_PASS}', mw.getRandomString(10)) |
||||
content = content.replace('{$CONFIG_REDIS}', initRedisConf()) |
||||
return content |
||||
|
||||
|
||||
def initDreplace(): |
||||
|
||||
file_tpl = getInitDTpl() |
||||
service_path = os.path.dirname(os.getcwd()) |
||||
|
||||
initD_path = getServerDir() + '/init.d' |
||||
if not os.path.exists(initD_path): |
||||
mw.execShell("mkdir -p " + initD_path) |
||||
|
||||
file_bin = initD_path + '/' + getPluginName() |
||||
|
||||
# initd replace |
||||
if not os.path.exists(file_bin): |
||||
content = mw.readFile(file_tpl) |
||||
content = content.replace('{$SERVER_PATH}', service_path) |
||||
mw.writeFile(file_bin, content) |
||||
mw.execShell('chmod +x ' + file_bin) |
||||
|
||||
# log |
||||
dataLog = getServerDir() + '/data' |
||||
if not os.path.exists(dataLog): |
||||
mw.execShell('chmod +x ' + file_bin) |
||||
|
||||
# config replace |
||||
dst_conf = getServerDir() + '/gorse.toml' |
||||
dst_conf_init = getServerDir() + '/init.pl' |
||||
if not os.path.exists(dst_conf_init): |
||||
content = mw.readFile(getConfTpl()) |
||||
content = content.replace('{$SERVER_PATH}', service_path) |
||||
content = contentReplace(content) |
||||
mw.writeFile(dst_conf, content) |
||||
mw.writeFile(dst_conf_init, 'ok') |
||||
|
||||
# systemd |
||||
systemDir = mw.systemdCfgDir() |
||||
systemService = systemDir + '/' + getPluginName() + '.service' |
||||
if os.path.exists(systemDir) and not os.path.exists(systemService): |
||||
systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl' |
||||
service_path = mw.getServerDir() |
||||
content = mw.readFile(systemServiceTpl) |
||||
content = content.replace('{$SERVER_PATH}', service_path) |
||||
mw.writeFile(systemService, se_content) |
||||
mw.execShell('systemctl daemon-reload') |
||||
|
||||
return file_bin |
||||
|
||||
|
||||
def gorseOp(method): |
||||
file = initDreplace() |
||||
|
||||
# print(file) |
||||
|
||||
current_os = mw.getOs() |
||||
if current_os == "darwin": |
||||
data = mw.execShell(file + ' ' + method) |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
if current_os.startswith("freebsd"): |
||||
data = mw.execShell('service ' + getPluginName() + ' ' + method) |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
data = mw.execShell('systemctl ' + method + ' ' + getPluginName()) |
||||
if data[1] == '': |
||||
return 'ok' |
||||
return data[1] |
||||
|
||||
|
||||
def start(): |
||||
return gorseOp('start') |
||||
|
||||
|
||||
def stop(): |
||||
return gorseOp('stop') |
||||
|
||||
|
||||
def restart(): |
||||
status = gorseOp('restart') |
||||
log_file = runLog() |
||||
mw.execShell("echo '' > " + log_file) |
||||
return status |
||||
|
||||
|
||||
def reload(): |
||||
return gorseOp('reload') |
||||
|
||||
|
||||
def getPort(): |
||||
conf = getServerDir() + '/gorse.conf' |
||||
content = mw.readFile(conf) |
||||
|
||||
rep = "^(" + 'port' + ')\s*([.0-9A-Za-z_& ~]+)' |
||||
tmp = re.search(rep, content, re.M) |
||||
if tmp: |
||||
return tmp.groups()[1] |
||||
|
||||
return '6379' |
||||
|
||||
|
||||
def initdStatus(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
if current_os.startswith('freebsd'): |
||||
initd_bin = getInitDFile() |
||||
if os.path.exists(initd_bin): |
||||
return 'ok' |
||||
|
||||
shell_cmd = 'systemctl status ' + getPluginName() + ' | grep loaded | grep "enabled;"' |
||||
data = mw.execShell(shell_cmd) |
||||
if data[0] == '': |
||||
return 'fail' |
||||
return 'ok' |
||||
|
||||
|
||||
def initdInstall(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
# freebsd initd install |
||||
if current_os.startswith('freebsd'): |
||||
import shutil |
||||
source_bin = initDreplace() |
||||
initd_bin = getInitDFile() |
||||
shutil.copyfile(source_bin, initd_bin) |
||||
mw.execShell('chmod +x ' + initd_bin) |
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="YES"') |
||||
return 'ok' |
||||
|
||||
mw.execShell('systemctl enable ' + getPluginName()) |
||||
return 'ok' |
||||
|
||||
|
||||
def initdUinstall(): |
||||
current_os = mw.getOs() |
||||
if current_os == 'darwin': |
||||
return "Apple Computer does not support" |
||||
|
||||
if current_os.startswith('freebsd'): |
||||
initd_bin = getInitDFile() |
||||
os.remove(initd_bin) |
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="NO"') |
||||
return 'ok' |
||||
|
||||
mw.execShell('systemctl disable ' + getPluginName()) |
||||
return 'ok' |
||||
|
||||
|
||||
def runLog(): |
||||
return getServerDir() + '/logs.pl' |
||||
|
||||
def installPreInspection(): |
||||
redis_path = mw.getServerDir() + "/redis" |
||||
if not os.path.exists(redis_path): |
||||
return "默认需要安装Redis" |
||||
|
||||
mongodb_path = mw.getServerDir() + "/mongodb" |
||||
if not os.path.exists(mongodb_path): |
||||
return "默认需要安装MongoDB" |
||||
return 'ok' |
||||
|
||||
if __name__ == "__main__": |
||||
func = sys.argv[1] |
||||
if func == 'status': |
||||
print(status()) |
||||
elif func == 'start': |
||||
print(start()) |
||||
elif func == 'stop': |
||||
print(stop()) |
||||
elif func == 'restart': |
||||
print(restart()) |
||||
elif func == 'reload': |
||||
print(reload()) |
||||
elif func == 'initd_status': |
||||
print(initdStatus()) |
||||
elif func == 'initd_install': |
||||
print(initdInstall()) |
||||
elif func == 'initd_uninstall': |
||||
print(initdUinstall()) |
||||
elif func == 'install_pre_inspection': |
||||
print(installPreInspection()) |
||||
elif func == 'conf': |
||||
print(getConf()) |
||||
elif func == 'run_log': |
||||
print(runLog()) |
||||
elif func == 'config_tpl': |
||||
print(configTpl()) |
||||
elif func == 'read_config_tpl': |
||||
print(readConfigTpl()) |
||||
else: |
||||
print('error') |
@ -0,0 +1,18 @@ |
||||
{ |
||||
"sort": 7, |
||||
"ps": "一款高效简单的推荐系统[单机]", |
||||
"name": "gorse", |
||||
"title": "Gorse", |
||||
"shell": "install.sh", |
||||
"versions":["0.4.15"], |
||||
"tip": "soft", |
||||
"install_pre_inspection":true, |
||||
"checks": "server/gorse", |
||||
"path": "server/gorse", |
||||
"display": 1, |
||||
"author": "midoks", |
||||
"date": "2024-06-12", |
||||
"home": "https://gorse.io/zh/docs/master/deploy/binary.html", |
||||
"type": 0, |
||||
"pid": "5" |
||||
} |
@ -0,0 +1,13 @@ |
||||
[Unit] |
||||
Description=Gorse, an open source recommender system service written in Go. |
||||
After=network.target |
||||
|
||||
[Service] |
||||
Type=simple |
||||
Restart=always |
||||
ExecStart={$SERVER_PATH}/gorse/bin/gorse-in-one -c {$SERVER_PATH}/gorse/gorse.toml \ |
||||
--log-path {$SERVER_PATH}/gorse/gorse.log \ |
||||
--cache-path {$SERVER_PATH}/gorse/data/cache.data |
||||
|
||||
[Install] |
||||
WantedBy=multi-user.target |
@ -0,0 +1,57 @@ |
||||
#!/bin/sh |
||||
# chkconfig: 2345 55 25 |
||||
# description: Gorse Service |
||||
|
||||
### BEGIN INIT INFO |
||||
# Provides: Gorse |
||||
# Required-Start: $all |
||||
# Required-Stop: $all |
||||
# Default-Start: 2 3 4 5 |
||||
# Default-Stop: 0 1 6 |
||||
# Short-Description: starts Gorse |
||||
# Description: starts the MDW-Web |
||||
### END INIT INFO |
||||
|
||||
# Simple Gorse init.d script conceived to work on Linux systems |
||||
# as it does use of the /proc filesystem. |
||||
|
||||
CONF="{$SERVER_PATH}/gorse/gorse.toml" |
||||
|
||||
APP_DIR={$SERVER_PATH}/gorse |
||||
|
||||
app_start(){ |
||||
echo "Starting Gorse server..." |
||||
echo "$APP_DIR/bin/gorse-in-one -c $CONF" |
||||
nohup $APP_DIR/bin/gorse-in-one -c $CONF >> {$SERVER_PATH}/gorse/logs.pl 2>&1 & |
||||
} |
||||
|
||||
app_stop(){ |
||||
echo "Stopping ..." |
||||
|
||||
find_gorse=`ps -ef | grep gorse | grep -v grep | awk "{print $2}"` |
||||
for p in ${find_gorse[@]} |
||||
do |
||||
kill -9 $p > /dev/null 2>&1 |
||||
done |
||||
|
||||
echo "Gorse stopped" |
||||
} |
||||
|
||||
|
||||
case "$1" in |
||||
start) |
||||
app_start |
||||
;; |
||||
stop) |
||||
app_stop |
||||
;; |
||||
restart|reload) |
||||
app_stop |
||||
sleep 0.3 |
||||
app_start |
||||
;; |
||||
*) |
||||
echo "Please use start or stop as first argument" |
||||
;; |
||||
esac |
||||
|
@ -0,0 +1,97 @@ |
||||
#!/bin/bash |
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin |
||||
export PATH |
||||
|
||||
curPath=`pwd` |
||||
rootPath=$(dirname "$curPath") |
||||
rootPath=$(dirname "$rootPath") |
||||
serverPath=$(dirname "$rootPath") |
||||
sysName=`uname` |
||||
sysArch=`arch` |
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/gorse && bash install.sh install 0.4.15 |
||||
# cd /www/server/mdserver-web/plugins/gorse && bash install.sh install 0.4.15 |
||||
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl |
||||
VERSION=$2 |
||||
|
||||
Install_App() |
||||
{ |
||||
echo '正在安装脚本文件...' > $install_tmp |
||||
mkdir -p $serverPath/source |
||||
mkdir -p $serverPath/source/gorse |
||||
|
||||
SYSNAME=linux |
||||
if [ "$sysName" == "Darwin" ];then |
||||
SYSNAME=darwin |
||||
fi |
||||
|
||||
ARCH="amd64" |
||||
if [ "$sysArch" == "x86_64" ];then |
||||
ARCH="amd64" |
||||
elif [ "$sysArch" == "aarch64" ];then |
||||
ARCH="arm64" |
||||
elif [ "$sysArch" == "arm64" ];then |
||||
ARCH="arm64" |
||||
else |
||||
ARCH="amd64" |
||||
fi |
||||
|
||||
FILE_TGZ=gorse_${SYSNAME}_${ARCH}.zip |
||||
GORSE_DIR=$serverPath/source/gorse |
||||
|
||||
# https://github.com/gorse-io/gorse/releases/download/v0.4.15/gorse_linux_amd64.zip |
||||
echo "https://github.com/gorse-io/gorse/releases/download/v${VERSION}/${FILE_TGZ}" |
||||
|
||||
if [ ! -f $GORSE_DIR/${FILE_TGZ} ];then |
||||
wget -O $GORSE_DIR/${FILE_TGZ} https://github.com/gorse-io/gorse/releases/download/v${VERSION}/${FILE_TGZ} |
||||
fi |
||||
|
||||
mkdir -p $serverPath/gorse/bin |
||||
mkdir -p $serverPath/gorse/logs |
||||
cd $GORSE_DIR && unzip -d $serverPath/gorse/bin ${FILE_TGZ} |
||||
|
||||
mkdir -p $serverPath/gorse/data |
||||
echo "${VERSION}" > $serverPath/gorse/version.pl |
||||
echo '安装Gorse完成' |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/gorse/index.py start |
||||
cd ${rootPath} && python3 ${rootPath}/plugins/gorse/index.py initd_install |
||||
|
||||
if [ -d ${GORSE_DIR}/gorse-${VERSION} ];then |
||||
rm -rf ${GORSE_DIR}/gorse-${VERSION} |
||||
fi |
||||
} |
||||
|
||||
Uninstall_App() |
||||
{ |
||||
app_name=gorse |
||||
systemctl_dir=/lib/systemd/system |
||||
if [ -d /usr/lib/systemd/system ];then |
||||
systemctl_dir=/usr/lib/systemd/system |
||||
fi |
||||
|
||||
if [ -f ${systemctl_dir}/${app_name}.service ];then |
||||
systemctl stop ${app_name} |
||||
systemctl disable ${app_name} |
||||
rm -rf ${systemctl_dir}/${app_name}.service |
||||
systemctl daemon-reload |
||||
fi |
||||
|
||||
if [ -f $serverPath/${app_name}/initd/${app_name} ];then |
||||
$serverPath/${app_name}/initd/${app_name} stop |
||||
fi |
||||
|
||||
if [ -d $serverPath/${app_name} ];then |
||||
rm -rf $serverPath/${app_name} |
||||
fi |
||||
|
||||
echo "卸载Gorse成功" |
||||
} |
||||
|
||||
action=$1 |
||||
if [ "${1}" == 'install' ];then |
||||
Install_App |
||||
else |
||||
Uninstall_App |
||||
fi |
@ -0,0 +1,67 @@ |
||||
function gorsePost(method, version, args,callback){ |
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||
|
||||
var req_data = {}; |
||||
req_data['name'] = 'gorse'; |
||||
req_data['func'] = method; |
||||
req_data['version'] = version; |
||||
|
||||
if (typeof(args) == 'string'){ |
||||
req_data['args'] = JSON.stringify(toArrayObject(args)); |
||||
} else { |
||||
req_data['args'] = JSON.stringify(args); |
||||
} |
||||
|
||||
$.post('/plugins/run', req_data, function(data) { |
||||
layer.close(loadT); |
||||
if (!data.status){ |
||||
//错误展示10S
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); |
||||
return; |
||||
} |
||||
|
||||
if(typeof(callback) == 'function'){ |
||||
callback(data); |
||||
} |
||||
},'json');
|
||||
} |
||||
|
||||
function gorsePostCallbak(method, version, args,callback){ |
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||
|
||||
var req_data = {}; |
||||
req_data['name'] = 'gorse'; |
||||
req_data['func'] = method; |
||||
args['version'] = version; |
||||
|
||||
if (typeof(args) == 'string'){ |
||||
req_data['args'] = JSON.stringify(toArrayObject(args)); |
||||
} else { |
||||
req_data['args'] = JSON.stringify(args); |
||||
} |
||||
|
||||
$.post('/plugins/callback', req_data, function(data) { |
||||
layer.close(loadT); |
||||
if (!data.status){ |
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); |
||||
return; |
||||
} |
||||
|
||||
if(typeof(callback) == 'function'){ |
||||
callback(data); |
||||
} |
||||
},'json');
|
||||
} |
||||
|
||||
|
||||
function gorseReadme(){ |
||||
|
||||
|
||||
var readme = '<ul class="help-info-text c7">'; |
||||
readme += '<li>参考官方</li>'; |
||||
readme += '<li><a target="_blank" href="https://gorse.io">https://gorse.io</a></li>'; |
||||
readme += '</ul>'; |
||||
|
||||
$('.soft-man-con').html(readme);
|
||||
} |
||||
|
@ -0,0 +1,252 @@ |
||||
[database] |
||||
|
||||
# The database for caching, support Redis, MySQL, Postgres and MongoDB: |
||||
# redis://<user>:<password>@<host>:<port>/<db_number> |
||||
# rediss://<user>:<password>@<host>:<port>/<db_number> |
||||
# redis+cluster://<user>:<password>@<host1>:<port1>,<host2>:<port2>,...,<hostN>:<portN> |
||||
# postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full |
||||
# postgresql://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full |
||||
# mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] |
||||
# mongodb+srv://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] |
||||
cache_store = "redis://localhost:6379/0" |
||||
|
||||
# The database for persist data, support MySQL, Postgres, ClickHouse and MongoDB: |
||||
# mysql://[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN] |
||||
# postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full |
||||
# postgresql://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full |
||||
# clickhouse://user:password@host[:port]/database?param1=value1&...¶mN=valueN |
||||
# chhttp://user:password@host[:port]/database?param1=value1&...¶mN=valueN |
||||
# chhttps://user:password@host[:port]/database?param1=value1&...¶mN=valueN |
||||
# mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] |
||||
# mongodb+srv://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] |
||||
data_store = "mysql://gorse:gorse_pass@tcp(localhost:3306)/gorse" |
||||
|
||||
# The naming prefix for tables (collections, keys) in databases. The default value is empty. |
||||
table_prefix = "" |
||||
|
||||
# The naming prefix for tables (collections, keys) in cache storage databases. The default value is `table_prefix`. |
||||
cache_table_prefix = "" |
||||
|
||||
# The naming prefix for tables (collections, keys) in data storage databases. The default value is `table_prefix`. |
||||
data_table_prefix = "" |
||||
|
||||
[master] |
||||
|
||||
# GRPC port of the master node. The default value is 8086. |
||||
port = 8086 |
||||
|
||||
# gRPC host of the master node. The default values is "0.0.0.0". |
||||
host = "0.0.0.0" |
||||
|
||||
# HTTP port of the master node. The default values is 8088. |
||||
http_port = 8088 |
||||
|
||||
# HTTP host of the master node. The default values is "0.0.0.0". |
||||
http_host = "0.0.0.0" |
||||
|
||||
# AllowedDomains is a list of allowed values for Http Origin. |
||||
# The list may contain the special wildcard string ".*" ; all is allowed |
||||
# If empty all are allowed. |
||||
http_cors_domains = [] |
||||
|
||||
# AllowedMethods is either empty or has a list of http methods names. Checking is case-insensitive. |
||||
http_cors_methods = [] |
||||
|
||||
# Number of working jobs in the master node. The default value is 1. |
||||
n_jobs = 1 |
||||
|
||||
# Meta information timeout. The default value is 10s. |
||||
meta_timeout = "10s" |
||||
|
||||
# Username for the master node dashboard. |
||||
dashboard_user_name = "" |
||||
|
||||
# Password for the master node dashboard. |
||||
dashboard_password = "" |
||||
|
||||
# Secret key for admin APIs (SSL required). |
||||
admin_api_key = "" |
||||
|
||||
[server] |
||||
|
||||
# Default number of returned items. The default value is 10. |
||||
default_n = 10 |
||||
|
||||
# Secret key for RESTful APIs (SSL required). |
||||
api_key = "" |
||||
|
||||
# Clock error in the cluster. The default value is 5s. |
||||
clock_error = "5s" |
||||
|
||||
# Insert new users while inserting feedback. The default value is true. |
||||
auto_insert_user = true |
||||
|
||||
# Insert new items while inserting feedback. The default value is true. |
||||
auto_insert_item = true |
||||
|
||||
# Server-side cache expire time. The default value is 10s. |
||||
cache_expire = "10s" |
||||
|
||||
[recommend] |
||||
|
||||
# The cache size for recommended/popular/latest items. The default value is 10. |
||||
cache_size = 100 |
||||
|
||||
# Recommended cache expire time. The default value is 72h. |
||||
cache_expire = "72h" |
||||
|
||||
[recommend.data_source] |
||||
|
||||
# The feedback types for positive events. |
||||
positive_feedback_types = ["star","like"] |
||||
|
||||
# The feedback types for read events. |
||||
read_feedback_types = ["read"] |
||||
|
||||
# The time-to-live (days) of positive feedback, 0 means disabled. The default value is 0. |
||||
positive_feedback_ttl = 0 |
||||
|
||||
# The time-to-live (days) of items, 0 means disabled. The default value is 0. |
||||
item_ttl = 0 |
||||
|
||||
[recommend.popular] |
||||
|
||||
# The time window of popular items. The default values is 4320h. |
||||
popular_window = "720h" |
||||
|
||||
[recommend.user_neighbors] |
||||
|
||||
# The type of neighbors for users. There are three types: |
||||
# similar: Neighbors are found by number of common labels. |
||||
# related: Neighbors are found by number of common liked items. |
||||
# auto: If a user have labels, neighbors are found by number of common labels. |
||||
# If this user have no labels, neighbors are found by number of common liked items. |
||||
# The default value is "auto". |
||||
neighbor_type = "similar" |
||||
|
||||
# Enable approximate user neighbor searching using vector index. The default value is true. |
||||
enable_index = true |
||||
|
||||
# Minimal recall for approximate user neighbor searching. The default value is 0.8. |
||||
index_recall = 0.8 |
||||
|
||||
# Maximal number of fit epochs for approximate user neighbor searching vector index. The default value is 3. |
||||
index_fit_epoch = 3 |
||||
|
||||
[recommend.item_neighbors] |
||||
|
||||
# The type of neighbors for items. There are three types: |
||||
# similar: Neighbors are found by number of common labels. |
||||
# related: Neighbors are found by number of common users. |
||||
# auto: If a item have labels, neighbors are found by number of common labels. |
||||
# If this item have no labels, neighbors are found by number of common users. |
||||
# The default value is "auto". |
||||
neighbor_type = "similar" |
||||
|
||||
# Enable approximate item neighbor searching using vector index. The default value is true. |
||||
enable_index = true |
||||
|
||||
# Minimal recall for approximate item neighbor searching. The default value is 0.8. |
||||
index_recall = 0.8 |
||||
|
||||
# Maximal number of fit epochs for approximate item neighbor searching vector index. The default value is 3. |
||||
index_fit_epoch = 3 |
||||
|
||||
[recommend.collaborative] |
||||
|
||||
# Enable approximate collaborative filtering recommend using vector index. The default value is true. |
||||
enable_index = true |
||||
|
||||
# Minimal recall for approximate collaborative filtering recommend. The default value is 0.9. |
||||
index_recall = 0.9 |
||||
|
||||
# Maximal number of fit epochs for approximate collaborative filtering recommend vector index. The default value is 3. |
||||
index_fit_epoch = 3 |
||||
|
||||
# The time period for model fitting. The default value is "60m". |
||||
model_fit_period = "60m" |
||||
|
||||
# The time period for model searching. The default value is "360m". |
||||
model_search_period = "360m" |
||||
|
||||
# The number of epochs for model searching. The default value is 100. |
||||
model_search_epoch = 100 |
||||
|
||||
# The number of trials for model searching. The default value is 10. |
||||
model_search_trials = 10 |
||||
|
||||
# Enable searching models of different sizes, which consume more memory. The default value is false. |
||||
enable_model_size_search = false |
||||
|
||||
[recommend.replacement] |
||||
|
||||
# Replace historical items back to recommendations. The default value is false. |
||||
enable_replacement = false |
||||
|
||||
# Decay the weights of replaced items from positive feedbacks. The default value is 0.8. |
||||
positive_replacement_decay = 0.8 |
||||
|
||||
# Decay the weights of replaced items from read feedbacks. The default value is 0.6. |
||||
read_replacement_decay = 0.6 |
||||
|
||||
[recommend.offline] |
||||
|
||||
# The time period to check recommendation for users. The default values is 1m. |
||||
check_recommend_period = "1m" |
||||
|
||||
# The time period to refresh recommendation for inactive users. The default values is 120h. |
||||
refresh_recommend_period = "24h" |
||||
|
||||
# Enable latest recommendation during offline recommendation. The default value is false. |
||||
enable_latest_recommend = true |
||||
|
||||
# Enable popular recommendation during offline recommendation. The default value is false. |
||||
enable_popular_recommend = false |
||||
|
||||
# Enable user-based similarity recommendation during offline recommendation. The default value is false. |
||||
enable_user_based_recommend = true |
||||
|
||||
# Enable item-based similarity recommendation during offline recommendation. The default value is false. |
||||
enable_item_based_recommend = false |
||||
|
||||
# Enable collaborative filtering recommendation during offline recommendation. The default value is true. |
||||
enable_collaborative_recommend = true |
||||
|
||||
# Enable click-though rate prediction during offline recommendation. Otherwise, results from multi-way recommendation |
||||
# would be merged randomly. The default value is false. |
||||
enable_click_through_prediction = true |
||||
|
||||
# The explore recommendation method is used to inject popular items or latest items into recommended result: |
||||
# popular: Recommend popular items to cold-start users. |
||||
# latest: Recommend latest items to cold-start users. |
||||
# The default values is { popular = 0.0, latest = 0.0 }. |
||||
explore_recommend = { popular = 0.1, latest = 0.2 } |
||||
|
||||
[recommend.online] |
||||
|
||||
# The fallback recommendation method is used when cached recommendation drained out: |
||||
# item_based: Recommend similar items to cold-start users. |
||||
# popular: Recommend popular items to cold-start users. |
||||
# latest: Recommend latest items to cold-start users. |
||||
# Recommenders are used in order. The default values is ["latest"]. |
||||
fallback_recommend = ["item_based", "latest"] |
||||
|
||||
# The number of feedback used in fallback item-based similar recommendation. The default values is 10. |
||||
num_feedback_fallback_item_based = 10 |
||||
|
||||
[tracing] |
||||
|
||||
# Enable tracing for REST APIs. The default value is false. |
||||
enable_tracing = false |
||||
|
||||
# The type of tracing exporters should be one of "jaeger", "zipkin", "otlp" and "otlphttp". The default value is "jaeger". |
||||
exporter = "jaeger" |
||||
|
||||
# The endpoint of tracing collector. |
||||
collector_endpoint = "http://localhost:14268/api/traces" |
||||
|
||||
# The type of tracing sampler should be one of "always", "never" and "ratio". The default value is "always". |
||||
sampler = "always" |
||||
|
||||
# The ratio of ratio based sampler. The default value is 1. |
||||
ratio = 1 |
Loading…
Reference in new issue