Gentoo Archives: gentoo-commits

From: "Pacho Ramos (pacho)" <pacho@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-db/mysql-init-scripts/files: mysqld-prepare-db-dir mysqld_at.service mysqld-wait-ready mysql.conf mysqld.service
Date: Tue, 03 Sep 2013 18:49:54
Message-Id: 20130903184949.461BF2004E@flycatcher.gentoo.org
1 pacho 13/09/03 18:49:49
2
3 Added: mysqld-prepare-db-dir mysqld_at.service
4 mysqld-wait-ready mysql.conf mysqld.service
5 Log:
6 Add systemd support (#466084)
7
8 (Portage version: 2.2.1/cvs/Linux x86_64, signed Manifest commit with key A188FBD4)
9
10 Revision Changes Path
11 1.1 dev-db/mysql-init-scripts/files/mysqld-prepare-db-dir
12
13 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld-prepare-db-dir?rev=1.1&view=markup
14 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld-prepare-db-dir?rev=1.1&content-type=text/plain
15
16 Index: mysqld-prepare-db-dir
17 ===================================================================
18 #!/bin/sh
19
20 # This script creates the mysql data directory during first service start.
21 # In subsequent starts, it does nothing much.
22
23 # extract value of a MySQL option from config files
24 # Usage: get_mysql_option SECTION VARNAME DEFAULT
25 # result is returned in $result
26 # We use my_print_defaults which prints all options from multiple files,
27 # with the more specific ones later; hence take the last match.
28 get_mysql_option(){
29 result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
30 if [ -z "$result" ]; then
31 # not found, use default
32 result="$3"
33 fi
34 }
35
36 # Defaults here had better match what mysqld_safe will default to
37 get_mysql_option mysqld datadir "/var/lib/mysql"
38 datadir="$result"
39 get_mysql_option mysqld_safe log-error "/var/log/mysql/mysql.log"
40 errlogfile="$result"
41
42 # Absorb configuration settings from the specified systemd service file,
43 # or the default "mysqld" service if not specified
44 SERVICE_NAME="$1"
45 if [ x"$SERVICE_NAME" = x ]
46 then
47 SERVICE_NAME=mysqld.service
48 fi
49
50 myuser=`systemctl show -p User "${SERVICE_NAME}" |
51 sed 's/^User=//'`
52 if [ x"$myuser" = x ]
53 then
54 myuser=mysql
55 fi
56
57 mygroup=`systemctl show -p Group "${SERVICE_NAME}" |
58 sed 's/^Group=//'`
59 if [ x"$mygroup" = x ]
60 then
61 mygroup=mysql
62 fi
63
64 # Set up the errlogfile with appropriate permissions
65 touch "$errlogfile"
66 chown "$myuser:$mygroup" "$errlogfile"
67 chmod 0640 "$errlogfile"
68 [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
69
70 # Make the data directory
71 if [ ! -d "$datadir/mysql" ] ; then
72 # First, make sure $datadir is there with correct permissions
73 # (note: if it's not, and we're not root, this'll fail ...)
74 if [ ! -e "$datadir" -a ! -h "$datadir" ]
75 then
76 mkdir -p "$datadir" || exit 1
77 fi
78 chown "$myuser:$mygroup" "$datadir"
79 chmod 0755 "$datadir"
80 [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"
81
82 # Now create the database
83 echo "Initializing MySQL database"
84 /usr/share/mysql/scripts/mysql_install_db \
85 --datadir="$datadir" --user="$myuser" --basedir="/usr"
86 ret=$?
87 if [ $ret -ne 0 ] ; then
88 echo "Initialization of MySQL database failed." >&2
89 echo "Perhaps /etc/mysql/my.cnf is misconfigured." >&2
90 # Clean up any partially-created database files
91 if [ ! -e "$datadir/mysql/user.frm" ] ; then
92 rm -rf "$datadir"/*
93 fi
94 exit $ret
95 fi
96 # In case we're running as root, make sure files are owned properly
97 chown -R "$myuser:$mygroup" "$datadir"
98 fi
99
100 exit 0
101
102
103
104 1.1 dev-db/mysql-init-scripts/files/mysqld_at.service
105
106 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld_at.service?rev=1.1&view=markup
107 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld_at.service?rev=1.1&content-type=text/plain
108
109 Index: mysqld_at.service
110 ===================================================================
111 # It's not recommended to modify this file in-place, because it will be
112 # overwritten during package upgrades. If you want to customize, the
113 # best way is to create a file "/etc/systemd/system/mysqld.service",
114 # containing
115 # .include /lib/systemd/system/mysqld.service
116 # ...make your changes here...
117 # For more info about custom unit files, see
118 # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
119
120 # For example, if you want to increase mysql's open-files-limit to 10000,
121 # you need to increase systemd's LimitNOFILE setting, so create a file named
122 # "/etc/systemd/system/mysqld.service" containing:
123 # .include /lib/systemd/system/mysqld.service
124 # [Service]
125 # LimitNOFILE=10000
126
127 # Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line
128 # though /lib/... will still work.
129
130 [Unit]
131 Description=MySQL database server
132 ConditionPathExists=/etc/mysql/my%I.cnf
133 After=network.target
134
135 [Service]
136 Type=simple
137 User=mysql
138 Group=mysql
139
140 ExecStartPre=/usr/libexec/mysqld-prepare-db-dir %n
141 # Note: we set --basedir to prevent probes that might trigger SELinux alarms,
142 # per bug #547485
143 ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/mysql/my%I.cnf --basedir=/usr
144 ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
145
146 # Give a reasonable amount of time for the server to start up/shut down
147 TimeoutSec=300
148
149 # Place temp files in a secure directory, not /tmp
150 PrivateTmp=true
151
152 [Install]
153 WantedBy=multi-user.target
154
155
156
157 1.1 dev-db/mysql-init-scripts/files/mysqld-wait-ready
158
159 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld-wait-ready?rev=1.1&view=markup
160 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld-wait-ready?rev=1.1&content-type=text/plain
161
162 Index: mysqld-wait-ready
163 ===================================================================
164 #!/bin/sh
165
166 # This script waits for mysqld to be ready to accept connections
167 # (which can be many seconds or even minutes after launch, if there's
168 # a lot of crash-recovery work to do).
169 # Running this as ExecStartPost is useful so that services declared as
170 # "After mysqld" won't be started until the database is really ready.
171
172 # Service file passes us the daemon's PID (actually, mysqld_safe's PID)
173 daemon_pid="$1"
174
175 # extract value of a MySQL option from config files
176 # Usage: get_mysql_option SECTION VARNAME DEFAULT
177 # result is returned in $result
178 # We use my_print_defaults which prints all options from multiple files,
179 # with the more specific ones later; hence take the last match.
180 get_mysql_option(){
181 result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
182 if [ -z "$result" ]; then
183 # not found, use default
184 result="$3"
185 fi
186 }
187
188 # Defaults here had better match what mysqld_safe will default to
189 get_mysql_option mysqld datadir "/var/lib/mysql"
190 datadir="$result"
191 get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock"
192 socketfile="$result"
193
194 # Wait for the server to come up or for the mysqld process to disappear
195 ret=0
196 while /bin/true; do
197 RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
198 mret=$?
199 if [ $mret -eq 0 ]; then
200 break
201 fi
202 # exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
203 # anything else suggests a configuration error
204 if [ $mret -ne 1 -a $mret -ne 11 ]; then
205 ret=1
206 break
207 fi
208 # "Access denied" also means the server is alive
209 echo "$RESPONSE" | grep -q "Access denied for user" && break
210
211 # Check process still exists
212 if ! /bin/kill -0 $daemon_pid 2>/dev/null; then
213 ret=1
214 break
215 fi
216 sleep 1
217 done
218
219 exit $ret
220
221
222
223 1.1 dev-db/mysql-init-scripts/files/mysql.conf
224
225 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysql.conf?rev=1.1&view=markup
226 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysql.conf?rev=1.1&content-type=text/plain
227
228 Index: mysql.conf
229 ===================================================================
230 d /var/run/mysqld 0755 mysql mysql -
231
232
233
234 1.1 dev-db/mysql-init-scripts/files/mysqld.service
235
236 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld.service?rev=1.1&view=markup
237 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld.service?rev=1.1&content-type=text/plain
238
239 Index: mysqld.service
240 ===================================================================
241 # It's not recommended to modify this file in-place, because it will be
242 # overwritten during package upgrades. If you want to customize, the
243 # best way is to create a file "/etc/systemd/system/mysqld.service",
244 # containing
245 # .include /lib/systemd/system/mysqld.service
246 # ...make your changes here...
247 # For more info about custom unit files, see
248 # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
249
250 # For example, if you want to increase mysql's open-files-limit to 10000,
251 # you need to increase systemd's LimitNOFILE setting, so create a file named
252 # "/etc/systemd/system/mysqld.service" containing:
253 # .include /lib/systemd/system/mysqld.service
254 # [Service]
255 # LimitNOFILE=10000
256
257 # Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line
258 # though /lib/... will still work.
259
260 [Unit]
261 Description=MySQL database server
262 After=syslog.target
263 After=network.target
264
265 [Service]
266 Type=simple
267 User=mysql
268 Group=mysql
269
270 ExecStartPre=/usr/libexec/mysqld-prepare-db-dir %n
271 # Note: we set --basedir to prevent probes that might trigger SELinux alarms,
272 # per bug #547485
273 ExecStart=/usr/bin/mysqld_safe --basedir=/usr
274 ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
275
276 # Give a reasonable amount of time for the server to start up/shut down
277 TimeoutSec=300
278
279 # Place temp files in a secure directory, not /tmp
280 PrivateTmp=true
281
282 [Install]
283 WantedBy=multi-user.target