-
Notifications
You must be signed in to change notification settings - Fork 9
/
lampp_switcher.sh
195 lines (164 loc) · 3.85 KB
/
lampp_switcher.sh
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
# script version: 1.5
LAMPP_ACTION=$1
LAMPP_VERSION=$2
LAMPP="/opt/lampp"
XAMPP=$LAMPP"/xampp"
function stopall {
sudo $XAMPP stopapache
sudo $XAMPP stopmysql
sleep 3
}
function startall {
sudo $XAMPP startapache
sudo $XAMPP startmysql
sleep 3
}
function stopmysql {
sudo $XAMPP stopmysql
sleep 3
# this is import to make sure we are working on right databases
# and kill any instance of mysqld on your system
sudo killall mysqld < /dev/null &> /dev/null &
}
function stopapache {
sudo $XAMPP stopapache
sleep 3
sudo killall apache2 < /dev/null &> /dev/null &
sudo killall httpd < /dev/null &> /dev/null &
}
function startmysql {
sudo $XAMPP startmysql
sleep 3
}
function startapache {
sudo $XAMPP startapache
sleep 3
}
function checklampplink {
# check if exist a link and delete it
if [[ -L "$LAMPP" && -d "$LAMPP" ]]
then
echo "$LAMPP is a symlink to a directory: try DELETE!"
sudo rm -f $LAMPP
if [[ -L "$LAMPP" && -d "$LAMPP" ]];
then
echo "Link not deleted! exit 1"
exit 1
else
echo "Link Deleted! continue ..."
fi
else
echo "NO $LAMPP LINK WAS FOUND! continue ..."
fi
# create a new link
echo "Try to create LAMPP link ..."
cd /opt
ln -s "$LAMPP$LAMPP_VERSION" "lampp"
## check if is created
if [[ -L "$LAMPP" && -d "$LAMPP" ]];
then
echo $LAMPP "created! continue ..."
else
echo "LINK not created! exit 1"
exit 1
fi
}
function checkservices {
echo
$XAMPP status
echo
echo
# check if services exists and try to stop property
PIDS_MYSQL=$(ps -C mysqld -C mysqld_safe -o pid=)
PIDS_APACHE=$(ps -C /opt/lampp/bin/ -o pid=)
if [ -n "$PIDS_MYSQL" ];
then
stopmysql
else
echo "NO MYSQL TO KILL continue ..."
fi
if [ -n "$PIDS_APACHE" ];
then
stopapache
else
echo "NO APACHE TO KILL continue ..."
fi
}
###############################################
###############################################
# get an action
if [ -z "$LAMPP_ACTION" ];
then
echo
echo "ACTION: ( start | stop | restart)?"
read LAMPP_ACTION
else
echo "ACTION SET TO: "$LAMPP_ACTION
fi
# if action is stop exit else verify
if [ "$LAMPP_ACTION" = "stop" ];
then
stopall
exit 0
else
if [[ "$LAMPP_ACTION" = "start" || "$LAMPP_ACTION" = "restart" ]];
then
echo "Ok we will $LAMPP_ACTION continue ..."
else
echo "No Action .... exit 1"
exit 1
fi
fi
####
# get a version
if [ -z "$LAMPP_VERSION" ];
then
echo
echo "VERSION: ( 5 | 7 )? "
read LAMPP_VERSION
else
echo "VERSION SET TO: " $LAMPP_VERSION
fi
if [[ "$LAMPP_VERSION" = "5" || "$LAMPP_VERSION" = "7" ]];
then
echo "GOOD VERSION continue ..."
else
echo "Wrong VERSION exit 1"
exit 1
fi
## if action is start or restart do the same
echo
echo "Checking services ..."
checkservices
echo "End check services continue ..."
# check folder link
echo
echo "Checking lampp link ..."
checklampplink
echo "End checking link continue ..."
echo
echo "Select an option to START:"
echo "1) ALL current installed services on xampp "
echo "2) to apache and mysql - phpmyadmin "
echo
echo "Type enter to start option default ( 2 ) "
read USER_START
echo
echo "Starting services ..."
echo
if [ -z "$USER_START" ];
then
startapache
startmysql
else
if [ "$USER_START" = "1" ];
then
startall
else
startapache
startmysql
fi
fi
echo "Done"
exit 0