-
Notifications
You must be signed in to change notification settings - Fork 206
/
service.sh
76 lines (60 loc) · 1.74 KB
/
service.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
#!/bin/bash
#
function init_pg() {
echo ">> Init database"
DB_NAME=${DB_NAME:-jumpserver}
DB_PASSWORD=${DB_PASSWORD:-PleaseChangeMe}
DB_ENGINE=${DB_ENGINE:-postgresql}
DB_HOST=${DB_HOST:-127.0.0.1}
DB_PORT=${DB_PORT:-5432}
DB_USER=${DB_USER:-postgres}
export DB_NAME DB_PASSWORD DB_ENGINE DB_HOST DB_PORT DB_USER
if [[ ${DB_HOST} != "127.0.0.1" ]];then
echo "External database skip start, ${DB_HOST}"
return
fi
echo ">> Start database postgre"
chown -R postgres:postgres /var/lib/postgresql/13/main
pg_ctlcluster 13 main start
sleep 3
if [[ ! -f /var/lib/postgresql/13/main/inited.txt ]];then
sudo -u postgres psql -c "ALTER USER postgres PASSWORD '$DB_PASSWORD';"
sudo -u postgres psql -c "CREATE DATABASE $DB_NAME;"
touch /var/lib/postgresql/13/main/inited.txt
fi
}
function init_ng(){
echo ">> Init nginx"
echo """
127.0.0.1 core
127.0.0.1 koko
127.0.0.1 lion
127.0.0.1 chen
""" >> /etc/hosts
mkdir -p /var/log/nginx
mkdir -p /var/cache/nginx
}
function init_redis() {
REDIS_HOST=${REDIS_HOST:-127.0.0.1}
REDIS_PORT=${REDIS_PORT:-6379}
REDIS_PASSWORD=${REDIS_PASSWORD:-PleaseChangeMe}
export REDIS_HOST REDIS_PORT REDIS_PASSWORD
if [[ ${REDIS_HOST} != '127.0.0.1' ]];then
echo "External redis server skip start, ${REDIS_HOST}"
return
fi
echo ">> Start redis server"
/usr/bin/redis-server /etc/redis/redis.conf --requirepass $REDIS_PASSWORD
}
function init_other() {
# chen
sed -i "s@root: INFO@root: ${LOG_LEVEL}@g" /opt/chen/config/application.yml
# cron
if [ -f "/etc/init.d/cron" ]; then
/etc/init.d/cron start
fi
}
init_pg
init_ng
init_redis
init_other