Skip to content

Instantly share code, notes, and snippets.

@blackhuman
Forked from andrzejressel/aria2
Last active February 29, 2016 04:58
Show Gist options
  • Save blackhuman/35f7fdd74801c64dc886 to your computer and use it in GitHub Desktop.
Save blackhuman/35f7fdd74801c64dc886 to your computer and use it in GitHub Desktop.
init.d file for aria2c daemon (debian)
#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# 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="nas"
DAEMON=/usr/bin/aria2c
CONF=/etc/aria2.conf
start() {
if [ -f $CONF ]; then
echo "Starting aria2 daemon"
start-stop-daemon -S -c $USER -x $DAEMON -- -D --enable-rpc --conf-path=$CONF
else
echo "Couldn't start aria2 daemon for $USER (no $CONF found)"
fi
}
stop() {
start-stop-daemon -o -c $USER -K -u $USER -x $DAEMON
}
status() {
dbpid=`pgrep -fu $USER $DAEMON`
if [ -z "$dbpid" ]; then
echo "aria2c daemon for USER $USER: not running."
else
echo "aria2c daemon for USER $USER: running (pid $dbpid)"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
stop
start
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/aria2 {start|stop|reload|force-reload|restart|status}"
exit 1
esac
exit 0
@blackhuman
Copy link
Author

注意,使用USER="nas"这个指定的user来运行aria2时,可能因为某个文件的权限问题导致运行失败(比如/var/log/aria2.log的写权限),而失败的时候start-stop-daemon不返回任何错误结果。所以使用脚本前请确认单独在那个用户下运行aria2c的时候是可以正常运行的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment