-
Notifications
You must be signed in to change notification settings - Fork 4
/
persistence.sh
139 lines (102 loc) · 3.12 KB
/
persistence.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
#!/bin/bash
# This entire file is currently a big ol' TODO.
function postgresql_install {
apt-get -y install postgresql
}
function postgresql_tune {
# Tunes postgresql's memory usage to utilize the percentage of memory you specify, defaulting to 40%
# $1 - the percent of system memory to allocate towards postgresql
if [ ! -n "$1" ];
then PERCENT=40
else PERCENT="$1"
fi
# sed -i -e 's/^#skip-innodb/skip-innodb/' /etc/mysql/my.cnf # disable innodb - saves about 100M
MEM=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo) # how much memory in MB this system has
PGMEM=$((MEM*PERCENT/100)) # how much memory we'd like to tune postgresql with
PGMEMCHUNKS=$((PGMEM/4)) # how many 4MB chunks we have to play with
# postgresql config options we want to set to the percentages in the second list, respectively
# OPTLIST=(key_buffer sort_buffer_size read_buffer_size read_rnd_buffer_size myisam_sort_buffer_size query_cache_size)
# DISTLIST=(75 1 1 1 5 15)
# for opt in ${OPTLIST[@]}; do
# sed -i -e "/\[mysqld\]/,/\[.*\]/s/^$opt/#$opt/" /etc/mysql/my.cnf
# done
# for i in ${!OPTLIST[*]}; do
# val=$(echo | awk "{print int((${DISTLIST[$i]} * $MYMEMCHUNKS/100))*4}")
# if [ $val -lt 4 ]
# then val=4
# fi
# config="${config}\n${OPTLIST[$i]} = ${val}M"
# done
# sed -i -e "s/\(\[mysqld\]\)/\1\n$config\n/" /etc/mysql/my.cnf
/etc/init.d/postgresql restart
}
function postgresql_create_database {
# $1 - the postgresql root password
# $2 - the db name to create
if [ ! -n "$1" ]; then
echo "postgresql_create_database() requires the root pass as its first argument"
return 1;
fi
if [ ! -n "$2" ]; then
echo "postgresql_create_database() requires the name of the database as the second argument"
return 1;
fi
psql -c "CREATE DATABASE $2;" template1
}
function postgresql_create_user {
}
function postgresql_grant_user {
}
function mongodb_install {
}
function mongodb_tune {
}
function mongodb_create_database {
}
function mongodb_create_user {
}
function mongodb_grant_user {
}
function redis_install {
}
function redis_tune {
}
function redis_create_database {
}
function redis_create_user {
}
function redis_grant_user {
}
function couchdb_install {
}
function couchdb_tune {
}
function couchdb_create_database {
}
function couchdb_create_user {
}
function couchdb_grant_user {
}
function mysql_tune {
}
function mysql_create_database {
}
function mysql_create_user {
# $1 - the mysql root password
# $2 - the user to create
# $3 - their password
if [ ! -n "$1" ]; then
echo "mysql_create_user() requires the root pass as its first argument"
return 1;
fi
if [ ! -n "$2" ]; then
echo "mysql_create_user() requires username as the second argument"
return 1;
fi
if [ ! -n "$3" ]; then
echo "mysql_create_user() requires a password as the third argument"
return 1;
fi
echo "CREATE USER '$2'@'localhost' IDENTIFIED BY '$3';" | mysql -u root -p$1
}
function mysql_grant_user {