Customizable OrientDB installer script
Hmmm, So, want to install orientdb huh!!!!
I remember the day I wanted to learn more about graph databases and try few of them in my ubuntu desktop. The first graph database that I came across was the Neo4j. At that time my thought was to find a database that would leave the troubles of worrying about the license with the features I wanted. So, then immediately I had to rule out Neo4j because of its licensing(free for only opensource projects) and community edition was lacking many features.
Then I again my hunt for free graph database started, found ArangoDB. I really had very nice time with it. Installation was straight-forward. Just download the package, double click install or (all right, but wait I like the apt-get way :)) install it through package manager, done. Either way installation was very quick and painless. But, again after few weeks of trying found that it lacked support to sharding (but it has been introduced in the later releases along with lot many new features).
Then once again my search continued and finally found my candy, OrientDB with every feature that I wanted to replace MongoDB along with graph database support. And most of all, it had a community edition too (left me with sigh of relief, Oh god!, finally I can start trying it without a fear of starting a whole new search again).
My idea was and still is to build a social networking engine using nodejs (not to compete facebook :), but) to start doing something new other than what I do in my workplace. There was another story to pick a all-in-one web application framework. After around 3 months or searching and trying out frameworks, I settled with SailsJs.
Oh, god, I must say this
what a framework man
It had everything for me to build an web application and API server. So, I finally started it and made a little progress to what it is now here.
SailsJs framework comes with its own ORM framework called waterline. There was no waterline adapter available to use orientdb in my application. After spending few sleepless nights, I came up with my own adapter. An yeah, I had to do few workarounds to support the features that I needed like creating edges automatically based on how models are configured.
I think, I am deviating from what I really wanted to publish. Lets get to the real matter,
hhmm hmmm, so we want to install orientdb. When I first tried to install I followed one of the wytze's blog posts, exactly this one. Many thanks to him.
I had to install the same in my personal vps too. So, first few times just manually did as how it was mentioned in that blog post. Then new versions got released and I had to do same thing again again in my desktop and vps. So, I wanted to minimize the time that I spend on updating it everytime I want to or need to. Then I created a bash script by compiling the instructions from that post. The script is here,
# $1 - user group who manages the orientdb, $2 user in the group who is going to use currently
#installation directory
INSTALL_DIR="/opt/orientdb"
#url to download the orientdb package
url="http://www.orientechnologies.com/[email protected]&file=orientdb-community-2.0-rc1.tar.gz&os=linux"
#name of the file that will be downloaded from url
FILE_NAME="$PWD/orientdb-community-2.0-rc1.tar.gz"
#actual directory name where the dowloaded package would be installed
DIR_NAME="$PWD/orientdb-community-2.0-rc1"
if [ ! -f "/etc/init.d/orientdb.sh" ]; then
echo "Attempting to stop, orientdb service of previous version"
sudo /etc/init.d/orientdb.sh stop
fi
if [ ! -f "$FILE_NAME" ]; then
wget -O $FILE_NAME "$url"
fi
if [ ! -d "$DIR_NAME" ]; then
tar -zxvf $FILE_NAME
fi
if [ -d "$INSTALL_DIR" ]; then
sudo rm $INSTALL_DIR -r
fi
if [ ! -d "$INSTALL_DIR" ]; then
sudo mkdir $INSTALL_DIR
fi
echo "copy from $DIR_NAME to $INSTALL_DIR"
sudo cp $DIR_NAME/* $INSTALL_DIR -r
cd /opt
#echo "create shortcut for $DIR_NAME as $INSTALL_DIR"
#sudo ln -s $DIR_NAME/ $INSTALL_DIR
sudo nano $INSTALL_DIR/config/orientdb-server-config.xml
# -d, --home-dir HOME_DIR home directory of the new account
# -M, --no-create-home do not create the user's home directory
# -r, --system create a system account
# -s, --shell SHELL login shell of the new account (/bin/false = no login)
# -U, --user-group create a group with the same name as the user
sudo useradd -d $INSTALL_DIR -M -r -s /bin/false -U $1
echo "configuring permissions for bin and log directory under $INSTALL_DIR"
sudo chown -R orientdb.orientdb orientdb*
sudo chmod 775 $INSTALL_DIR/bin
sudo chmod g+x $INSTALL_DIR/bin/*.sh
sudo chmod 775 $INSTALL_DIR/log
sudo usermod -a -G orientdb $2
cd /etc/init.d
echo "Removing existing init.d script"
if [ ! -f "/orientdb.sh" ]; then
sudo update-rc.d -f orientdb.sh remove
sudo rm orientdb.sh
fi
echo "Publishing service from $INSTALL_DIR/bin/orientdb.sh"
sudo cp $INSTALL_DIR/bin/orientdb.sh /etc/init.d/
sudo sed -i "s|$INSTALL_DIR|;s|$2|orientdb|" /etc/init.d/orientdb.sh
echo "Editing service configuration at /etc/init.d/orientdb.sh"
sudo nano /etc/init.d/orientdb.sh
sudo update-rc.d orientdb.sh defaults
echo "Setting execution rights"
sudo chmod +x /etc/init.d/orientdb.sh
echo "Starting orient db...."
sudo /etc/init.d/orientdb.sh start
if [ -f "$FILE_NAME" ]; then
rm $FILE_NAME
fi
if [ -d "$DIR_NAME" ]; then
rm $DIR_NAME -r
fi
Just save the above script into a file (for example: orientdbinstaller.sh) or link to file is provided at the end of this post.
then in your terminal type,
sudo bash orientdbinstaller.sh [THE GROUP NAME OF ORIENT DB USER] [USER NAME WHO SHOULD BE GIVEN ACCESS TO]
Note: exclude square brackets []
Before we want to install new version of OrientDB we have to configure the installer with the URL to download the package from, the file name and directory name where the package should be installed.
#installation directory
INSTALL_DIR="/opt/orientdb"
#url to download the orientdb package
url="http://www.orientechnologies.com/[email protected]&file=orientdb-community-2.0-rc1.tar.gz&os=linux"
#name of the file that will be downloaded from url
FILE_NAME="orientdb-community-2.0-rc1.tar.gz"
#actual directory name where the dowloaded package would be installed
DIR_NAME="orientdb-community-2.0-rc1"
That's it, we are left with just one step to complete after running the installer script, at the end of the execution, the script will show orientdb startup configuration file, there we just have to set the following two variables
ORIENTDB_DIR="[THE VALUE OF "INSTALL_DIR" VARIABLE SET IN INSTALLER GOES HERE]"
ORIENTDB_USER="[THE SECOND PARAMETER THAT WE SENT TO INSTALLER GOES HERE]"
and save, exit done. Phew...! The orientdb is installed.