shell 启动脚本
时间: 2023-12-02 19:43:05 浏览: 31
以下是一个简单的shell启动脚本的例子:
```shell
#!/bin/bash
# 脚本名称:start_app.sh
# 用途:启动应用程序
# 加载系统函数库
. /etc/init.d/functions
# 定义变量
APP_NAME="myapp"
APP_HOME="/opt/myapp"
APP_START_CMD="./start.sh"
APP_STOP_CMD="./stop.sh"
# 定义函数
start_app() {
cd $APP_HOME
$APP_START_CMD > /dev/null 2>&1 &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
action "Starting $APP_NAME: " /bin/true
else
action "Starting $APP_NAME: " /bin/false
fi
}
stop_app() {
cd $APP_HOME
$APP_STOP_CMD > /dev/null 2>&1 &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
action "Stopping $APP_NAME: " /bin/true
else
action "Stopping $APP_NAME: " /bin/false
fi
}
restart_app() {
stop_app
start_app
}
# 主程序
case "$1" in
start)
start_app
;;
stop)
stop_app
;;
restart)
restart_app
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
```
该脚本定义了三个变量:应用程序名称、应用程序安装目录和启动/停止命令。它还定义了三个函数:启动应用程序、停止应用程序和重启应用程序。最后,它使用case语句处理命令行参数,并调用相应的函数。