shell - Aria2 工作初始化脚本

标签 shell init.d aria2

我希望 aria2 在系统启动时启动。我发现了不同的 init.d 脚本,但没有一个对我有用......

你能告诉我那个 init.d 脚本有什么问题吗?

#!/bin/sh
### BEGIN INIT INFO
# Provides: Aria2
# Required-Start: $network $local_fs $remote_fs
# Required-Stop:: $network $local_fs $remote_fs
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Aria2 - Download Manager
### END INIT INFO
NAME=aria2c
ARIA2C=/usr/local/bin/$NAME
PIDFILE=/var/run/$NAME.pid
CONF=/etc/aria2/aria2.conf
ARGS="--conf-path=${CONF} --enable-rpc --rpc-listen-all --daemon"
USER="aria2"
test -f $ARIA2C || exit 0
. /lib/lsb/init-functions

case "$1" in
start) log_daemon_msg "Starting aria2c" "aria2c"
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chuid $USER     --startas $ARIA2C -- $ARGS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping aria2c" "aria2c"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
log_end_msg $?
;;
restart|reload|force-reload)
log_daemon_msg "Restarting aria2c" "aria2c"
start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chuid $USER     --startas $ARIA2C -- $ARGS
log_end_msg $?
;;
status)
status_of_proc -p $PIDFILE $ARIA2C aria2c && exit 0 || exit $?
;;
*) log_action_msg "Usage: /etc/init.d/aria2c     {start|stop|restart|reload|force-reload|status}"
exit 2
;;
esac
exit 0

当我开始时,它说

[ ok ] Starting aria2c: aria2c.

但是当我用

看时

/etc/init.d/aria2c status

它说

[FAIL] aria2c is not running ... failed!

感谢您的帮助!

最佳答案

试试这个:

#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2c init script.
# Description: Starts and stops aria2 daemon.
### END INIT INFO

USER="root"
DAEMON=/usr/bin/aria2c
CONF=/etc/aria2/aria2.conf


start() {
if [ -f $CONF ]; then
logger -st ARIA2C "Starting aria2c daemon..."
nohup start-stop-daemon -S -c $USER -x $DAEMON -- -D --enable-rpc --conf-path=$CONF
else
logger -st ARIA2C "Couldn't start aria2 daemon (no $CONF found)"
fi
}

stop() {
logger -st ARIA2C "Stoping aria2c daemon..."
start-stop-daemon -o -c $USER -K -u $USER -x $DAEMON
}

status() {
dbpid=`pgrep -fu $USER $DAEMON`
if [ -z "$dbpid" ]; then
logger -st ARIA2C "aria2c daemon not running."
else
logger -st ARIA2C "aria2c daemon running..."
fi
}

case "$1" in
start)
start
sleep 1
;;
stop)
stop
sleep 1
;;
restart)
stop
sleep 2
start
;;
status)
status
;;
*)
echo "Usage: {start|stop|restart|status}"
exit 1
esac

exit 0

关于shell - Aria2 工作初始化脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28721073/

相关文章:

用于 cron 作业的 Linux 服务和源代码

bash - <<END_SCRIPT 同时通过 bash 连接到 FTP

bash - 如何使用 Bash 抑制命令的所有输出?

python - 在 Python3 中执行链式 bash 命令,包括多个管道和 grep

linux - 将文件内容传递给 docker exec

ruby - 如何通过 sudo 运行 ruby

centos - 在 Centos 6.5 上以不同的用户或服务帐户运行 filebeat

terminal - Aria2c - 如何下载大量文件并输出为 0.pdf、1.pdf、2.pdf ...?

download - 使用aria2c完成下载后如何立即关闭连接?