SystemD is the newer alternative to the init.d system. Instead of service files being in /etc/init.d/, they are in /lib/systemd/system. In /etc/systemd/system/multi-user.target.wants/ there are symlinks to the /lib/systemd/system service files. Anything in the multi-user target gets launched on boot (in the order specified with all of the After and Before markings in each service file. SystemD is smart enough to figure the order out.)

Here is my systemd  files for these services. Note that as time goes on these might needs tweaking. Also they might need tweaking to adjust for your system. Things to adjust would be the user,group and paths and also priorities. You could comment out the user & group labels like I did, if you simply want root to launch them (which in my case I do). Also you could comment out the priority labels if you just want everything to run normal. In my case I wanted these services to have less priority than the rest of the system. The downloading services like uTorrent & Transmission & NZBget, get a slightly better priority, but still lower than the system.

NOTE: when I use the word priority below, I mean literally a higher priority (more CPU usage). linux flips the concept sometimes and higher Priority number usually mean less CPU usage. You can tell my “priority” apart from linux “Priority” because they capitalize it and I dont.

NOTE ON NICE – this sets how used the CPU is: Nice works just like “Nice” and it works on CPU priorities. -20 is highest priority, and +19 is lowest cpu priority. I gave a 10 to downloaders and 15 to the other ones. By default system puts everything at a 0.

NOTE ON IO PRIORITYS – this sets how used the data drives are: IOSchedulingClass (like -c from ionice) and IOSchedulingPriority (like -n from ionice) are just like “ionice”. IOSchedulingClass is the -c option with ionice, and IOSchedulingPriority is the -n option. IOSchedulingClass=1, ionice  -c1, is the best priority (realtime priority). IOSchedulingClass=3, ionice -c3 program1, is the worse priority (waits for the device to be unused). IOSchedulingClass=2, ionice -c2 -n# program1, is the middle priority and it has 8 settings for setting the IOSchedulingPriority from 0 to 8 (which you substitute inplace of the #). IOSchedulingClass=2 & IOSchedulingPriority=0, ionice -c2 -n0 program1, has the highest priorty in this middle class. IOSchedulingClass=2 & IOSchedulingPriority=0, ionice -c2 -n0 program1, has the lowest priorty in this middle class . With -c1 and -c3 you dont need to set a -n option, in otherwords with  IOSchedulingClass=1 or 3 you dont need to set IOSchedulingPriority. However with IOSchedulingClass=2 you do need to set the IOSchedulingPriority either between 0 or 7 (inclusive) – note maybe you dont need to explicitly set IOSchedulingPriority  with class 2 and the system might pick something like -n0 by default. NOTE: program1 is just an example of a program, so that you can see ionice usage.

MORE on NICE and IONICE here: http://ram.kossboss.com/ionice/

The SYSTEMD Files

NOTE: im not the systemd expert however I have read up about it and have adjusted my service files for the best.

NOTE: if your not using a ReadyNAS 6.x you can change After=apache2.service readynasd.service to After=network.target. These After labels / clauses are read during boot up, and it launches all of the “multi-user-wants” service files in order thanks to these After and Before clauses (we dont use any Befores, but other service files do). We want these services to be started after the network comes up, so by default we would want them to say After=network.target. However since im using a ReadyNAS 6.x i want them to come up after the volume comes up (as the volumes holds the /apps subvolume). The volume comes up after readynasd.service. I know for a fact too that once apache2 and readynasd come up everything in the system is up and running including the network and the volumes, so as a safety precaution I just have these services start up after apache & readynasd. This alike to saying I want these services to start up last in the boot order. the network.target service file is pretty minimal it only exists as a systemd service to tell other service if the network is up (for use with After/Before etc.)

NOTE: I use the After label to make sure these services start after the network starts. I saw DaemonAfter in some example Service files. I couldnt find any documentation about it. Eitherway I know that After works just as well, so thats what we I will use.

NOTE: We use Type=forking because these are daemons, meaning they fork off and the first/parent PID is not the daemons pid. So Type has to be set to forking. There is a way you can do these with Type=simple you would have to use bash with the ExecStart i.e. http://forum.utorrent.com/topic/92258-installing-utorrent-for-debian-7-systemd-integration/. I like my method better. Also my method returns pretty output with systemctl status. Since these are Daemons its best to find out its PID by using PIDFile (a pid file is a text file that has the PID of the daemon, it is created when you start a daemon, usually into the /var/run folder, however you can change that up with apps, for example my utservers pid file goes right into /apps/ut/pid)

NOTE: the transmission service file is not actually called transmission.service on my system, its called fvapp-transmissionr6.service because its one of the installable addon/apps that come with the ReadyNAS6.x. I assume not all people that come across this page will be using a ReadyNAS so I changed the name to something more applicable to everyone.

NOTE: comments are done with # just like with bash scripts.

NOTE: User & Group are a good idea to use, but I didnt so I just comment them out.


 

uTorrent Server
file: /lib/systemd/system/utserver.service

SickRage SickBeard
file: /lib/systemd/system/sickrage.service

Couch Potato
file: /lib/systemd/system/cpot.service

Transmission
file: /lib/systemd/system/transmission.service

NZBget
file: /lib/systemd/system/nzbget.service


 

Here are examples of how you would use these with a systemctl command, however first make sure you have created the files and that they have the .service extension. My examples will use CouchPotato as an example which I made /lib/systemd/system/cpot.service. Note that I can refer to it as cpot or cpot.service with systemctl. So ill use cpot to type less.

To enable a service on boot (so it doesnt launch on boot – you will notice this simply creates a symlink): systemctl enable cpot

To disable a service on boot (you will notice this simply removes that symlink): systemctl disable cpot

To start the program/service now: systemctl start cpot

To stop the program/service now: systemctl stop cpot

To see if its running (along with other info, like if its enabled for boot, and its process info and some logs): systemctl status cpot

NOTE: if you have edited any of the service files that you have used already then you will need to run this for systemd to read the services files and cache them:  systemctl –system daemon-reload

The End

2 thoughts on “SystemD files for uTorrent Server, SickRage SickBeard, Couch Potato, Transmission, NZBget

  1. Hey! is it possible to strip out the utorrent content of your script only for a debian 8 box with utorrent server?

    iv’e been trying for days (im a noob) to get utorrent-server to start up at boot but with no luck, it seems like every guide i read is about the init.d autostart way, and that’s not working now i think?

    Also, cant seem to find any systemd scripts that i actually understand or is explained so a noob as myself can modify them :/

    If you could help me out i would gladly paypal you a 5-er or something 🙂

    1. Prior to Debian 8, Debian used sysvinit scripts to start processes (to manage process on boot and also during run mode). sysvinit is the one where you have to control booting of processes from /etc/init.d and /etc/rc#.d/ folders. Basically they were scripts that started things on boot. With Debian 8, systemd was adopted (and sysvinit was put to rest, even though you can see its remains in /etc/init.d and /etc/rc#.d folders), with systemd you can tell programs to boot with these dot service files that get put into /lib/systemd/system. The dot service files are not scripts, instead they are just like config/settings file, this dot service file tells the system what to do when the process is started or turned off, and it can also be instructed on how to start it (such as I put in a bunch of NICE and IONICE propreties so that the process launches with lowest priority on my CPU and lowest priority on my drives — I want simple file browsing/streaming to have the most priority).

      Are you able to start UT server manually without systemd? What command do you use to start it? Try to start it using this command:

      /apps/ut/utserver -daemon -configfile /apps/ut/config.txt -settingspath /apps/ut -logfile /apps/ut/log.txt -pidfile /apps/ut/pid

      Just replace /apps/ut/utserver with the full path of your utserver command. Also make sure that the folders exist for the files that I mention, so in my case I make sure /apps/ut exists.
      Did that work?

      Can you show me the output of this:
      cd /your/ut/server/path
      pwd
      find -ls

      After you get the command down, all we need to do is just to do is just make a single file with this name /lib/systemd/system/utserver.service, and its contents should be this:


      [Unit]
      Description=uTorrent Server
      After=network.target
      # DaemonAfter=readynasd.service
      # If your using ReadyNAS comment out above "After=network.target" and uncomment below.
      # After=apache2.service readynasd.service

      [Service]
      # User=utserver
      # Group=utserver
      ExecStart=/apps/ut/utserver -daemon -configfile /apps/ut/config.txt -settingspath /apps/ut -logfile /apps/ut/log.txt -pidfile /apps/ut/pid
      Type=forking
      PIDFile=/apps/ut/pid
      # -- added below to be less priority -- #
      Nice=10
      IOSchedulingClass=2
      IOSchedulingPriority=2

      [Install]
      WantedBy=multi-user.target

      You just need to modify the ExecStart command to however you start utserver (make sure to use full paths for everything). Also you can uncomment (remove the #) from User and Group if you want & set whatever user and group you have configured for utserver (leave it commented if you just want root to run it). Also you can comment out (add the # on the left) the Nice, and the IOSchedulingClass and the IOSchedulingPriority lines if you want utserver to have default priority on your processor, or just leave them as is if you want utserver to have lower priority (not a big deal it still downloads super quick).

      Test it like this
      systemctl start utserver
      systemctl status utserver
      systemctl stop utserver

      It should complain if it doesnt work.
      Once you get it to work and it starts with systemctl start, you can enable it on boot like so
      systemctl enable utserver

      To disable it from booting
      systemctl disable utserver

Leave a Reply

Your email address will not be published. Required fields are marked *