Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:05:41+00:00 2026-06-16T01:05:41+00:00

Unit tests run few times faster if I setup mysql instance in RAM memory,

  • 0

Unit tests run few times faster if I setup mysql instance in RAM memory, but because this is manual process, it take me some time to do this, and I need to do this on few server.
New mysql instance should run on port 3307, if it is free, otherwise return error.

So, first thing I need is to check if some service is already listen on this port, I added code for this, but on some servers it doesn’t show process that run on 3307 port, even if there are such processes. I need help to improve this script. I don’t have much experience with shell programming.

#!/bin/bash

STAT=`netstat -na | grep 3308 | awk '{print $6}'`
if [ "$STAT" = "LISTEN" ];
then
    echo "There is already process that listen on port 3307"
fi

# Create ramdisk
mkdir -p /mnt/ramdisk
mount -t tmpfs -o size=1G tmpfs /mnt/ramdisk
chown mysql:mysql /mnt/ramdisk

port=3307

distribution=$(lsb_release -i | cut -f2)


if [ $distribution == 'Debian' ]
then
    mkdir /var/lib/mysql2
    chown -R mysql.mysql /var/lib/mysql2/
    mkdir /var/log/mysql2
    chown -R mysql.mysql /var/log/mysql2
    cp -R /etc/mysql/ /etc/mysql2
    cd /etc/mysql2/
    sed -i "s/3306/$port/g" my.cnf
    sed -i "s/mysqld.sock/mysqld2.sock/g" my.cnf
    sed -i "s/mysqld.pid/mysqld2.pid/g" my.cnf
    sed -i "s/var\/lib\/mysql/var\/lib\/mysql2/g" my.cnf
    sed -i "s/var\/log\/mysql/var\/log\/mysql2/g" my.cnf
    mysql_install_db --user=mysql --datadir=/mnt/ramdisk
    mysqld_safe --defaults-file=/etc/mysql2/my.cnf &
elif [ $distribution == 'CentOS' ]
then
    cp /etc/my.cnf /etc/my2.cnf
    cd /etc
    sed -i "s/3306/$port/g" my2.cnf
    sed -i "s/mysqld.sock/mysqld2.sock/g" my2.cnf
    sed -i "s/mysqld.pid/mysqld2.pid/g" my2.cnf
    sed -i "s/var\/lib\/mysql/var\/lib\/mysql2/g" my2.cnf
    sed -i "s/var\/log\/mysql/var\/log\/mysql2/g" my2.cnf
    mysql_install_db --user=mysql --datadir=/mnt/ramdisk
    mysqld_safe --defaults-file=/etc/my2.cnf &
else
    exit 13
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:05:43+00:00Added an answer on June 16, 2026 at 1:05 am

    Ignoring the fact that you used 3308 in your test, to check if something is listening on a port, you might instead want to use netcat, which simply tries to connect:

    if nc -z localhost "$port"
    then
      echo "Port $port is in use"
      exit 1
    fi
    

    You could similarly use lsof -i TCP:"$port" -s TCP:LISTEN which would have the perhaps desirable side effect of printing the listening command if there is one. The advantage of nc/lsof over parsing netstat is that you can’t parse it wrong (your case would break if an app listened to UDP port 13307 for example).

    You may want to add set -e as the second line. This will make bash abort if one of the commands fail (e.g. due to missing files or permissions), instead of pointlessly continuing with the next commands and potentially ruining something.

    You can also use multiple expressions in one sed command, and use different delimiters for s to avoid excessive escaping:

    sed -i -e 's/mysqld.pid/mysqld2.pid/g' \
           -e 's:/var/lib/mysql:/var/lib/mysql2/:g' \
           file
    

    Just in general, you may also want to sed -i '1i# Autogenerated file, do not edit' my.cnf to add a comment on the first line, so people won’t modify it and have their changes overwritten.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to run Jison unit tests, but the command fails. How do I fix
I have log4net loggers configured to run with my unit tests, but for a
I'm writing quite a few unit tests and using nosetests to run them. Nose
I'm using nosetests to run a few unit tests and show me our code
I'm trying to run unit tests written in QUnit using jsTestDriver. I'm getting ReferenceError:
I have some Objective-C [i-os] code that I would like to run unit tests
I would like to accomplish two things during my build process: Run unit tests
We want to run our unit tests on our TFS server. We are running
Steps: Run the build including unit tests. Expected result: the unit tests are executed
I want to run some Python unit tests from my Maven module. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.