1#!/bin/bash 2 3# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License, version 2.0, 7# as published by the Free Software Foundation. 8# 9# This program is also distributed with certain software (including 10# but not limited to OpenSSL) that is licensed under separate terms, 11# as designated in a particular file or component or in included license 12# documentation. The authors of MySQL hereby grant you an additional 13# permission to link the program and your derivative works with the 14# separately licensed software that they have included with MySQL. 15# 16# This program is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU General Public License, version 2.0, for more details. 20# 21# You should have received a copy of the GNU General Public License 22# along with this program; if not, write to the Free Software 23# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 25get_pcount () { 26 PSCOUNT=$(ps -ef | grep "/usr/sbin/mysqld" | wc -l) 27 echo "${PSCOUNT}" 28} 29 30server_stop () { 31 PSCOUNT=$(get_pcount) 32 COUNT=0 33 while :; do 34 COUNT=$(( COUNT+1 )) 35 echo -n . 36 if [ "${PSCOUNT}" -eq 1 ]; 37 then 38 echo 39 break 40 fi 41 if [ "${COUNT}" -gt 15 ]; 42 then 43 echo 44 return 1 45 fi 46 PSCOUNT=$(get_pcount) 47 sleep 1 48 done 49 return 0 50} 51 52case "$1" in 53 install) 54 55 if [ -z "$2" ]; 56 then 57 58 set -e 59 60 if [ -x "/etc/init.d/mysql" ]; 61 then 62 invoke-rc.d mysql stop || exit $? 63 server_stop 64 fi 65 # Native 5.5 packages create a /var/run/mysqld owned by root. This can cause 66 # errors in the systemd service, so we reset ownership if it exists. 67 MYSQLRUN=/var/run/mysqld 68 if [ -d ${MYSQLRUN} ]; then 69 install -d -m0755 -omysql -gmysql ${MYSQLRUN} 70 fi 71 72 set +e 73 74 fi 75 76 ;; 77 78 upgrade) 79 80 set -e 81 82 #DEBHELPER# 83 server_stop 84 85 set +e 86 87 ;; 88 89 abort-upgrade) 90 91 ;; 92 93 *) 94 exit 1 95 ;; 96esac 97 98exit 0 99