Skip to content

Instantly share code, notes, and snippets.

@wolf-sigma
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolf-sigma/d20906e23c80aebd8ff4 to your computer and use it in GitHub Desktop.
Save wolf-sigma/d20906e23c80aebd8ff4 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2c
# Required-Start: $network $syslog $local_fs
# Required-Stop: $network $syslog $local_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2c
# Description: aria2c is a lightweight multi-protocol & multi-source command-line download utility
### END INIT INFO
if [ -e /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
log_success() {
log_success_msg "$1"
}
log_failure() {
log_failure_msg "$1"
}
else
. /etc/rc.d/init.d/functions
log_success() {
echo_success
echo "$1"
}
log_failure() {
echo_failure
echo "$1"
}
fi
NAME=aria2c
CONF=/etc/aria2c.conf
DAEMON=/usr/bin/aria2c
DAEMONOPTS="--daemon=true --enable-rpc --rpc-listen-all" # --conf-path=$CONF"
PIDFILE=/var/run/$NAME.pid
RUNUSER=aria2
case "$1" in
start)
echo "Starting $NAME:"
sudo -u $RUNUSER $DAEMON $DAEMONOPTS > /dev/null 2>&1
PID=`pidof $NAME` > /dev/null 2>&1
if [ -z $PID ]; then
log_failure "failed"
else
echo $PID > $PIDFILE
log_success "started"
fi
;;
stop)
echo "Stopping $NAME:"
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
kill -HUP $PID
rm -f $PIDFILE
log_success "stopped"
else
log_failure "not running"
fi
;;
restart)
$0 stop && sleep 2 && $0 start
;;
status)
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
echo "$NAME pid $PID is running"
else
echo "$NAME is not running"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
@wolf-sigma
Copy link
Author

For Ubuntu. Tested on 14.04.1 LTS

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