安装NFS驱动程序的systemd execute python脚本不工作

2024-09-27 23:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个systemd脚本和python脚本来自动检测挂载。你知道吗

系统脚本:

[Unit]
Description=TAD_Client - TAD WebService
After=network.target
[Service]
User=root
Type=forking
ExecStart=/data/.services/autoconfig.sh start
ExecReload=/data/.services/autoconfig.sh restart
ExecStop=/data/.services/autoconfig.sh stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

Shell脚本(部分):

export SHELL=/bin/bash
case "$1" in
"start" )
    echo "configuration service start"
    exec "/usr/bin/python" /data/.services/AutoConfiguration.py run &
;;
"stop" )
    echo "configuration service stop"
    exec "/usr/bin/python" /data/.services/AutoConfiguration.py stop
;;
"restart" )
    echo "restart configuration service"
    exec "/usr/bin/python" /data/.services/AutoConfiguration.py stop
    exec "/usr/bin/python" /data/.services/AutoConfiguration.py run &
;;

Python脚本(部分):

def mount_peu_server(self):
    mount_command = 'mount -t nfs ' + server_ip.addr + ':/mnt /mnt'
    p = subprocess.Popen(mount_command, stdout=subprocess.PIPE)
    out, err = p.communicate()
    self.log_error(out)
    self.log_error(err)

当我使用systemd作为服务启动脚本时,mount命令不起作用,但是如果我直接执行python脚本文件,mount命令可以成功执行。你知道吗

我已经检查了输出和err输出,subprocess没有返回任何内容。我认为这可能是一个权限问题,但是这个服务是由root用户运行的,它应该不再需要任何权限了。你知道吗


Tags: pyecho脚本databinusrshservice

热门问题