Last active
August 29, 2015 14:24
-
-
Save swanwish/7330b0cb98e832d995d9 to your computer and use it in GitHub Desktop.
Restart service
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 | |
if [ -z "$1" ]; then | |
echo Please pass the service name | |
exit | |
else | |
SERVICE_NAME=$1 | |
fi | |
if [ ! $2 ]; then | |
echo Set service dir as ~/servers | |
SERVICE_DIR=~/servers | |
else | |
SERVICE_DIR=$2 | |
fi | |
if [ ! $3 ]; then | |
echo Set service parameter as -port=8080 | |
SERVICE_PARAM="-port=8080" | |
else | |
SERVICE_PARAM="$3" | |
fi | |
echo Stop service $SERVICE_NAME | |
ps -ef | grep $SERVICE_NAME | grep -v grep | grep -v "$0" | awk '{print $2}' | xargs kill -9 | |
cd $SERVICE_DIR | |
ZIP_FILE_NAME=$SERVICE_NAME.tar.gz | |
if [ -f $ZIP_FILE_NAME ] | |
then | |
echo Extract $ZIP_FILE_NAME | |
tar xzf $ZIP_FILE_NAME | |
echo Remove $ZIP_FILE_NAME | |
rm $ZIP_FILE_NAME | |
fi | |
echo Start service $SERVICE_NAME | |
cd $SERVICE_DIR/$SERVICE_NAME | |
nohup ./$SERVICE_NAME $SERVICE_PARAM >> $SERVICE_NAME.log 2>&1 & | |
# Usage | |
# restart_service.sh fileserver ~/servers -port=8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment