网页网站您现在的位置是:首页 > 博客日志 > 网页网站

升级Python导致bt面板中的计划任务执行失败

<a href='mailto:'>微wx笑</a>的头像微wx笑 2022-03-03网页网站138 8 0关键字: bt面板  宝塔面板  Python  计划任务  

bt面板升级Python导致 RuntimeError: Bad magic number in .pyc file,解决了之后以为就没有问题了,后来发现设置的计划任务全都执行失败了,根据失败的错误日志判断,还是升级Python版本导致的。


9ts无知

错误日志

1
2
3
4
5
6
7
8
9
10
11
12
  File "/www/server/panel/script/backup.py", line 23
    print "★["+endDate+"] "+log
             ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("★["+endDate+"] "+log)?
  File "/www/server/panel/script/backup.py", line 23
    print "★["+endDate+"] "+log
             ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("★["+endDate+"] "+log)?
  File "/www/server/panel/script/backup.py", line 23
    print "★["+endDate+"] "+log
             ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("★["+endDate+"] "+log)?

解决方法

参考:bt面板升级Python导致 RuntimeError: Bad magic number in .pyc file9ts无知

在解决BT面板不能启动的问题时,只将部分位置的“python”修改为“python2.6”,导致一些功能不能用。9ts无知

比如“bt”文件中的
9ts无知

1
ps aux |grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'

如果程序是通过“python2.6”启动,那么可能查询到进程ID,如果不是,那就查不到。9ts无知

1、将“bt”文件中的所有“python”都修改为“python2.6”

完整文件内容如下:9ts无知

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# chkconfig: 2345 55 25
# description: bt Cloud Service
 
### BEGIN INIT INFO
# Provides:          bt
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts bt
# Description:       starts the bt
### END INIT INFO
panel_path=/www/server/panel
cd $panel_path
panel_start()
{
        isStart=`ps aux |grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'`
        if "$isStart" == '' ];then
                echo -e "Starting Bt-Panel... \c"
                if [ -f 'main.py' ];then
                        python2.6 -m py_compile main.py
                fi
                nohup python2.6 main.pyc `cat data/port.pl` > /tmp/panelBoot.pl 2>&1 &
                sleep 0.2
                isStart=`ps aux |grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'`
                if "$isStart" == '' ];then
                        echo -e "\033[31mfailed\033[0m"
                        echo '------------------------------------------------------'
                        cat /tmp/panelBoot.pl
                        echo '------------------------------------------------------'
                        echo -e "\033[31mError: BT-Panel service startup failed.\033[0m"
                        return;
                fi
                echo -e "\033[32mdone\033[0m"
        else
                echo "Starting Bt-Panel... Bt-Panel (pid $isStart) already running"
        fi
 
        isStart=`ps aux |grep 'python2.6 task.pyc$'|awk '{print $2}'`
        if "$isStart" == '' ];then
                echo -e "Starting Bt-Tasks... \c"
                if [ -f 'task.py' ];then
                        python2.6 -m py_compile task.py
                fi
                nohup python2.6 task.pyc > /tmp/panelTask.pl 2>&1 &
                sleep 0.2
                isStart=`ps aux |grep 'python2.6 task.pyc$'|awk '{print $2}'`
                if "$isStart" == '' ];then
                        echo -e "\033[31mfailed\033[0m"
                        echo '------------------------------------------------------'
                        cat /tmp/panelTask.pl
                        echo '------------------------------------------------------'
                        echo -e "\033[31mError: BT-Task service startup failed.\033[0m"
                        return;
                fi
                echo -e "\033[32mdone\033[0m"
        else
                echo "Starting Bt-Tasks... Bt-Tasks (pid $isStart) already running"
        fi
}
 
panel_stop()
{
        echo -e "Stopping Bt-Tasks... \c";
        pids=`ps aux | grep 'python2.6 task.pyc$'|awk '{print $2}'`
        arr=($pids)
 
        for in ${arr[@]}
        do
                kill -9 $p
        done
        echo -e "\033[32mdone\033[0m"
 
        echo -e "Stopping Bt-Panel... \c";
        pids=`ps aux | grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'`
        arr=($pids)
 
        for in ${arr[@]}
        do
                kill -9 $p
        done
        echo -e "\033[32mdone\033[0m"
}
 
panel_status()
{
        isStart=`ps aux |grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'`
        if "$isStart" != '' ];then
                echo -e "\033[32mBt-Panel (pid $isStart) already running\033[0m"
        else
                echo -e "\033[31mBt-Panel not running\033[0m"
        fi
 
        isStart=`ps aux |grep 'python2.6 task.pyc$'|awk '{print $2}'`
        if "$isStart" != '' ];then
                echo -e "\033[32mBt-Task (pid $isStart) already running\033[0m"
        else
                echo -e "\033[31mBt-Task not running\033[0m"
        fi
}
 
panel_reload()
{
        isStart=`ps aux |grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'`
        if "$isStart" != '' ];then
                echo -e "Reload service Bt-Panel... \c"
                pids=`ps aux | grep 'python2.6 main.pyc'|grep -v grep|awk '{print $2}'`
                arr=($pids)
                for in ${arr[@]}
                do
                        kill -9 $p
                done
                nohup python2.6 main.pyc `cat data/port.pl` >> /tmp/panelBoot.pl 2>&1 &
                if "$isStart" == '' ];then
                        echo -e "\033[31mfailed\033[0m"
                        echo '------------------------------------------------------'
                        cat /tmp/panelBoot.pl
                        echo '------------------------------------------------------'
                        echo -e "\033[31mError: BT-Panel service startup failed.\033[0m"
                        return;
                fi
                echo -e "\033[32mdone\033[0m"
        else
                echo -e "\033[31mBt-Panel not running\033[0m"
        fi
}
 
install_used()
{
        if [ ! -f /www/server/panel/aliyun.pl ];then
                return;
        fi
        password=`cat /dev/urandom head -n 16 | md5sum | head -c 12`
        username=`python2.6 /www/server/panel/tools.py panel $password`
        echo "$password" /www/server/panel/default.pl
        rm -f /www/server/panel/aliyun.pl
}
 
 
case "$1" in
        'start')
                install_used
                panel_start
                ;;
        'stop')
                panel_stop
                ;;
        'restart')
                panel_stop
                sleep 0.2
                panel_start
                ;;
        'reload')
                panel_reload
                ;;
        'status')
                panel_status
                ;;
        'default')
                port=`cat /www/server/panel/data/port.pl`
                password=`cat /www/server/panel/default.pl`
                echo -e "=================================================================="
                echo -e "\033[32mBT-Panel default info!\033[0m"
                echo -e "=================================================================="
                echo  "Bt-Panel: http://IP:$port"
                echo -e `python2.6 /www/server/panel/tools.py username`
                echo -e "password: $password"
                echo -e "\033[33mWarning:\033[0m"
                echo -e "\033[33mIf you cannot access the panel, \033[0m"
                echo -e "\033[33mrelease the following port (8888|888|80|443|20|21) in the security group\033[0m"
                echo -e "=================================================================="
                ;;
        *)
                echo "Usage: /etc/init.d/bt {start|stop|restart|reload|default}"
        ;;
esac

我的系统中最初安装的是python2.6,后来又安装了python 3.7.59ts无知

执行“python -V”,得到的结果是 python 3.7.5,具体安装过程参考:CentOS release 6.10 下 Python 3.7.5 安装记录9ts无知


9ts无知

2、修改/www/server/panel/class/crontab.py文件

在管理计划任务的时候,可以看到地址栏访问的是/crontab,于是找到/www/server/panel/class/crontab.py文件,把用到“python”的地方都修改为“python2.6”9ts无知

已经创建的任务可以删除重新创建,也可以直接在线编辑脚本,将“python”都修改为“python2.6”就可以了。9ts无知


9ts无知

本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/web/2022-03-03/1079.html

很赞哦! (10) 有话说 (0)

文章评论