Skip to content

Instantly share code, notes, and snippets.

@nickdiego
Created January 17, 2017 21:19
Show Gist options
  • Select an option

  • Save nickdiego/c0042759bb02a160b14e704c20908b77 to your computer and use it in GitHub Desktop.

Select an option

Save nickdiego/c0042759bb02a160b14e704c20908b77 to your computer and use it in GitHub Desktop.
Shell script to start node server (can be used as a cron job)
#!/bin/bash
USERHOME=${HOME:-/home/nick}
SERVER_ROOT="${USERHOME}/projects/drunk-waiter/src/server-prototype"
RUN_SERVER_IN_TMUX=1 # set here or export in ~/.bashrc
tmuxsession='server'
logfile="${SERVER_ROOT}/server.log"
commands=(
"source '${USERHOME}/.bashrc';"
"cd '${SERVER_ROOT}';"
"npm start 2>&1 | tee '$logfile';"
)
if (( $RUN_SERVER_IN_TMUX )); then
tmux has-session -t $tmuxsession &>/dev/null ||
tmux new-session -d -s $tmuxsession
tmux send-keys -t $tmuxsession "${commands[*]}"
tmux send-keys -t $tmuxsession Enter
else
eval "${commands[*]}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment