Created
August 9, 2012 19:01
-
-
Save christiannelson/3307133 to your computer and use it in GitHub Desktop.
Joyent SmartMachine scripts that set things up in a saner fashion than what's prescribed by the docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright 2011 Joyent, Inc. All rights reserved. | |
# | |
# Based on http://wiki.joyent.com/download/attachments/1639170/mongodbnode.sh | |
# Updated to configure mongo more similarly to how it's configured on a Mongo SmartMachine. | |
# Tested on v1.3.3 Node.js SmartMachine and MongoDB 2.0.7 | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root. Aborting..." 1>&2 | |
exit 1 | |
fi | |
if [[ $# -ne 1 ]] ; then | |
echo "Usage: $0 <version>" | |
echo "E.g.: $0 2.0.7" | |
exit 1 | |
fi | |
FILE=mongodb-sunos5-x86_64-$1 | |
INSTALL_DIR=/opt/local | |
MONGO_USER=mongod | |
MONGO_GROUP=mongod | |
if [[ $1 > '1.6.5' ]] ; then | |
JOURNAL_OPT=--journal | |
else | |
JOURNAL_OPT= | |
fi | |
if [[ ! -e $FILE.tgz ]] ; then | |
echo "Downloading $FILE.tgz..." | |
wget -nv http://fastdl.mongodb.org/sunos5/$FILE.tgz | |
if [[ ! -e $FILE.tgz ]] ; then | |
echo "No file downloaded; nothing to install." | |
exit 1 | |
fi | |
echo "Downloading was successful." | |
else | |
echo "$FILE.tgz already downloaded. Continuing..." | |
fi | |
echo "Untarring $FILE.tgz" | |
tar xvf $FILE.tgz | |
if [[ $? -ne 0 ]] ; then | |
echo "Problem untarring $FILE.tgz." | |
exit 1 | |
fi | |
echo "Creating mongod user and group." | |
groupadd $MONGO_GROUP | |
useradd -g $MONGO_GROUP -d /var/mongodb -s /opt/local/bin/pdksh $MONGO_USER | |
if [[ ! -d $INSTALL_DIR ]] ; then | |
echo "No $INSTALL_DIR found; creating one." | |
mkdir $INSTALL_DIR | |
fi | |
if [[ ! -d $INSTALL_DIR/bin ]] ; then | |
echo "No $INSTALL_DIR/bin found; creating one." | |
mkdir $INSTALL_DIR/bin | |
echo "export PATH=\$INSTALL_DIR/bin:\$PATH" >> ~/.bashrc | |
fi | |
if [[ ! -d $INSTALL_DIR/lib ]] ; then | |
echo "No $INSTALL_DIR/lib found; creating one." | |
mkdir $INSTALL_DIR/lib | |
fi | |
if [[ ! -d /var/mongodb ]] ; then | |
echo "No /var/mongodb found; creating one." | |
mkdir /var/mongodb | |
fi | |
chown $MONGO_USER.$MONGO_GROUP -R /var/mongodb | |
if [[ ! -d /var/log/mongod ]] ; then | |
echo "No /var/log/mongod found; creating one." | |
mkdir /var/log/mongod | |
fi | |
chown $MONGO_USER.$MONGO_GROUP -R /var/log/mongod | |
echo "Moving files to their final location." | |
mv $FILE/bin/* $INSTALL_DIR/bin | |
echo "Cleaning up files." | |
rm -rf $FILE/ | |
rm $FILE.tgz | |
echo "Installing MongoDB service..." | |
echo "<?xml version='1.0'?> | |
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> | |
<service_bundle type='manifest' name='export'> | |
<service name='application/mongodb' type='service' version='0'> | |
<create_default_instance enabled='false'/> | |
<single_instance/> | |
<dependency name='network' grouping='require_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/milestone/network:default'/> | |
</dependency> | |
<dependency name='filesystem' grouping='require_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/system/filesystem/local'/> | |
</dependency> | |
<method_context working_directory='/var/mongodb'> | |
<method_credential group='$MONGO_GROUP' user='$MONGO_USER'/> | |
</method_context> | |
<exec_method name='start' type='method' exec='$INSTALL_DIR/bin/mongod --fork --bind_ip=127.0.0.1 $JOURNAL_OPT --dbpath /var/mongodb --logpath /var/log/mongod/server.log --logappend' timeout_seconds='60'/> | |
<exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'/> | |
<property_group name='application' type='application'/> | |
<property_group name='startd' type='framework'> | |
<propval name='ignore_error' type='astring' value='core,signal'/> | |
</property_group> | |
<stability value='Evolving'/> | |
<template> | |
<common_name> | |
<loctext xml:lang='C'>MongoDB server</loctext> | |
</common_name> | |
</template> | |
</service> | |
</service_bundle> | |
" > $FILE.xml | |
pfexec svccfg import $FILE.xml | |
if [[ $? -ne 0 ]] ; then | |
echo "Problem adding SMF manifest for MongoDB service" | |
exit 1 | |
fi | |
rm $FILE.xml | |
echo | |
echo "Congratulations, MongoDB looks like it was successfully installed." | |
echo "The mongo binaries are in $INSTALL_DIR/bin and the data is in /var/mongodb" | |
echo "To start using MongoDB, run the following two commands:" | |
echo | |
echo " pfexec svcadm enable mongodb" | |
echo | |
echo "For security purposes, MongoDB is only listening for connections from 127.0.0.1." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Add new version of nodejs to a nodejs or no.de SmartMachine | |
# | |
# Based off of https://help.joyent.com/entries/21512976-adding-a-new-version-of-node-to-a-node-js-smartmachine | |
# | |
# Tested on v1.3.3 Node.js SmartMachine and node 0.8.8 | |
# Check to see if script is being run as the root user | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root. Aborting..." 1>&2 | |
exit 1 | |
fi | |
VERSION=$1 | |
if [ -z "$VERSION" ]; then | |
echo "Usage: $0 <version> (e.g. 0.8.8)" | |
exit 127 | |
fi | |
# Is the gcc compiler installed? If not, install | |
pkgin list | grep -q gcc-compiler | |
if [ $? -eq 1 ]; then | |
pkgin -f update # make sure the local repo is up to date | |
pkgin -y install gcc-compiler | |
fi | |
# Don't create the src dir if it already exists | |
if [ ! -e ~/src/ ]; then | |
mkdir ~/src | |
fi | |
cd ~/src | |
# Check if the version of node is installed, if so exit | |
if [ -e /opt/nodejs/v${VERSION}/ ]; then | |
echo "/opt/nodejs/v${VERSION}/ exists. ${VERSION} Already installed?" | |
exit 1 | |
fi | |
# Download, make and compile node | |
curl -O http://nodejs.org/dist/v${VERSION}/node-v${VERSION}.tar.gz | |
gtar -xpf node-v${VERSION}.tar.gz | |
cd node-v${VERSION}/ | |
./configure --with-dtrace --prefix=/opt/nodejs/v${VERSION}/ | |
gmake install | |
# Clean up but leave the ~/src directory | |
cd ~/ | |
rm -rf ~/src/node-v${VERSION}* | |
# Update the symlink so the local version of node is in sync | |
rm /home/node/local/nodejs | |
ln -s /opt/nodejs/v${VERSION} /home/node/local/nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install redis from source on a JoyentS SmartMachine and configure it as a service. | |
# | |
# Tested on v1.3.3 Node.js SmartMachine and and Redis 2.4.16 | |
# | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root. Aborting..." 1>&2 | |
exit 1 | |
fi | |
if [[ $# -ne 1 ]] ; then | |
echo "Usage: $0 <version>" | |
echo "E.g.: $0 2.4.16" | |
exit 1 | |
fi | |
# Is the gcc compiler installed? If not, install | |
pkgin list | grep -q gcc-compiler | |
if [ $? -eq 1 ]; then | |
pkgin -f update # make sure the local repo is up to date | |
pkgin -y install gcc-compiler | |
fi | |
FILE=redis-$1 | |
INSTALL_DIR=/opt/local | |
REDIS_USER=redis | |
REDIS_GROUP=redis | |
if [[ ! -e $FILE..tar.gz ]] ; then | |
echo "Downloading $FILE.tar.gz..." | |
wget -nv wget http://redis.googlecode.com/files/$FILE.tar.gz | |
if [[ ! -e $FILE.tar.gz ]] ; then | |
echo "No file downloaded; nothing to install." | |
exit 1 | |
fi | |
echo "Downloading was successful." | |
else | |
echo "$FILE.tar.gz already downloaded. Continuing..." | |
fi | |
echo "Untarring $FILE.tar.gz" | |
tar xvf $FILE.tar.gz | |
if [[ $? -ne 0 ]] ; then | |
echo "Problem untarring $FILE.tar.gz." | |
exit 1 | |
fi | |
echo "Creating user and group." | |
groupadd $REDIS_GROUP | |
useradd -g $REDIS_GROUP -d /var/redis -s /opt/local/bin/pdksh $REDIS_USER | |
if [[ ! -d $INSTALL_DIR ]] ; then | |
echo "No $INSTALL_DIR found; creating one." | |
mkdir $INSTALL_DIR | |
fi | |
if [[ ! -d $INSTALL_DIR/bin ]] ; then | |
echo "No $INSTALL_DIR/bin found; creating one." | |
mkdir $INSTALL_DIR/bin | |
echo "export PATH=\$INSTALL_DIR/bin:\$PATH" >> ~/.bashrc | |
fi | |
if [[ ! -d $INSTALL_DIR/lib ]] ; then | |
echo "No $INSTALL_DIR/lib found; creating one." | |
mkdir $INSTALL_DIR/lib | |
fi | |
if [[ ! -d /var/redis ]] ; then | |
echo "No /var/redis found; creating one." | |
mkdir /var/redis | |
fi | |
chown $REDIS_USER.$REDIS_GROUP -R /var/redis | |
if [[ ! -d /var/log/redis ]] ; then | |
echo "No /var/log/redis found; creating one." | |
mkdir /var/log/redis | |
fi | |
chown $REDIS_USER.$REDIS_GROUP -R /var/log/redis | |
echo "Building redis." | |
cd $FILE | |
make | |
if [[ $? -ne 0 ]] ; then | |
echo "Problem building redis from source" | |
exit 1 | |
fi | |
echo "Moving files to their final location." | |
find src -name "redis*" -type f -perm +111 -exec mv {} $INSTALL_DIR/bin \; | |
cat redis.conf | sed "s/^dir .*$/dir \/var\/redis/" | sed "s/^daemonize no/daemonize yes/" > $INSTALL_DIR/etc/redis.conf | |
cd .. | |
echo "Cleaning up files." | |
rm -rf $FILE/ | |
rm $FILE.tar.gz | |
echo "Installing Redis service..." | |
echo "<?xml version='1.0'?> | |
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> | |
<service_bundle type='manifest' name='export'> | |
<service name='application/redis' type='service' version='0'> | |
<create_default_instance enabled='false'/> | |
<single_instance/> | |
<dependency name='network' grouping='require_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/milestone/network:default'/> | |
</dependency> | |
<dependency name='filesystem' grouping='require_all' restart_on='error' type='service'> | |
<service_fmri value='svc:/system/filesystem/local'/> | |
</dependency> | |
<method_context working_directory='/var/redis'> | |
<method_credential group='$REDIS_GROUP' user='$REDIS_USER'/> | |
</method_context> | |
<exec_method name='start' type='method' exec='$INSTALL_DIR/bin/redis-server %{config_file}' timeout_seconds='60'/> | |
<exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'/> | |
<property_group name='startd' type='framework'> | |
<propval name='duration' type='astring' value='contract'/> | |
<propval name='ignore_error' type='astring' value='core,signal'/> | |
</property_group> | |
<property_group name='application' type='application'> | |
<propval name='config_file' type='astring' value='$INSTALL_DIR/etc/redis.conf'/> | |
</property_group> | |
<stability value='Evolving'/> | |
<template> | |
<common_name> | |
<loctext xml:lang='C'>Redis server</loctext> | |
</common_name> | |
</template> | |
</service> | |
</service_bundle>" > $FILE.xml | |
pfexec svccfg import $FILE.xml | |
if [[ $? -ne 0 ]] ; then | |
echo "Problem adding SMF manifest for Redis service" | |
exit 1 | |
fi | |
rm $FILE.xml | |
echo | |
echo "Congratulations, Redis looks like it was successfully installed." | |
echo "The redis binaries are in $INSTALL_DIR/bin and the data is in /var/redis" | |
echo "To start using Redis, run the following two commands:" | |
echo | |
echo " pfexec svcadm enable redis" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment