mount 命令在终端中运行良好,但不能通过 python 中的 cgi 脚本运行。我为此使用了 apache2

mount 命令在终端中运行良好,但不能通过 python 中的 cgi 脚本运行。我为此使用了 apache2
#!/usr/bin/python3
import cgi,subprocess
import getpass

current_user = getpass.getuser()
form = cgi.FieldStorage()
ip = form.getvalue('ip')
username = form.getvalue('username')
password = form.getvalue('password')
storage = form.getvalue('storage')
options = form.getvalue('options')
status=0

def allocate(ip,storage):
    lv_create_cmd = f"sudo lvcreate -n {ip} -L +{storage}m mycloud > /dev/null 2>&1"
    lv_format_cmd = f"sudo mkfs.ext4 /dev/mycloud/{ip} > /dev/null 2>&1"
    mount_create_cmd = f"sudo mkdir /mnt/fs_{ip}"
    permit_cmd=f"sudo chmod 777 /mnt/fs_{ip}"
    mount_up_cmd = f"sudo /bin/mount -t ext4 /dev/mycloud/{ip} /mnt/fs_{ip}" 

    #cmd_run = f"{lv_create_cmd} && {lv_format_cmd} && {mount_create_cmd} && {permit_cmd}"
    print(f"Current user: {current_user}")
    print(subprocess.run(lv_create_cmd,shell=True,check=True))
    print(subprocess.run(lv_format_cmd,shell=True,check=True))
    print(subprocess.run(mount_create_cmd,shell=True,check=True))
    print(subprocess.run(permit_cmd,shell=True,check=True))
    print("mount point created")
    print(subprocess.run(mount_up_cmd,shell=True,check=True))
    print("mounting done...")

print("Content-Type: text/html")
print()
print("<h1>Form Submission Results</h1>")
print(f"<p>IP Address: {ip}</p>")
print(f"<p>Username: {username}</p>")
print(f"<p>Password: {password}</p>")
print(f"<p>Storage: {storage} MB</p>")
print(f"<p>Options: {options}</p>")

if options == 'primary':
    allocate(ip, storage)

我的输出如下:

点击此处查看输出

这是我给予 www-data 的许可。

www-data ALL=(ALL) NOPASSWD:ALL

问题是df -h没有列出我的 /dev/mapper/.. 但是 mount 命令正在执行,状态代码为 0。

相关内容