Skip to content
Extraits de code Groupes Projets
server 2,32 ko
Newer Older
  • Learn to ignore specific revisions
  • #
    # Start diaspora websocket and main services
    #
    
    
    realpath=$( ruby -e "puts File.expand_path(\"$0\")")
    cd $( dirname $realpath)/..
    
    
    Alec Leamas's avatar
    Alec Leamas a validé
    [ -e config/server.sh ] && source config/server.sh
    
    
    function init_public
    # Create all dynamically generated files in public/ folder
    {
        bundle exec thin \
             -d --pid log/thin.pid --address localhost --port $THIN_PORT \
             start
        for ((i = 0; i < 20; i += 1)) do
            sleep 2
            wget -q -O tmp/server.html http://localhost:$THIN_PORT && \
                rm tmp/server.html && break
        done
        bundle exec thin --pid log/thin.pid stop
        if [ -e tmp/server.html ]; then
            echo "Cannot get index.html from web server (aborted)" >&2
            return 2
        fi
        bundle exec jammit
    }
    
    
    Alec Leamas's avatar
    Alec Leamas a validé
    # Scan for -p, find out what port thin is about to use.
    args="$DEFAULT_THIN_ARGS $@"
    prev_arg=''
    for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
    do
        [ "$prev_arg" = '-p' ] && THIN_PORT="$arg"
        prev_arg="$arg"
    
    # Is someone listening on the ports already? (ipv4 only test ?)
    
    Alec Leamas's avatar
    Alec Leamas a validé
    services=$( netstat -nl | grep '[^:]:'$THIN_PORT'[ \t]')
    
    if [ -n "$services" ]; then
    
    Alec Leamas's avatar
    Alec Leamas a validé
        echo "Error: thin port $THIN_PORT is already in use. Exiting" >&2
    
    Alec Leamas's avatar
    Alec Leamas a validé
    services=$( netstat -nl | grep '[^:]:'$SOCKET_PORT'[ \t]')
    
    if [ -n "$services" ]; then
    
    Alec Leamas's avatar
    Alec Leamas a validé
        echo "Error: websocket port $SOCKET_PORT is already in use. Exiting" >&2
    
    # Check if Mongo is running
    
    if  ! ps ax | grep -v grep | grep mongod >/dev/null
    
        echo "Error: Mongod not started. Exiting" >&2
        exit 64
    
    
    # Force AGPL
    if [ -w public -a ! -e  public/source.tar.gz ]; then
    
        tar czf public/source.tar.gz  `git ls-tree -r master | awk '{print $4}'`
    
    fi
    if [ ! -e public/source.tar.gz ]; then
        echo "Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
        exit 65
    fi
    
    
    # Precache jammit assets
    
    if [[ -w public  && ! -e public/stylesheets/application.css ]]; then
        if [ "$INIT_PUBLIC" != 'no' ]; then
            echo "Making first-time server initialization."
            init_public
        fi
    
    fi
    if [ ! -e 'public/assets/main.js.gz' ]; then
        echo 'Jammit precache error (now or at install)' >&2
        exit 66
    fi
    
    
    
    mkdir -p -v log/thin/
    bundle exec ruby ./script/websocket_server.rb&
    
    #bundle exec magent start --log-path=log/ &
    
    Alec Leamas's avatar
    Alec Leamas a validé
    bundle exec thin start $args