添加权限
drwxr-xr-x -rwxr-xr-x
<strong>第一位:-代表文件,d代表目录<br> 用户、组用户、其他用户都是rwx形式,其中r表示读、w表示写、x表示可执行,-表示没有权限,拿用户组举例,r只能出现在第一个位置、w只能出现在第二个位置、x只能出现在第三位。<br> 如果我们将出现字符(可以是r、w、x)表示为1,出现-表示为0,那么对应二进制如下,r - - = 100、- w - = 010、- - x = 001、再转换成10进制,那么读=4、写=2、可执行=1,将转换为以下关系</strong>
第一位 | 用户 | 组用户 | 其他用户 |
- | rwx | r-x | r-x |
- | 7 | 5 | 5 |
chmod +777 /etc/rc.d/rc.local
##iot###
#
#
#/home/java/iot_auto_deploy.sh
nohup java -jar /home/java/iotserver.jar >/home/java/iot.log 2>&1 &
##tomcat##
/home/java/apache-tomcat-8.5.85/bin/startup.sh
##fastdfs###
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
###nginx###
#/usr/local/nginx/sbin/nginx
/usr/sbin/nginx
iot_auto_deploy.sh
#nohup java -jar /home/java/iotserver.jar >/home/java/iotlog.txt 2>&1 &
#
#
#!/bin/bash
# 定义变量
# 要运行的jar包路径,加不加引号都行。 注意:等号两边 不能 有空格,否则会提示command找不到
JAR_NAME="/home/java/iotserver.jar"
# 日志路径,加不加引号都行。 注意:等号两边 不能 有空格,否则会提示command找不到
LOG_PATh=/home/java/iot.log
# 如果输入格式不对,给出提示!
tips() {
echo ""
echo "WARNING!!!......Tips, please use command: sh iot_auto_deploy.sh [start|stop|restart|status]. For example: sh iot_auto_deploy.sh start "
echo ""
exit 1
}
# 启动方法
start() {
# 重新获取一下pid,因为其它操作如stop会导致pid的状态更新
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
# -z 表示如果$pid为空时执行
if [ -z $pid ]; then
nohup java -jar $JAR_NAME > /home/java/iotlog.log 2>&1 &
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
echo ""
echo "Service ${JAR_NAME} is starting!pid=${pid}"
echo "........................Here is the log.............................."
echo "....................................................................."
tail -f $LOG_PATh
echo "........................Start successfully!........................."
else
echo ""
echo "Service ${JAR_NAME} is already running,it's pid = ${pid}. If necessary, please use command: sh auto_deploy.sh restart."
echo ""
fi
}
# 停止方法
stop() {
# 重新获取一下pid,因为其它操作如start会导致pid的状态更新
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
# -z 表示如果$pid为空时执行。 注意:每个命令和变量之间一定要前后加空格,否则会提示command找不到
if [ -z $pid ]; then
echo ""
echo "Service ${JAR_NAME} is not running! It's not necessary to stop it!"
echo ""
else
kill -9 $pid
echo ""
echo "Service stop successfully!pid:${pid} which has been killed forcibly!"
echo ""
fi
}
# 输出运行状态方法
status() {
# 重新获取一下pid,因为其它操作如stop、restart、start等会导致pid的状态更新
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
# -z 表示如果$pid为空时执行。注意:每个命令和变量之间一定要前后加空格,否则会提示command找不到
if [ -z $pid ];then
echo ""
echo "Service ${JAR_NAME} is not running!"
echo ""
else
echo ""
echo "Service ${JAR_NAME} is running. It's pid=${pid}"
echo ""
fi
}
# 重启方法
restart() {
echo ""
echo ".............................Restarting.............................."
echo "....................................................................."
# 重新获取一下pid,因为其它操作如start会导致pid的状态更新
pid=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
# -z 表示如果$pid为空时执行。 注意:每个命令和变量之间一定要前后加空格,否则会提示command找不到
if [ ! -z $pid ]; then
kill -9 $pid
fi
start
echo "....................Restart successfully!..........................."
}
# 根据输入参数执行对应方法,不输入则执行tips提示方法
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
tips
;;
esac