Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Toyo authored May 7, 2017
1 parent 1ed020c commit bfd7401
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
83 changes: 83 additions & 0 deletions other/aria2_centos
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
# chkconfig: 2345 90 10
# description: aria2 is a lightweight multi-protocol & multi-source command-line download utility.

### BEGIN INIT INFO
# Provides: aria2 is a lightweight multi-protocol & multi-source command-line download utility.
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2 is a lightweight multi-protocol & multi-source command-line download utility.
# Description: Start or stop the Aria2
### END INIT INFO

NAME="Aria2"
NAME_BIN="aria2c"

Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
RETVAL=0

check_running(){
PID=`ps -ef |grep "${NAME_BIN}" |grep -v "grep" | grep -v ".sh"| grep -v "init.d" |grep -v "service" |awk '{print $2}'`
if [[ ! -z ${PID} ]]; then
return 0
else
return 1
fi
}
do_start(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME (PID ${PID}) 正在运行..." && exit 0
else
nohup aria2c -c "${HOME}/.aria2" > "${HOME}/.aria2/aria2.log" 2>&1 &
sleep 2s
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME 启动成功 !"
else
echo -e "${Error} $NAME 启动失败 !"
fi
fi
}
do_stop(){
check_running
if [[ $? -eq 0 ]]; then
kill -9 ${PID}
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo -e "${Info} $NAME 停止成功 !"
else
echo -e "${Error} $NAME 停止失败 !"
fi
else
echo -e "${Info} $NAME 未运行"
RETVAL=1
fi
}
do_status(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME (PID $(echo ${PID})) 正在运行..."
else
echo -e "${Info} $NAME 未运行 !"
RETVAL=1
fi
}
do_restart(){
do_stop
do_start
}
case "$1" in
start|stop|restart|status)
do_$1
;;
*)
echo -e "使用方法: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL
81 changes: 81 additions & 0 deletions other/aria2_debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: aria2 is a lightweight multi-protocol & multi-source command-line download utility.
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2 is a lightweight multi-protocol & multi-source command-line download utility.
# Description: Start or stop the Aria2
### END INIT INFO

NAME="Aria2"
NAME_BIN="aria2c"

Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
RETVAL=0

check_running(){
PID=`ps -ef |grep "${NAME_BIN}" |grep -v "grep" | grep -v ".sh"| grep -v "init.d" |grep -v "service" |awk '{print $2}'`
if [[ ! -z ${PID} ]]; then
return 0
else
return 1
fi
}
do_start(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME (PID ${PID}) 正在运行..." && exit 0
else
nohup aria2c -c "${HOME}/.aria2" > "${HOME}/.aria2/aria2.log" 2>&1 &
sleep 2s
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME 启动成功 !"
else
echo -e "${Error} $NAME 启动失败 !"
fi
fi
}
do_stop(){
check_running
if [[ $? -eq 0 ]]; then
kill -9 ${PID}
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo -e "${Info} $NAME 停止成功 !"
else
echo -e "${Error} $NAME 停止失败 !"
fi
else
echo -e "${Info} $NAME 未运行"
RETVAL=1
fi
}
do_status(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info} $NAME (PID $(echo ${PID})) 正在运行..."
else
echo -e "${Info} $NAME 未运行 !"
RETVAL=1
fi
}
do_restart(){
do_stop
do_start
}
case "$1" in
start|stop|restart|status)
do_$1
;;
*)
echo "使用方法: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL

0 comments on commit bfd7401

Please sign in to comment.