A simple starter script to copy a node app to a remote host and start it over ssh.
Not very robust in terms of order-dependent argument handling. Arguments have defaults, but if you provide a value for one, any preceding args must also be supplied.
Arguments
- The source directory. Defaults to current directory.
- The destination server for the ssh connection.
- The port to run the app on the destination server. Defaults to port 80.
#!/bin/sh
# source
DIR=${1:-`pwd`}
DIRPATH=$(dirname $DIR)
# destination
HOST=${2:-default.server.com}
APPPORT=${3:-80}
TARGETPATH=node
DIRNAME=$(basename $DIR)
# don't want to be prompted by ssh for first time remote hosts.
alias ssh='ssh -o StrictHostKeyChecking=no'
# push app to host
# ssh root@$HOST 'cd node; rm -rf *'
cd $DIRPATH; tar czf - $DIRNAME | ssh root@$HOST '(cd $TARGETPATH; rm -rf *; tar xzf -)'
# start app
# ssh root@$HOST "cd $TARGETPATH/$DIRNAME; PORT=$APPPORT; npm start"