Archive

Archive for the ‘Uncategorized’ Category

Unprivileged standalone instance of MySQL

November 21st, 2010 No comments

Small script to run a instance of mysql in my home directory using the binary provided by the OS. Maybe some day I will make it more usable but for the time being it suits my needs.

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
#!/bin/bash
 
MYSQL_HOME=$HOME
MYSQL_USER=$USER
MYSQL_PORT=13306
 
ACTION=$1
if [ $ACTION == 'init' ]; then
    echo "initalising new mysql installation at $MYSQL_HOME/var/lib/mysql"
    rm -rf $MYSQL_HOME/var/lib/mysql
    mkdir -p $MYSQL_HOME/var/lib/mysql $MYSQL_HOME/mysql/data $HOME/var/lib/mysql/tmp
    mysql_install_db --user=$MYSQL_USER  --datadir=$MYSQL_HOME/var/lib/mysql/data/
 
    cat < $HOME/.my.cnf
[mysqld]
user=$MYSQL_USER
datadir=$MYSQL_HOME/var/lib/mysql/data
log-error=mysqld.log
pid-file=mysqld.pid
socket=$MYSQL_HOME/var/lib/mysql/tmp/mysql.sock
port=$MYSQL_PORT
 
[client]
user=$MYSQL_USER
socket=$MYSQL_HOME/var/lib/mysql/tmp/mysql.sock
port=$MYSQL_PORT
 
[safe_mysqld]
log-error=mysqld.log
pid-file=mysqld.pid
port=$MYSQL_PORT
EOT
    echo "   Done"
 
elif [ $ACTION == 'start' ];then
    echo -n "Starting mysqld as $MYSQL_USER on $MYSQL_PORT"
    nohup mysqld_safe &>/dev/null &
    echo "   Done"
elif [ $ACTION == 'stop' ];then
    PID=$(cat $MYSQL_HOME/var/lib/mysql/data/mysqld.pid)
    echo -n "Stopping mysql instance [$PID]"
    kill `cat $MYSQL_HOME/var/lib/mysql/data/mysqld.pid`
    echo "   Done"
else
    echo "Unknown command '$1'"
 
fi

UPDATED SCRIPT:

I decided to update the script and make it less hacky

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
#!/bin/bash
 
MYSQL_HOME=$HOME
MYSQL_USER=$USER
MYSQL_PORT=13306
 
function init {
 
    echo "initalising new mysql installation at $MYSQL_HOME/var/lib/mysql"
    rm -rf $MYSQL_HOME/var/lib/mysql
    mkdir -p $MYSQL_HOME/var/lib/mysql $MYSQL_HOME/mysql/data $HOME/var/lib/mysql/tmp
    mysql_install_db --user=$MYSQL_USER  --datadir=$MYSQL_HOME/var/lib/mysql/data/
 
    cat <<EOT > $HOME/.my.cnf 
[mysqld]
user=$MYSQL_USER
datadir=$MYSQL_HOME/var/lib/mysql/data
log-error=mysqld.log
pid-file=mysqld.pid
socket=$MYSQL_HOME/var/lib/mysql/tmp/mysql.sock
port=$MYSQL_PORT
innodb_file_per_table
 
[client]
user=$MYSQL_USER
socket=$MYSQL_HOME/var/lib/mysql/tmp/mysql.sock
port=$MYSQL_PORT
 
[safe_mysqld]
log-error=mysqld.log
pid-file=mysqld.pid
port=$MYSQL_PORT
EOT
    echo "   Done"
}
 
function start {
    echo -n "Starting mysqld as $MYSQL_USER on $MYSQL_PORT"
    nohup mysqld_safe &>/dev/null &
    echo "   Done"
}
 
function stop {
    if [ -e $MYSQL_HOME/var/lib/mysql/data/mysqld.pid ]; then
        PID=$(cat $MYSQL_HOME/var/lib/mysql/data/mysqld.pid)
        echo -n "Stopping mysql instance [$PID]"
        kill $PID
        echo "   Done"
    else
        echo "mysqld.pid file doesnt exist"
    fi
}
 
function usage {
    echo "Unknown command '$1'"
}
 
function status {
    if [ -e $MYSQL_HOME/var/lib/mysql/data/mysqld.pid ]; then
        PID=$(cat $MYSQL_HOME/var/lib/mysql/data/mysqld.pid)
        ps -p $PID &>/dev/null
        RTN=$?
    else
        RTN=-1
    fi
    if [ $RTN -eq 0 ]; then
        echo "Mysql Running, pid:$PID"
    elif [ $RTN -eq 1 ]; then
        echo "mysql stopped but pidfile exists"
    elif [ $RTN -eq -1 ]; then
        echo "Stopped"
    fi
}
 
case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        status)
            status
            ;;
        restart)
            stop
            start
            ;;
        init)
            init
            ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart|init}"
            exit 1
esac
Categories: Linux, Uncategorized Tags: ,

Installing Thrift on Fedora 13 (Goddard)

July 22nd, 2010 No comments

From Thrift Site – “Thrift is a software framework for scalable cross-language services development. It combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk, and OCaml.”

When I initially tried to install thrift I had some difficulty because of an error which follows. This error makes you think you need something to do with boost but I am pretty sure the issue was that I was missing gcc-c++

checking for boostlib >= 1.33.1... configure: error: We could not detect the boost libraries (version 1.33 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost  for more documentation.

I did this on a ‘Desktop’ install on my laptop so this may not be every package required. You will need to install at least the following packages.

yum -y install autocon automake libtool flex \
 boost-devel gcc-c++ perl-ExtUtils-MakeMaker byacc

Download the thrift from subversion to get the latest and greatest.

svn co http://svn.apache.org/repos/asf/incubator/thrift/trunk thrift
cd thrift

Then, following the README, you need to do the following.

./bootstrap.sh
 
./configure
 
make
 
sudo make install

And that appears to be it. If you find any issues please leave a comment and I will try on an @base install of Fedora to iron out any other dependencies.

Categories: Uncategorized Tags: ,