运行 服务器内的可执行后台程序

Running executable backgroung program inside server

我是我大学一个空气质量实验室的实习生,他们希望我改进他们的网站,该网站运行空气质量研究人员使用的一个程序(我认为该程序是用锈)。 它现在的工作方式是用户将一些必要的文件上传到 webapp(顺便说一下,这是用 Django 编写的),然后 webapp 调用这个程序,该程序在服务器上运行并上传文件。问题是如果用户离开或刷新页面,后台程序就会停止。 我从来没有在服务器后台处理过 运行 其他可执行文件的概念,所以我在理解这一切时遇到了一些问题。我遇到了 python 的“Celery”包,但它似乎很难实现,我想知道是否还有其他方法可以做到这一点。

你可以用 subprocess

template.html

<form action="{% url 'run_sh' %}" method="POST">
    {% csrf_token %}
    <button type="submit">Call</button>
</form>

urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('run-sh/', views.index, name='run_sh')
]

views.py

import subprocess

def index(request):
    if request.POST:
        subprocess.call('/home/user/test.sh') 

    return render(request,'index.html',{})

test.sh

#!/bin/sh
echo 'hello'

基于对此

的回答