-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlampine.sh
executable file
·106 lines (92 loc) · 2.68 KB
/
lampine.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
#!/bin/bash
guide(){
echo -e "Help: \n"
echo -e "lampine (start|stop|config|status|reload|sh|shroot) [local_port:port] \n"
echo -e "ex: lampine start 8000:8000"
echo "ex: lampine start"
}
if [ $# -eq 0 ];then
guide
exit
fi
if [ ! -f ~/.lampinerc ];then
echo "~/.lampinerc not found please reinstall"
exit
fi
. ~/.lampinerc
if [ ! -d $document_root ]
then
mkdir -p $document_root
fi
if [ ! -d $data_dir ]
then
mkdir -p $data_dir
fi
if [ ! -d $apache_conf ]
then
mkdir -p $apache_conf
fi
if [ ! -d $composer_home ]
then
mkdir -p $composer_home
fi
if [ ! -d $php_libs ]
then
mkdir -p $php_libs
fi
if [ "$1" == "start" ];then
append=""
if [[ $# -eq 2 ]] && [[ "$2" =~ ^[0-9]+\:[0-9]+$ ]];then
append=" -p $2"
fi
echo -e "Starting ... \n"
echo "Document root: $document_root"
echo "Mysql data directory: $data_dir"
echo "Mysql password: $mysql_password"
echo "Apache config dir: $apache_conf"
echo "Composer home: $composer_home"
echo "Apache local port: $apache_port"
echo "Apache Logs: $apache_logs"
echo -e "Mysql local port: $mysql_port \n"
if docker inspect "$container_name" > /dev/null 2>&1; then
echo "The container $container_name exists."
# Check if the container is running
if $(docker inspect -f '{{.State.Status}}' "$container_name" | grep -q "running"); then
echo "The container $container_name is running."
else
echo "The container $container_name is not running."
docker start $container_name
fi
else
docker run -d -v $document_root:/var/www/localhost/htdocs/ \
-v $etc_dir:/root/.etc -v $data_dir:/var/lib/mysql -v $composer_home:/tmp/composer \
-v $apache_logs:/var/log/apache2 \
-e MYSQL_ROOT_PASSWORD=$mysql_password -p $apache_port:80 -p $mysql_port:3306 $append \
--name lampine-server develhopper/lampine:latest 2>/dev/null
fi
if [ $? -eq 125 ];then
echo -e "somthing is wrong. please make sure docker service is running\nor maybe container is already running"
fi
elif [ "$1" == "stop" ];then
echo "Stoping server ..."
docker stop $container_name>/dev/null 2>&1
elif [ "$1" == "config" ];then
vi ~/.lampinerc
elif [ "$1" == "status" ];then
docker stats $container_name --no-stream 2>/dev/null
if [ $? -ne 0 ];then
echo "server is not running"
fi
elif [ "$1" == "sh" ];then
docker exec -it --user $UID:$UID $container_name ash -l
elif [ "$1" == "shroot" ];then
docker exec -it $container_name ash -l
elif [ "$1" == "reload" ];then
docker exec $container_name cp -r /root/.etc/apache2 /root/.etc/php8 /etc/
docker exec $container_name cp -r /root/.etc/lib/php8/ /usr/lib
docker exec $container_name pkill httpd
docker exec $container_name httpd
echo -e "\nApache Reloaded \n"
else
guide
fi