Skip to content

Commit

Permalink
Merge pull request #9 from EricssonResearch/develop
Browse files Browse the repository at this point in the history
Upload script to run the IoT-F as a service
  • Loading branch information
Alberto Blázquez committed Nov 26, 2014
2 parents 2e45a56 + 333e657 commit c10097e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
55 changes: 55 additions & 0 deletions scripts/boot/iotf-gui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: rails
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start a Rails instance
# Description: Do the simplest thing possible in keeping with
# upstart to spin up a single Rails instance.
### END INIT INFO

# Author: Sam Pointer
#
# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/bin/
USER="ubuntu"
PORT=3000
RAILS_ROOT="/home/ubuntu/iot-framework-gui"
COMMAND="/home/ubuntu/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/rails s -p $PORT -d"
# COMMAND="rails s -p $PORT -d"
DESCRIPTION="Rails instance"

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
#cd $RAILS_ROOT && sudo bash --login -c "$COMMAND"
sudo su - ubuntu -c "cd $RAILS_ROOT; $COMMAND"
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESCRIPTION"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
esac
18 changes: 17 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/bash --login
touch ~/.bash_profile

install_boot_script() { # $1 is the script
sudo cp $PWD/scripts/boot/$1 /etc/init.d
if [ $? -ne 0 ]; then
echo "Call the script from the project folder"
else
echo "Success!"
sudo chmod +x /etc/init.d/$1
sudo update-rc.d $1 defaults
fi
}

echo "=============================================================================="
echo "Downloading RVM"
echo "=============================================================================="
Expand Down Expand Up @@ -64,4 +75,9 @@ bundle install --without production
echo "=============================================================================="
echo "Creates the database to be used for Ruby on Rails"
echo "=============================================================================="
bundle exec rake db:migrate
bundle exec rake db:migrate

echo "=============================================================================="
echo "Install a script to run the app as a Linux service"
echo "=============================================================================="
install_boot_script "iotf-gui"

0 comments on commit c10097e

Please sign in to comment.