mirror of https://gitee.com/anolis/sysom.git
feat: Add microservices demo
This commit is contained in:
parent
456f2e22d8
commit
7f3df272e9
|
@ -95,7 +95,14 @@ server {
|
|||
proxy_redirect off;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
|
||||
location /api/v1/demo/ {
|
||||
proxy_pass http://127.0.0.1:7008;
|
||||
proxy_read_timeout 180;
|
||||
proxy_redirect off;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:7001;
|
||||
proxy_read_timeout 180s;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
SERVICE_NAME=sysom-demo
|
||||
clear_app() {
|
||||
rm -rf /etc/supervisord.d/${SERVICE_NAME}.ini
|
||||
###use supervisorctl update to stop and clear services###
|
||||
supervisorctl update
|
||||
}
|
||||
clear_app
|
|
@ -0,0 +1,43 @@
|
|||
#!/bin/bash
|
||||
SERVER_DIR="sysom_server"
|
||||
DEMO_DIR=${SERVER_DIR}/sysom_demo
|
||||
VIRTUALENV_HOME=${SERVER_HOME}/virtualenv
|
||||
TARGET_PATH=${SERVER_HOME}/target
|
||||
SERVICE_NAME=sysom-demo
|
||||
|
||||
if [ "$UID" -ne 0 ]; then
|
||||
echo "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source_virtualenv() {
|
||||
echo "INFO: activate virtualenv..."
|
||||
source ${VIRTUALENV_HOME}/bin/activate || exit 1
|
||||
}
|
||||
|
||||
init_conf() {
|
||||
cp ${SERVICE_NAME}.ini /etc/supervisord.d/
|
||||
###change the install dir base on param $1###
|
||||
sed -i "s;/usr/local/sysom;${APP_HOME};g" /etc/supervisord.d/${SERVICE_NAME}.ini
|
||||
}
|
||||
|
||||
start_app() {
|
||||
###if supervisor service started, we need use "supervisorctl update" to start new conf####
|
||||
supervisorctl update
|
||||
supervisorctl status ${SERVICE_NAME}
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "supervisorctl start ${SERVICE_NAME} success..."
|
||||
return 0
|
||||
fi
|
||||
echo "${SERVICE_NAME} service start fail, please check log"
|
||||
exit 1
|
||||
}
|
||||
|
||||
deploy() {
|
||||
source_virtualenv
|
||||
init_conf
|
||||
start_app
|
||||
}
|
||||
|
||||
deploy
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
SERVICE_NAME=sysom-demo
|
||||
start_app() {
|
||||
supervisorctl start $SERVICE_NAME
|
||||
}
|
||||
|
||||
start_app
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
SERVICE_NAME=sysom-demo
|
||||
stop_app() {
|
||||
supervisorctl stop $SERVICE_NAME
|
||||
}
|
||||
|
||||
stop_app
|
|
@ -0,0 +1,9 @@
|
|||
[program:sysom-demo]
|
||||
directory = /usr/local/sysom/server/target/sysom_server/sysom_demo
|
||||
command=/usr/local/sysom/server/virtualenv/bin/uvicorn main:app --port 7007
|
||||
startsecs=3
|
||||
autostart=true
|
||||
autorestart=true
|
||||
environment=PATH="/usr/local/sysom/server/virtualenv/bin/"
|
||||
stderr_logfile=/usr/local/sysom/server/logs/sysom-demo-error.log
|
||||
stdout_logfile=/usr/local/sysom/server/logs/sysom-demo.log
|
|
@ -20,4 +20,7 @@
|
|||
5_sysom_migration
|
||||
|
||||
[hotfix]
|
||||
6_sysom_hotfix
|
||||
6_sysom_hotfix
|
||||
|
||||
[demo]
|
||||
7_sysom_demo
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
from fastapi import FastAPI
|
||||
from channel_job import default_channel_job_executor
|
||||
|
||||
SYSOM_CEC_URL = "redis://localhost:6379?cec_default_max_len=1000&cec_auto_mk_topic=true"
|
||||
CHANNEL_JOB_URL = f"{SYSOM_CEC_URL}&channel_job_target_topic=SYSOM_CEC_CHANNEL_TOPIC" \
|
||||
f"&channel_job_listen_topic=SYSOM_CEC_DEMO_TOPIC" \
|
||||
f"&channel_job_consumer_group=SYSOM_CEC_DEMO_CONSUMER_GROUP"
|
||||
|
||||
default_channel_job_executor.init_config(CHANNEL_JOB_URL)
|
||||
default_channel_job_executor.start()
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/api/v1/demo/get_kernel_info/{instance}")
|
||||
async def get_kernel_info(instance: str):
|
||||
job = default_channel_job_executor.dispatch_job(
|
||||
channel_type="ssh",
|
||||
channel_opt="cmd",
|
||||
params={
|
||||
"instance": instance,
|
||||
"command": "uname -a"
|
||||
}
|
||||
)
|
||||
channel_result = await job.execute_async()
|
||||
return {
|
||||
"code": channel_result.code,
|
||||
"err_msg": channel_result.err_msg,
|
||||
"result": channel_result.result
|
||||
}
|
Loading…
Reference in New Issue