Setup AFD


Currently there are two different init systems. The SystemV initd system and systemd. There is support for both, but you need to decide this when you compile AFD. If you want to use systemd you must compile AFD with the configure option --enable-systemd.

Setup with SystemV initd


In /etc/sysconfig/afd you can setup under which users AFD is to be started when system boots. If the user name is donald you need to set this as follows:

    AFD_USER_0=donald

The AFD_USER_0 is handled via the script /etc/init.d/afd. More users can be added by incrementing the number:

    AFD_USER_1=daisy

The AFD_HA_USER_0 variable can be used to start AFD users in a high availability environment via the /etc/init.d/afdha script.

If you need to start more then one AFD under one user, it can be done by using the environment variable MULTI_AFD_DIRS. If the user donald wants to run three AFD's he needs three different AFD home directories, it can be done by setting this variable in his .profile file:

   MULTI_AFD_DIRS="/home/donald/tick /home/donald/trick /home/donald/track"

Setup with systemd


Setting up AFD users under systemd can be done via creating an environment file /etc/afd/<user>_environment.conf for each user. In it you need to set the working directory of AFD. For the user donald you would have to create the file /etc/afd/donald_environment.conf with the following content:

   AFD_WORK_DIR=/home/donald

To start/stop donalds AFD the system administrator needs to run the following command:

   systemctl start afd@donald.service
   systemctl stop afd@donald.service

If donalds AFD is to be started automatically at boot, the system administrator needs to run the following command:

   systemctl enable afd@donald.service

And if it is no longer needed it can be removed by the system administrator with the command:

   systemctl disable afd@donald.service

Under systemd the AFD will not inherit the environment variables of the user. These need to be set in /etc/afd/<user>_environment.conf. Alternatively the user can set these variables via $AFD_WORK_DIR/etc/environment.conf file himself.

If possible try and put the environment variables in /etc/afd/<user>_environment.conf. To only set the values in one file only, put in the users profile the following:

        if [ -f /etc/afd/${USER}_environment.conf ]
        then
           source /etc/afd/${USER}_environment.conf
           export $(cut -d= -f1 /etc/afd/${USER}_environment.conf)
        fi

If one needs to start more the one AFD under one user it can be done by copying /usr/lib/systemd/system/afd@.service to etc/systemd/system/afd.target.wants with a specific name. If the user donald wants to run three AFD's in his directories ~/tick, ~/trick and ~/track, it can be done as follows by the system administrator:

   cd /usr/lib/systemd/system
   cp afd@.service afd@donald_tick.service
   cp afd@.service afd@donald_trick.service
   cp afd@.service afd@donald_track.service

These three files must then be modified by the system administrator by changing the line

   User=%i

as follows:

   User=donald

Next the three environment files donald_tick_environment.conf, donald_trick_environment.conf and donald_track_environment.conf need to be created in /etc/afd with the following contend:

   cat /etc/afd/donald_tick_environment.conf
   AFD_WORK_DIR=/home/donald/tick

   cat /etc/afd/donald_trick_environment.conf
   AFD_WORK_DIR=/home/donald/trick

   cat /etc/afd/donald_track_environment.conf
   AFD_WORK_DIR=/home/donald/track

Then issue the command 'systemctl daemon-reload', so systemd sees those modifications.


Copyright © 2020 by H.Kiehl
Holger.Kiehl@dwd.de
Last updated: 19.08.2020
[red dot]Index [red dot]Home