Created
January 17, 2017 21:19
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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