Files
aigrammar/service.sh
2024-08-17 04:29:48 +00:00

40 lines
900 B
Bash

#!/bin/bash
# 确保脚本使用一个参数
if [ $# -ne 1 ]; then
echo "Usage: $0 {start|stop|restart}"
exit 1
fi
# 定义程序的目录路径
program_dir="/usr/local/aigrammar"
program_name="aigrammar"
log_file="output.log"
case "$1" in
start)
echo "Starting $program_name..."
cd $program_dir
nohup ./$program_name > $log_file 2>&1 &
echo "$program_name started."
;;
stop)
echo "Stopping $program_name..."
killall $program_name
echo "$program_name stopped."
;;
restart)
echo "Restarting $program_name..."
killall $program_name
sleep 2
cd $program_dir
nohup ./$program_name > $log_file 2>&1 &
echo "$program_name restarted."
;;
*)
echo "Unknown command: $1"
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac