Skip to content

Instantly share code, notes, and snippets.

@yashodhank
Forked from stackia/homebrew.mxcl.aria2.plist
Last active April 17, 2024 05:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashodhank/f18c5e545d6c2babc941c847e2003ca7 to your computer and use it in GitHub Desktop.
Save yashodhank/f18c5e545d6c2babc941c847e2003ca7 to your computer and use it in GitHub Desktop.
aria2c daemon start at boot. Put this file into /Library/LaunchDaemons, them 'chmod 600' and 'chown root'. Remember to fill REPLACE_WITH_YOUR_ placeholders below.

Title: Starting and Stopping Aria2 as a Service on Mac M1/M2 (Apple Silicon) Devices

Introduction:

If you are using a Mac with Apple Silicon (M1/M2) and want to start and stop the Aria2 download manager as a service using Homebrew, this tutorial is for you. We will walk you through the process of creating the necessary file for Aria2 to work seamlessly with Homebrew on your Mac M1/M2 device.

Step 1: Install Aria2 using Homebrew

Ensure that you have Aria2 and Homebrew installed on your Mac. If you haven't installed them yet, you can follow the installation instructions on their respective websites:

  • Homebrew: https://brew.sh/
  • Aria2: install using brew install aria2
  • AriaNG: Optionally GUI for easy management install using brew install ariang

Step 2: Create the Aria2 Service File

To enable the brew services commands for Aria2, you will need to create a service file under the Aria2 installation directory in Homebrew. Follow these steps:

  1. Open Terminal on your Mac.
  2. Navigate to the Aria2 installation directory in Homebrew. In this example, the Aria2 version is 1.36.0_1. Adjust the path accordingly if you have a different version installed:
cd /opt/homebrew/Cellar/aria2/1.36.0_1/
  1. Create a new file called homebrew.mxcl.aria2.plist in this directory. You can use a text editor like nano or vim to create and edit the file:
nano homebrew.mxcl.aria2.plist

OR

# Direct download link for homebrew.mxcl.aria2.plist file
curl -LRO https://gist.github.com/yashodhank/f18c5e545d6c2babc941c847e2003ca7/raw/homebrew.mxcl.aria2.plist
  1. Populate the file with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>KeepAlive</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>Label</key>
        <string>homebrew.mxcl.aria2</string>
        <key>ProgramArguments</key>
        <array>
                <string>/opt/homebrew/bin/aria2c</string>
                <string>--enable-rpc=true</string>
                <string>--rpc-secret=REPLACE_WITH_YOUR_SECRET_KEY</string>
                <string>--rpc-allow-origin-all=true</string>
                <string>--rpc-listen-all=true</string>
                <string>--rpc-listen-port=6800</string>
        </array>
        <key>WorkingDirectory</key>
        <string>/Users/REPLACE_WITH_YOUR_USER_NAME/Downloads/</string>
        <key>StandardErrorPath</key>
                <string>/usr/local/var/log/aria2.log</string>
        <key>StandardOutPath</key>
                <string>/usr/local/var/log/aria2.log</string>
</dict>
</plist>

Note:

  • Update Your own Secret Key: REPLACE_WITH_YOUR_SECRET_KEY
  • Update correct Path for working directory: /Users/REPLACE_WITH_YOUR_USER_NAME/Downloads/
  1. Save and close the file.

Step 3: Start and Stop Aria2 as a Service

Now that you have created the service file, you can start and stop Aria2 as a service using the brew services commands:

  • To start Aria2 as a service, run:
brew services start aria2
  • To stop Aria2 as a service, run:
brew services stop aria2

Optionally setting for AriaNG:

Update your REPLACE_WITH_YOUR_SECRET_KEY value in AriaNG Settings > RPC (localhost:6800) image

Conclusion:

By following this tutorial, you should now be able to start and stop Aria2 as a service using Homebrew on your Mac M1/M2 device. This will allow you to manage Aria2 more efficiently and ensure it runs smoothly on your Apple Silicon Mac.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.aria2</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/aria2c</string>
<string>--enable-rpc=true</string>
<string>--rpc-secret=REPLACE_WITH_YOUR_SECRET_KEY</string>
<string>--rpc-allow-origin-all=true</string>
<string>--rpc-listen-all=true</string>
<string>--rpc-listen-port=6800</string>
</array>
<key>WorkingDirectory</key>
<string>/Users/REPLACE_WITH_YOUR_USER_NAME/Downloads/</string>
<key>StandardErrorPath</key>
<string>/dev/null</string>
<key>StandardOutPath</key>
<string>/dev/null</string>
</dict>
</plist>
@bowencool
Copy link

Help:

$ brew services start aria2
Error: undefined method `plist_startup' for #<Formula aria2 (stable) /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/a/aria2.rb>
Did you mean?  plist_name
/opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/formula_wrapper.rb:71:in `service_startup?'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:280:in `service_load'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:122:in `block in start'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:97:in `each'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:97:in `start'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/commands/start.rb:12:in `run'
/opt/homebrew/Library/Taps/homebrew/homebrew-services/cmd/services.rb:139:in `run'
/opt/homebrew/Library/Homebrew/brew.rb:89:in `<main>'
If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core):
  https://github.com/homebrew/homebrew-services/issues/new

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