Skip to content

Instantly share code, notes, and snippets.

@shad0wuser
Last active January 2, 2018 22:36
Show Gist options
  • Save shad0wuser/94796176ce36102e998236cf97f419f7 to your computer and use it in GitHub Desktop.
Save shad0wuser/94796176ce36102e998236cf97f419f7 to your computer and use it in GitHub Desktop.
Bash script to start, stop and restart any processes.

Bash Script to Start, Stop and Restart the process.

Script for start, stop and restart the processe. And also it shows the status.

#!/bin/bash  

server_root=~/path/to/my/working-directory
log_file=$server_root/path/to/log/log.file

startme() {
	cd $server_root
	first_command &
	second_command &
}

stopme() {
	pkill -f "1st_process_name" 
	pkill -f "2nd_process_name"
}
statusme() {
	tail -f $log_file
}

case "$1" in 
	start)   	startme ;;
	stop)    	stopme ;;
	restart) 	stopme; startme ;;
	status)		statusme ;;
	*) echo 	"Usage: $0 start|stop|restart|status" >&2
		   		exit 1
		   		;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment