Introduction
During my last post about the DS215j from Sinology i introduced the DiskStation and provided a way to bootstrap the NAS. Lately i found myself in the situation that it was not enough to be able to install packages using bootstrap and ipkg. I’d like to have a working pyLoad installation to be able to handle all of my downloading belongings. The provided DownloadStation was not capable of handling so called OneClickHoster especially the captcha request.
Because of this reason i needed an alternative. It was very easy to find some, pyLoad. It was not that easy to get it running on my DS215j. There are precompiled .ipk packages of pyLoad on their homepage but they are not working because of an issue with python.
I will provide the instructions to install pyLoad from ipkg even if it is not runnable. Because if someone has the same problems, he will find this article and sees the better solution.
Install pyLoad
From ipkg sources
This part of the article won’t provide you a running pyLoad instance by now. Maybe there will be a python2.7 fix for the following issues.
Needed packages
First we need a list of packages to be able to run pyLoad. The following command will install them. You have to log-in into your DiskStation using root or a user able to use sudo.
1 |
sudo ipkg install screen nano wget unzip unrar psmisc wget tesseract-ocr tesseract-ocr-lang-eng ossp-js unrar |
Download the pyLoad package
The precompiled package will be downloaded directly from the homepage of pyLoad and installed afterwards.
1 2 |
wget http://get.pyload.org/static/pyload-v0.4.9-noarch.ipk sudo ipkg install pyload-v0.4.9-noarch.ipk |
Running pyLoadCore
During the first start, pyLoad should place its default configuration under ~/.pyLoad, which it does, but nothing more. The -s parameter starts the initial setup process.
1 |
sudo pyLoadCore -s |
The command finished exactly after it was started. This couldn’t be the way it should work. I dug a little bit deeper and ran the following command to be able to see a few debug messages.
1 2 |
cd /volume1/@optware/share/pyload/ sudo python -vv pyLoadCore.py |
This provided me with this truncated output.
1 2 3 4 5 6 |
... # trying /volume1/@optware/share/pyload/module/module.pyc # trying /volume1/@optware/share/pyload/module/utils.so # trying /volume1/@optware/share/pyload/module/utilsmodule.so # trying /volume1/@optware/share/pyload/module/utils.py # /volume1/@optware/share/pyload/module/utils.pyc has bad magic |
That message indicates a problem with some module. Some googling showed me, there is a problem with pyLoad an python2.5, which is default, running the python command. Knowing about this i tried python2.6, getting the same result. Only python2.7 gave me another result. But not the one i was expecting.
1 2 3 4 5 6 7 8 9 10 11 |
> $ sudo python2.7 pyLoadCore.py -s Traceback (most recent call last): File "pyLoadCore.py", line 48, in <module> from module.network.RequestFactory import RequestFactory File "/volume1/@optware/share/pyload/module/network/RequestFactory.py", line 22, in <module> from Browser import Browser File "/volume1/@optware/share/pyload/module/network/Browser.py", line 6, in <module> from HTTPRequest import HTTPRequest File "/volume1/@optware/share/pyload/module/network/HTTPRequest.py", line 20, in <module> import pycurl ImportError: No module named pycurl |
The needed pycurl is currently not available for python2.7 on arm architecture.
Now it was time to give up this way and switch to a more powerful but advanced solution.
Using a Debian chroot environment
What is chroot
Chroot is short for change root and means to change the root directory of a process running on a linux system. The process is encapsulated inside this environment and can’t access files and folders outside of it. With a few device mount-points we are able to run a whole linux system inside of this sandbox and can use all of the benefits of it without changing the host operating system. Chroot is a simple sandboxing and virtualization approach.
Remove pyLoad ipkg installation
Before we are getting started with our chroot installation, we will clean the mess we did earlier.
1 2 |
sudo ipkg remove pyload sudo ipkg remove tesseract-ocr tesseract-ocr-lang-eng ossp-js -force-removal-of-dependent-packages |
Chroot package from SynoCommunity
The guys over at SynoCommunity are providing a fully functional debian wheezy chroot environment. If you have added their repository into your DSM Package Center, simply install the debian-chroot package that can be found under the community tab.
- Community packages overview
- Debian chroot package
This will take a few minutes install because of its size. After the installation is finished, click the action dropdown and select run. The next steps will be performed via ssh on your DiskStation.
Set up your chroot environment
The first things we have to do, is to mount your Volume and to add all of your users. The last step is needed to prevent file-mode issues between the host system and your chroot.
Mount your volume
To enter your new environment, the package provides a simple script that could be called with some params. We will run the following commands to enter the chroot as root user and create a folder to mount your volume.
1 2 3 |
sudo /var/packages/debian-chroot/scripts/start-stop-status chroot mkdir /volume1 exit |
Now we have to edit the script we called seconds ago and add a few lines to handle the mounting of our volume. I will post the whole modified script with adding descriptions in just before the lines i added.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
#!/bin/sh # Package PACKAGE="debian-chroot" DNAME="Debian Chroot" # Others INSTALL_DIR="/usr/local/${PACKAGE}" PATH="${INSTALL_DIR}/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin" CHROOTTARGET=`realpath ${INSTALL_DIR}/var/chroottarget` start_daemon () { # Mount if install is finished if [ -f ${INSTALL_DIR}/var/installed ]; then # Make sure we don't mount twice grep -q "${CHROOTTARGET}/proc " /proc/mounts || mount -t proc proc ${CHROOTTARGET}/proc grep -q "${CHROOTTARGET}/sys " /proc/mounts || mount -t sysfs sys ${CHROOTTARGET}/sys grep -q "${CHROOTTARGET}/dev " /proc/mounts || mount -o bind /dev ${CHROOTTARGET}/dev grep -q "${CHROOTTARGET}/dev/pts " /proc/mounts || mount -o bind /dev/pts ${CHROOTTARGET}/dev/pts ### ADDED mount volume 1 during start grep -q "${CHROOTTARGET}/volume1 " /proc/mounts || mount -o bind /volume1 ${CHROOTTARGET}/volume1 # Start all services ${INSTALL_DIR}/app/start.py fi } stop_daemon () { # Stop running services ${INSTALL_DIR}/app/stop.py # Unmount umount ${CHROOTTARGET}/dev/pts umount ${CHROOTTARGET}/dev umount ${CHROOTTARGET}/sys umount ${CHROOTTARGET}/proc ### ADDED unmount volume 1 during shutdown umount ${CHROOTTARGET}/volume1 } daemon_status () { `grep -q "${CHROOTTARGET}/proc " /proc/mounts` && `grep -q "${CHROOTTARGET}/sys " /proc/mounts` && `grep -q "${CHROOTTARGET}/dev " /proc/mounts` && `grep -q "${CHROOTTARGET}/dev/pts " /proc/mounts` } case $1 in start) if daemon_status; then echo ${DNAME} is already running exit 0 else echo Starting ${DNAME} ... start_daemon exit $? fi ;; stop) if daemon_status; then echo Stopping ${DNAME} ... stop_daemon exit 0 else echo ${DNAME} is not running exit 0 fi ;; status) if daemon_status; then echo ${DNAME} is running exit 0 else echo ${DNAME} is not running exit 1 fi ;; chroot) chroot ${CHROOTTARGET}/ /bin/bash ;; *) exit 1 ;; esac |
Now we can stop and restart the environment to be able to use our mounted volume.
1 2 |
sudo /var/packages/debian-chroot/scripts/start-stop-status stop sudo /var/packages/debian-chroot/scripts/start-stop-status start |
Generate locales and set timezone
By default Debian has no configured locale packages. We have to install them and set them up according to our needs.
1 |
sudo /var/packages/debian-chroot/scripts/start-stop-status chroot |
1 2 3 4 5 6 |
aptitude update aptitude upgrade aptitude install locales dpkg-reconfigure locales dpkg-reconfigure tzdata exit |
Add the users and groups
To be able to write and read onto your data you have to set up a group inside your DSM that has full access to your volume and contains all of the users that should have access from inside your chroot.
Adding a new group is quiet simple. Open your DSM, start the Control Panel, click on groups and create a new one. Mine is called chroot and has access to all of my shared folders.
For the next step we have to leave the DSM because there is no way to get the needed data from there. On your DiskStation shell, type the following commands and note the user id of your user added to the chroot-group and the id of the group itself.
1 2 |
> $ id andre uid=1026(andre) gid=100(users) groups=100(users),101(administrators),65536(chroot),1023(http) |
My user id is 1026 and the group id of chroot is 65536. With this information we can log into our debian environment.
1 |
sudo /var/packages/debian-chroot/scripts/start-stop-status chroot |
Now we are adding the user, in my case it is andre, and the group to the chroot environment. The home folder of the user is my DSM home folder. This is very convenient because now i’m able to share files and configurations that are stored inside of it between the host and the sandboxed system. Another benefit of it is, if you plan to remove the debian-chroot, all files will be kept inside of this folder even after removing the package.
1 2 3 |
adduser andre --uid 1026 --home /volume1/homes/andre/ addgroup --gid 65536 chroot usermod -a -G chroot andre |
If everything went fine you can check the following command and compare the output.
1 2 |
> # groups andre andre : andre chroot |
Install pyLoad in chroot
The installation is simple, paste the following commands and you are ready to go.
1 2 3 |
apt-get install python-crypto python-pycurl python-imaging python-beaker tesseract-ocr tesseract-ocr-eng gocr unrar python-django wget http://get.pyload.org/get/ubuntu-cli/ -O pyload-cli-v0.4.9-all.deb dpkg -i pyload-cli-v0.4.9-all.deb |
You can now run the pyLoad setup process. But for me it was not suitable to run it as root, so i decided to change it to my local user andre. The following steps will show how to do it.
1 2 3 |
su andre cd ~ pyLoadCore -s |
This starts the configuration wizard that will guide you through all necessary parts with ease.
After the config part you can run it directly with removing the -s part from the command. We will start it inside of a screen, to be able to detach the session and keep it up and running.
1 |
screen -d -m pyLoadCore |
Autostart pyLoad on DiskStation boot
Because of your chroot-environment not being able to start and stop services by its own during boot-up or shutdown, we have to provide a little script that works from the inside of your DiskStation and is able to do this task.
Log in via ssh as root on your DiskStation and create a file using the following command.
1 |
vi /usr/syno/etc/rc.d/Z01debian-services.sh |
Paste these code into the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/bin/sh # Package PACKAGE="debian-chroot" DNAME="Debian Chroot" # Others INSTALL_DIR="/usr/local/${PACKAGE}" PATH="${INSTALL_DIR}/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin" CHROOTTARGET=`realpath ${INSTALL_DIR}/var/chroottarget` if [ "$*" = 'start' ] ; then # start chroot with mounts, this should be the first /var/packages/debian-chroot/scripts/start-stop-status start # starting pyload chroot ${CHROOTTARGET}/ su -c 'screen -d -m pyLoadCore' andre else # shutdown pyload chroot ${CHROOTTARGET}/ su -c 'pyLoadCore -q' andre # shutdown chroot env /var/packages/debian-chroot/scripts/start-stop-status stop fi |
The script will be launched every time the NAS will boot or shutdown and runs some commands inside your chroot to start or stop your services.
Thats it, you are now able to use pyLoad and it will start and stop automatically.
Use pyLoad
There are many ways to interact with the pyLoad-daemon. The most common way is to use the web-interface. Simply open http://{ip-of-your-ds}:8080 in your preferred browser and you will see some of the following screens. All of the configuration you did earlier during the set-up process can be changed under the config tab.
- pyLoad main screen
- pyLoad configuration screen
Sources