.netcore linux开机自启脚本

开启脚本:

#!/bin/bash

APP_NAME=Host
SERVICE_NAME=Webapi
DLL_NAME=$SERVICE_NAME.dll
PID=$SERVICE_NAME.pid

PIDS=`ps -ef|grep -w "$DLL_NAME"|grep -v "grep"|awk '{print $2}'`
if [ -n "$PIDS" ]; then
	echo "ERROR: The $SERVICE_NAME already started!"
	echo "PID: $PIDS"
	exit 1
fi

echo -e "Starting the $SERVICE_NAME ...c"
nohup  /home/dotcore/dotnet  $DLL_NAME>/dev/null 2>&1 &

echo "OK!"
PIDS=`ps -ef|grep $DLL_NAME|grep -v "grep" |awk '{print $2}'`
echo "PID: $PIDS"

  暂停:

#!/bin/bash

APP_NAME=Host
SERVICE_NAME=Webapi
DLL_NAME=$SERVICE_NAME.dll
PID=$SERVICE_NAME.pid

PIDS=`ps -ef|grep -w "$DLL_NAME"|grep -v "grep"|awk '{print $2}'`
if [ -z "$PIDS" ]; then
	echo "ERROR: The $SERVICE_NAME does not started!"
	exit 1
fi

echo -e "Stopping the $SERVICE_NAME ...c"
for PID in $PIDS; do
	kill -9 $PID > /dev/null 2>&1
done

COUNT=0
while [ $COUNT -lt 1 ]; do
	echo -e ".c"
	sleep 1
	COUNT=1
	for PID in $PIDS; do
		PID_EXIST=`ps -f -p $PID|grep $DLL_NAME`
		if [ -n "$PID_EXIST" ]; then
			COUNT=0
			break
		fi
	done
done

echo "OK!"
echo "PID: $PIDS"

  开机自启:

  mkdir -p /home/soc/topo/service
   sleep 1
 cp -r /00-install/06-netcoreservice/toposervice/*  /home/soc/topo/service
 chmod +x /home/soc/topo/service/Webapi.sh
  cd /home/soc/topo/service/
  sh start.sh
 echo "TOPO服务端启动完成"
chmod +x /etc/rc.d/rc.local
chmod +x  /home/soc/topo/service/Webapi.sh
echo "nohup /home/soc/topo/service/Webapi.sh >/dev/null 2>&1 &">>/etc/rc.d/rc.local

  启动程序脚本:Webapi.sh

#!/bin/sh
while true
do
   PROC_NOW=`ps -ef |grep Webapi.dll  | wc -l`
	if [ $PROC_NOW  -lt 2 ]; then
                sleep 5
               cd  /home/LASTOPO/toposervice
               nohup /usr/bin/dotnet Webapi.dll>/dev/null 2>&1 &
        	echo " started success."
	else
		sleep 10
        	echo "Webapi.dll is exists!"
	fi
		
done

  

原文地址:https://www.cnblogs.com/sunliyuan/p/13794519.html