install from script?

djsodom

Active Member
#1
Hi,

I'm trying to configure a rails capistrano script to be used with Amazon's EC2 virtual servers. My script is designed to setup my entire server from script, including litespeed. I'm stuck on the LS .install.sh script. Part of the script wget's the latest litespeed package.

Is there a way to configure litespeed from the command line with script?

(I know I could just install litespeed and then save and register a new image. But I'd like to do it all from script for flexibility and automation sake.)
------
I've included part of my deploy script below to give you a better sense:
PHP:
task :install_software do
  #Ruby Gems
  run <<-CMD
      wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz &&
      tar -xvf rubygems-0.9.0.tgz
  CMD
  
  run "cd rubygems-0.9.0 && sudo ruby setup.rb" do |channel, stream, data|
      if data =~ /^Password:/
        channel.send_data "mypassword\n"
      end
  end
  
  cleanup
  run "cd .. && rm ruby* -drf"
  
  #Rails
  sudo "gem install -y --no-rdoc --no-ri rails"
  
  #Litespeed's ruby-lsapi
  sudo "gem install ruby-lsapi"
  
  #litespeed
  run <<-CMD
    wget http://litespeedtech.com/packages/2.2/std/lsws-2.2.6-std-i386-linux.tar.gz &&
    tar -xvf lsws-2.2.6-std-i386-linux.tar.gz
  CMD
  
  run "cd lsws-2.2.6 && sudo ./install.sh" do |channel, stream, data|
      if data =~ /^Password:/
        channel.send_data "mypassword\n"
      end
  end
end
 

mistwang

LiteSpeed Staff
#2
Yes, it is possible, you can take a look at two functions in "functions.sh", "buildConfigFiles()" and "installation()", set all environment variables used in those two functions, then call those two functions to install the server.
 
#3
I'm giving this a shot now. Do we also have to run admin_login or at least the last bit:

Code:
ENCRYPT_PASS=`"$LSINSTALL_DIR/admin/fcgi-bin/admin_php" -q "$LSINSTALL_DIR/admin/misc/htpasswd.php" $PASS_ONE`
		echo "$ADMIN_USER:$ENCRYPT_PASS" > "$LSINSTALL_DIR/admin/conf/htpasswd"
??

I'll post my solution when I have it working.
 
#5
Ok, I've got a version that's working locally. There may be more than is needed in here, but this worked for me on OS X. I'm going to try it on a slicehost slice next.

Edit: I cannot figure out how to attach a file, so:

Code:
#!/bin/sh
# A script to remotely install Litespeed server using Capistrano/Deprec
# Lots of stuff from litespeed's functions.sh pulled out to avoid
# all the interactive bits.


# set up an admin user, definitely change these
  ADMIN_USER=YOUR_ADMIN_USER
  PASS_ONE=YOUR_ADMIN_USER_PASS

# Maybe you want to change these, values assume setup by root
  WS_USER=nobody
  WS_GROUP=nogroup
  HTTP_PORT=80
  ADMIN_PORT=8000
	LSWS_HOME=/usr/local/lsws
  

# assuming nothing below here is going to be changed, all from functions.sh
  LSINSTALL_DIR=`dirname "$0"`
  cd $LSINSTALL_DIR
	INST_USER=`id`
	INST_USER=`expr "$INST_USER" : 'uid=.*(\(.*\)) gid=.*'`

	DIR_OWN=$WS_USER:$WS_GROUP
	CONF_OWN=$WS_USER:$WS_GROUP
	DIR_MOD=755
	SDIR_MOD=700
	EXEC_MOD=555
	CONF_MOD=600
	DOC_MOD=644

# I build php from source with lsapi, so this script doesn't take php or php cache setup into account.
  SETUP_PHP=0

# handy bit from install.sh
  source ./functions.sh 2>/dev/null
  if [ $? != 0 ]; then
      . ./functions.sh
      if [ $? != 0 ]; then
          echo [ERROR] Can not include 'functions.sh'.
          exit 1
      fi
  fi

# all of this is straight from functions.sh	
	SYS_NAME=`uname -s`
	if [ "x$SYS_NAME" = "xFreeBSD" ] || [ "x$SYS_NAME" = "xNetBSD" ] || [ "x$SYS_NAME" = "xDarwin" ] ; then
		PS_CMD="ps -ax"
		ID_GROUPS="id"
        TEST_BIN="/bin/test"
		ROOTGROUP="wheel"
    else
		PS_CMD="ps -ef"
		ID_GROUPS="id -a"
        TEST_BIN="/usr/bin/test"
		ROOTGROUP="root"
	fi
	
	VERSION=`cat VERSION`

#stop any running servers. Straight from functions.sh
  $LSINSTALL_DIR/bin/lswsctrl stop
  sleep 1
  RUNNING_PROCESS=`$PS_CMD | grep lshttpd | grep -v grep`
  if [ "x$RUNNING_PROCESS" != "x" ]; then
  	echo "Failed to stop server, abort installation!"
  	exit 1
  fi

# encrypt admin pass and add it to htaccess. Straight from functions.sh
  ENCRYPT_PASS=`"$LSINSTALL_DIR/admin/fcgi-bin/admin_php" -q "$LSINSTALL_DIR/admin/misc/htpasswd.php" $PASS_ONE`
  echo "$ADMIN_USER:$ENCRYPT_PASS" > "$LSINSTALL_DIR/admin/conf/htpasswd"
  
  configRuby
  
# Create the installation directory. Straight from functions.sh
	if [ ! -d "$LSWS_HOME" ]; then
		mkdir "$LSWS_HOME"
	fi

# install the server
  buildConfigFiles
  installation

# install awstats
  $LSWS_HOME/admin/misc/awstats_install.sh

# install startup script
  $LSWS_HOME/admin/misc/rc-inst.sh
 
Last edited:
#7
Now I'm going to work on my recipe. I use deprec, with a lot of modifications, so I may just post the litespeed task once I get it working.


It occurs to me that there are several ways to do this.
1. Use my separate install script posted above.
2. Use "sudo ENV_VAR="foo"; EXPORT ENV_VAR; install.sh"
3. Use deprec's run_with_input or sudo_with_input (maybe)

Implications:
1. Have to edit this file and have something in your recipe to upload it. Might be better to just over-write the default install.sh with my version.
2. That's a lot of variables to set and export.
3. I don't know if this can accept multiple regex's. Also requires a human to monitor the install process.
 
Last edited:
Top