-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlnmp
executable file
·140 lines (127 loc) · 2.6 KB
/
lnmp
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
#!/bin/bash
# The tool is used to conventient me to manage lnmp.
# Hope it will help you.
# And now I'm looking for a good job. If you think I'm ok, please contact me by email '[email protected]'.
PHP_PATH=/usr/local/php71
NGINX_PATH=/usr/local/nginx
MYSQL=/usr/local/mysql
function getNginxStatus(){
echo $( sudo lsof -i :80 | grep nginx | grep -v grep )
}
function getPhpfpmStatus(){
echo $( sudo ps aux | grep "php-fpm" | grep -v grep )
}
function getMysqlStatus(){
echo $( lsof -i :3306 | grep mysql | grep -v grep )
}
function startLnmp(){
nginx_info=$( getNginxStatus )
if [ -n "$nginx_info" ]
then
echo "nginx already started !"
else
echo "starting nginx"
sudo nginx
echo "nginx start successful !"
fi
phpfpm_info=$( getPhpfpmStatus )
if [ -n "$phpfpm_info" ]
then
echo "php-fpm already started !"
else
echo "starting php-fpm"
sudo $PHP_PATH/sbin/php-fpm
echo "php-fpm start successful !"
fi
mysql_info=$( getMysqlStatus )
if [ -n "$mysql_info" ]
then
echo "mysql already started !"
else
echo "starting mysql"
mysqld start >/dev/null
echo "mysql start successful !"
fi
}
function restartLnmp(){
info=$( getNginxStatus )
if [ -n "$info" ]
then
echo "reload nginx"
sudo nginx -s reload
echo "nginx reload successful !"
else
echo "starting nginx"
sudo nginx
echo "nginx start successful !"
fi
info=$( getPhpfpmStatus )
if [ -n "$info" ]
then
echo "stopping php-fpm"
sudo killall -9 php-fpm
echo "stop php-fpm successful !"
fi
echo "starting php-fpm"
sudo $PHP_PATH/sbin/php-fpm
echo "php-fpm start successful ! "
info=$( getMysqlStatus )
if [ -n "$info" ]
then
echo "restarting mysql"
mysqld restart
echo "restart mysql successful !"
else
echo "start mysql"
mysqld start
echo "mysql start successful 1"
fi
}
function stopLnmp(){
nginx_info=$( getNginxStatus )
if [ -n "$nginx_info" ]
then
echo "stopping nginx"
sudo nginx -s stop
echo "nginx stop successful !"
else
echo "No such nginx process !"
fi
phpfpm_info=$( getPhpfpmStatus )
if [ -n "$phpfpm_info" ]
then
echo "stoping php-fpm"
sudo killall -9 php-fpm
echo "php-fpm stop successful !"
else
echo "No such php-fpm process !"
fi
mysql_info=$( getMysqlStatus )
if [ -n "$mysql_info" ]
then
echo "stopping mysql"
mysqld stop >/dev/null
echo "mysql stop successful !"
else
echo "No such mysql process"
fi
}
if [ -z "$1" ]
then
echo "Please input a param like start..."
exit 1
fi
# first, stop nginx
# echo "shutdown nginx"
if [ "$1" == "restart" ]
then
restartLnmp
fi
if [ "$1" == "start" ]
then
startLnmp
fi
if [ "$1" == "stop" ]
then
stopLnmp
fi