# remote_run_everthing统一解决各种语言远程调试
jet家的什么python,java,clion的c/c++都带remote debug,但是第一要缴费版本,第二rust这种语言,缴费也没有。
一种方法是使用gdbserver,这个具体可以google
## 方法原理
使用python脚本,在远程环境调用cmd,把结果打印到目前的ide,调用的时候运行python脚本就可以,如果配合虚拟机共享文件夹使用,那么就不需要上传下载文件。可能有人会问,为什么下载文件,这个主要是为了ide代码智能补全。
## 以运行rust代码为例
pip install remote_run_everything
[remote_run_everythin github 地址](https://github.com/wangmarkqi/remote_run_everything.git)
```python
from remote_run_everything import Conf, Local, Remote
def test():
c = Conf(
host="192.168.177.130",
user="root",
pwd="a",
remote_root="/mnt/myrust/ssl",
local_root="D://myrust/ssl",
)
l = Local(c)
# step1:代码文件同步:这个命令会把local_root下的子文件夹递归复制到remote_root对应的子文件夹,虚拟机共享文件夹不需要本步骤
l.upload(c.local_root+"/src",exclude="node_modules")
#or
l.upload(c.local_root+"/src",exclude=["node_modules"])
#or
l.upload(c.local_root+"/src")
# step2: 命令行:这个命令会在远程环境remot_root文件夹中执行cargo run,并把输出结果打印在屏幕。多个命令以列表形式传递
# r.cmd(['cargo run'])
# step3:代码智能补全文件下载: 这个命令会把remote_root的子文件夹复制到local_root对应子文件夹,虚拟机共享文件夹不需要本步骤,这一步的意义在于ide智能补全(编译代码在虚拟机,本地没有)。实际中,执行此步骤需要根据语言变更子文件夹,以rust为例,复制target即可
l.download(c.remote_root+"/target")
test()
```
## 运维功能
此外,__scripts__文件夹下含有python运维管理脚本,运行就会把__scripts__下所有运维脚本上传到远程根目录,然后运行相应的cmd命令即可。目前的脚本主要是杀进程的,根据关键字杀进程,根据端口号杀进程,未来会不断拓展。详细参见__scripts__目录脚本写法.
```
c = Conf(
host="192.168.177.130",
user="root",
pwd="a",
remote_root="/mnt/myrust/ssl",
local_root="D://myrust/ssl",
)
l = Local(c)
r = Remote(c)
#把__scripts__下所有运维脚本上传到远程根目录
l.upload_scripts()
```
- 杀进程
```
# 杀掉端口号8088的所有进程(gunicorn针对一个端口多个进程,全杀)
r.cmd(['cd __scripts__', 'python kill_ss.py 8088'])
# 杀掉包含关键词的所有进程(gunicorn多个进程,全杀)
r.cmd(['cd __scripts__','python kill_ps.py keyword1 keyword2'])
```
- 芒果db备份恢复
```
# 将mongodb数据库1,2下所有数据备份到远程根目录mongoback目录下,数据库名称是子目录名称
r.cmd(['source /home/anaconda3/bin/activate server',
'python ./__scripts__/mongo_dump_restore.py dump mongodb://localhost:27017 mpy ruihe'
])
# 将备份文件拉回本地
l.download(c.remote_root+"/mongo_backup")
# 将mongodb数据库1,2下所有数据恢复
r.cmd(['source /home/anaconda3/bin/activate server','python ./__scripts__/mongo_dump_restore.py restore mongodb://localhost:27017 db1 db2'])
```
- gunicorn 重启server
```
start=['source /home/anaconda3/bin/activate server',"gunicorn riskMis:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8887 --daemon"]
r.cmd(start)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/wangmarkqi/remote_run_everything",
"name": "remote-run-everything",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "remote, debug, development tool",
"author": "Wang Qi",
"author_email": "wangmarkqi@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d3/58/912214c99bdea9059763febbf22f984d378d929f789a5bd0507bab81c8f0/remote_run_everything-1.9.tar.gz",
"platform": null,
"description": "# remote_run_everthing\u7edf\u4e00\u89e3\u51b3\u5404\u79cd\u8bed\u8a00\u8fdc\u7a0b\u8c03\u8bd5\r\n\r\njet\u5bb6\u7684\u4ec0\u4e48python\uff0cjava\uff0cclion\u7684c/c++\u90fd\u5e26remote debug\uff0c\u4f46\u662f\u7b2c\u4e00\u8981\u7f34\u8d39\u7248\u672c\uff0c\u7b2c\u4e8crust\u8fd9\u79cd\u8bed\u8a00\uff0c\u7f34\u8d39\u4e5f\u6ca1\u6709\u3002\r\n\r\n\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528gdbserver\uff0c\u8fd9\u4e2a\u5177\u4f53\u53ef\u4ee5google\r\n\r\n## \u65b9\u6cd5\u539f\u7406\r\n\r\n\u4f7f\u7528python\u811a\u672c\uff0c\u5728\u8fdc\u7a0b\u73af\u5883\u8c03\u7528cmd\uff0c\u628a\u7ed3\u679c\u6253\u5370\u5230\u76ee\u524d\u7684ide\uff0c\u8c03\u7528\u7684\u65f6\u5019\u8fd0\u884cpython\u811a\u672c\u5c31\u53ef\u4ee5\uff0c\u5982\u679c\u914d\u5408\u865a\u62df\u673a\u5171\u4eab\u6587\u4ef6\u5939\u4f7f\u7528\uff0c\u90a3\u4e48\u5c31\u4e0d\u9700\u8981\u4e0a\u4f20\u4e0b\u8f7d\u6587\u4ef6\u3002\u53ef\u80fd\u6709\u4eba\u4f1a\u95ee\uff0c\u4e3a\u4ec0\u4e48\u4e0b\u8f7d\u6587\u4ef6\uff0c\u8fd9\u4e2a\u4e3b\u8981\u662f\u4e3a\u4e86ide\u4ee3\u7801\u667a\u80fd\u8865\u5168\u3002\r\n\r\n## \u4ee5\u8fd0\u884crust\u4ee3\u7801\u4e3a\u4f8b\r\npip install remote_run_everything\r\n\r\n[remote_run_everythin github \u5730\u5740](https://github.com/wangmarkqi/remote_run_everything.git)\r\n\r\n```python\r\nfrom remote_run_everything import Conf, Local, Remote\r\ndef test():\r\n c = Conf(\r\n host=\"192.168.177.130\",\r\n user=\"root\",\r\n pwd=\"a\",\r\n remote_root=\"/mnt/myrust/ssl\",\r\n local_root=\"D://myrust/ssl\",\r\n )\r\n l = Local(c)\r\n \r\n # step1:\u4ee3\u7801\u6587\u4ef6\u540c\u6b65\uff1a\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u628alocal_root\u4e0b\u7684\u5b50\u6587\u4ef6\u5939\u9012\u5f52\u590d\u5236\u5230remote_root\u5bf9\u5e94\u7684\u5b50\u6587\u4ef6\u5939,\u865a\u62df\u673a\u5171\u4eab\u6587\u4ef6\u5939\u4e0d\u9700\u8981\u672c\u6b65\u9aa4\r\n l.upload(c.local_root+\"/src\",exclude=\"node_modules\")\r\n #or\r\n l.upload(c.local_root+\"/src\",exclude=[\"node_modules\"])\r\n #or\r\n l.upload(c.local_root+\"/src\")\r\n\r\n # step2: \u547d\u4ee4\u884c\uff1a\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u8fdc\u7a0b\u73af\u5883remot_root\u6587\u4ef6\u5939\u4e2d\u6267\u884ccargo run\uff0c\u5e76\u628a\u8f93\u51fa\u7ed3\u679c\u6253\u5370\u5728\u5c4f\u5e55\u3002\u591a\u4e2a\u547d\u4ee4\u4ee5\u5217\u8868\u5f62\u5f0f\u4f20\u9012\r\n # r.cmd(['cargo run'])\r\n \r\n # step3\uff1a\u4ee3\u7801\u667a\u80fd\u8865\u5168\u6587\u4ef6\u4e0b\u8f7d\uff1a \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u628aremote_root\u7684\u5b50\u6587\u4ef6\u5939\u590d\u5236\u5230local_root\u5bf9\u5e94\u5b50\u6587\u4ef6\u5939,\u865a\u62df\u673a\u5171\u4eab\u6587\u4ef6\u5939\u4e0d\u9700\u8981\u672c\u6b65\u9aa4\uff0c\u8fd9\u4e00\u6b65\u7684\u610f\u4e49\u5728\u4e8eide\u667a\u80fd\u8865\u5168\uff08\u7f16\u8bd1\u4ee3\u7801\u5728\u865a\u62df\u673a\uff0c\u672c\u5730\u6ca1\u6709\uff09\u3002\u5b9e\u9645\u4e2d\uff0c\u6267\u884c\u6b64\u6b65\u9aa4\u9700\u8981\u6839\u636e\u8bed\u8a00\u53d8\u66f4\u5b50\u6587\u4ef6\u5939,\u4ee5rust\u4e3a\u4f8b\uff0c\u590d\u5236target\u5373\u53ef\r\n \r\n l.download(c.remote_root+\"/target\")\r\n\r\n\r\ntest()\r\n\r\n```\r\n\r\n## \u8fd0\u7ef4\u529f\u80fd\r\n\r\n\u6b64\u5916\uff0c__scripts__\u6587\u4ef6\u5939\u4e0b\u542b\u6709python\u8fd0\u7ef4\u7ba1\u7406\u811a\u672c\uff0c\u8fd0\u884c\u5c31\u4f1a\u628a__scripts__\u4e0b\u6240\u6709\u8fd0\u7ef4\u811a\u672c\u4e0a\u4f20\u5230\u8fdc\u7a0b\u6839\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\u76f8\u5e94\u7684cmd\u547d\u4ee4\u5373\u53ef\u3002\u76ee\u524d\u7684\u811a\u672c\u4e3b\u8981\u662f\u6740\u8fdb\u7a0b\u7684\uff0c\u6839\u636e\u5173\u952e\u5b57\u6740\u8fdb\u7a0b\uff0c\u6839\u636e\u7aef\u53e3\u53f7\u6740\u8fdb\u7a0b\uff0c\u672a\u6765\u4f1a\u4e0d\u65ad\u62d3\u5c55\u3002\u8be6\u7ec6\u53c2\u89c1__scripts__\u76ee\u5f55\u811a\u672c\u5199\u6cd5.\r\n\r\n```\r\nc = Conf(\r\n host=\"192.168.177.130\",\r\n user=\"root\",\r\n pwd=\"a\",\r\n remote_root=\"/mnt/myrust/ssl\",\r\n local_root=\"D://myrust/ssl\",\r\n)\r\nl = Local(c)\r\nr = Remote(c)\r\n#\u628a__scripts__\u4e0b\u6240\u6709\u8fd0\u7ef4\u811a\u672c\u4e0a\u4f20\u5230\u8fdc\u7a0b\u6839\u76ee\u5f55\r\nl.upload_scripts()\r\n```\r\n- \u6740\u8fdb\u7a0b\r\n```\r\n# \u6740\u6389\u7aef\u53e3\u53f78088\u7684\u6240\u6709\u8fdb\u7a0b\uff08gunicorn\u9488\u5bf9\u4e00\u4e2a\u7aef\u53e3\u591a\u4e2a\u8fdb\u7a0b\uff0c\u5168\u6740\uff09\r\nr.cmd(['cd __scripts__', 'python kill_ss.py 8088'])\r\n\r\n# \u6740\u6389\u5305\u542b\u5173\u952e\u8bcd\u7684\u6240\u6709\u8fdb\u7a0b\uff08gunicorn\u591a\u4e2a\u8fdb\u7a0b\uff0c\u5168\u6740\uff09\r\nr.cmd(['cd __scripts__','python kill_ps.py keyword1 keyword2'])\r\n```\r\n\r\n- \u8292\u679cdb\u5907\u4efd\u6062\u590d\r\n```\r\n# \u5c06mongodb\u6570\u636e\u5e931,2\u4e0b\u6240\u6709\u6570\u636e\u5907\u4efd\u5230\u8fdc\u7a0b\u6839\u76ee\u5f55mongoback\u76ee\u5f55\u4e0b\uff0c\u6570\u636e\u5e93\u540d\u79f0\u662f\u5b50\u76ee\u5f55\u540d\u79f0\r\nr.cmd(['source /home/anaconda3/bin/activate server',\r\n 'python ./__scripts__/mongo_dump_restore.py dump mongodb://localhost:27017 mpy ruihe'\r\n ])\r\n\r\n# \u5c06\u5907\u4efd\u6587\u4ef6\u62c9\u56de\u672c\u5730\r\nl.download(c.remote_root+\"/mongo_backup\")\r\n\r\n# \u5c06mongodb\u6570\u636e\u5e931,2\u4e0b\u6240\u6709\u6570\u636e\u6062\u590d\r\nr.cmd(['source /home/anaconda3/bin/activate server','python ./__scripts__/mongo_dump_restore.py restore mongodb://localhost:27017 db1 db2'])\r\n\r\n```\r\n\r\n- gunicorn \u91cd\u542fserver\r\n```\r\nstart=['source /home/anaconda3/bin/activate server',\"gunicorn riskMis:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8887 --daemon\"]\r\nr.cmd(start)\r\n```\r\n",
"bugtrack_url": null,
"license": null,
"summary": "\u8fdc\u7a0b\u4e0a\u4f20\u3001\u8c03\u8bd5\u3001\u4e0b\u8f7d\u4efb\u4f55\u8bed\u8a00",
"version": "1.9",
"project_urls": {
"Homepage": "https://github.com/wangmarkqi/remote_run_everything"
},
"split_keywords": [
"remote",
" debug",
" development tool"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d358912214c99bdea9059763febbf22f984d378d929f789a5bd0507bab81c8f0",
"md5": "0f8426b68ad2d2d50b5d37bb31e36685",
"sha256": "cc34394ffefe64b149e2c0e8ab036c5918e93f30cc0cb655fcd87d42c5437d9f"
},
"downloads": -1,
"filename": "remote_run_everything-1.9.tar.gz",
"has_sig": false,
"md5_digest": "0f8426b68ad2d2d50b5d37bb31e36685",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12274,
"upload_time": "2024-11-21T09:02:12",
"upload_time_iso_8601": "2024-11-21T09:02:12.607198Z",
"url": "https://files.pythonhosted.org/packages/d3/58/912214c99bdea9059763febbf22f984d378d929f789a5bd0507bab81c8f0/remote_run_everything-1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-21 09:02:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wangmarkqi",
"github_project": "remote_run_everything",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "remote-run-everything"
}