Browse Source

服务脚本添加可以配置启动路径

tangs 6 năm trước cách đây
mục cha
commit
b5fcd8769a
2 tập tin đã thay đổi với 8 bổ sung1 xóa
  1. 6 0
      install.sh
  2. 2 1
      server.sh

+ 6 - 0
install.sh

@@ -6,12 +6,14 @@ show_usage="./install.sh -u(--user) user -n(--name) name -e(--exec) exec"
 server_name=""
 server_user=""
 server_exec=""
+server_path=""
 
 while [ -n "$1" ]; do
 	case "$1" in
 		-n|--name ) server_name=$2 ; shift 2;;
 		-u|--user ) server_user=$2 ; shift 2;;
 		-e|--exec ) server_exec=$2 ; shift 2;;
+		-d|--chdir ) server_path=$2 ; shift 2;;
 		* ) echo $show_usage; exit 1 ;;
 	esac
 done
@@ -29,11 +31,15 @@ elif [[ "" == $server_user ]]; then
 	exit 1
 fi
 
+test "" -ne $server_path || server_path=`pwd`
+
+
 serverd=/etc/init.d/${server_name}d
 cp -f server.sh $serverd
 
 sed -i "s!SERVER_NAME!$server_name!" $serverd
 sed -i "s!SERVER_USER!$server_user!" $serverd
 sed -i "s!SERVER_DAEMON!$server_exec!" $serverd
+sed -i "s!SERVER_PATH!$server_path!" $serverd
 
 echo "Install success!!!"

+ 2 - 1
server.sh

@@ -9,6 +9,7 @@ NAME=SERVER_NAME
 USER=SERVER_USER
 DAEMON=SERVER_DAEMON
 PROCESS=/var/run/$NAME.pid
+SERVERPATH=SERVER_PATH
 
 if [ ! -f "$DAEMON" ]; then
 	echo "$DAEMON not found"
@@ -24,7 +25,7 @@ start (){
 		exit
 	fi
 
-	start-stop-daemon --start --make-pidfile --background --pidfile=$PROCESS --user=$USER --exec=$DAEMON
+	start-stop-daemon --start --make-pidfile --background --pidfile=$PROCESS --chuid=$USER --chdir=$SERVERPATH --exec=$DAEMON
 	test $? -ne 0 || echo "$NAME start successful, pid(`cat $PROCESS`)"
 }