管理 python 项目脚本示例
# python3 程序
# linux 示例
python3 启动一个简单 httpserver
#!/bin/bash
Tag="Application_${PROJECT_ID}"
Lib="${PROJECT_PATH}"
Log="${PROJECT_PATH}/run.log"
echo $Tag
RETVAL="0"
# See how we were called.
function start() {
echo $Log
if [ ! -f $Log ]; then
touch $Log
fi
nohup python $Lib/simple_httpd.py $Tag > $Log 2>&1 &
sleep 3
head -n 10 $Log
}
function stop() {
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo -n "boot ( pid $pid) is running"
echo
echo -n $"Shutting down boot: "
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo "kill boot process"
kill -9 "$pid"
fi
else
echo "boot is stopped"
fi
status
}
function status()
{
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
#echo "$pid"
if [ "$pid" != "" ]; then
echo "running:$pid"
else
echo "boot is stopped"
fi
}
# See how we were called.
RETVAL="0"
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
usage
;;
esac
exit $RETVAL
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
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
# python2 程序
# linux 示例
python2 启动一个简单 httpserver
#!/bin/bash
Tag="Application_${PROJECT_ID}"
Lib="${PROJECT_PATH}"
Log="${PROJECT_PATH}/run.log"
echo $Tag
RETVAL="0"
# See how we were called.
function start() {
echo $Log
if [ ! -f $Log ]; then
touch $Log
fi
cd $Lib && nohup python -m SimpleHTTPServer 8000 $Tag > $Log 2>&1 &
sleep 5
head -n 10 $Log
}
function stop() {
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo -n "boot ( pid $pid) is running"
echo
echo -n $"Shutting down boot: "
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo "kill boot process"
kill -9 "$pid"
fi
else
echo "boot is stopped"
fi
status
}
function status()
{
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
#echo "$pid"
if [ "$pid" != "" ]; then
echo "running:$pid"
else
echo "boot is stopped"
fi
}
# See how we were called.
RETVAL="0"
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
usage
;;
esac
exit $RETVAL
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
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
帮助我们改善此文档 (opens new window)
上次更新: 2022/12/02, 13:53:34