Skip to content

Management ru RU

ArchiBot edited this page May 26, 2022 · 20 revisions

Management

This section covers subjects related to managing the ASF process in optimal way. While not strictly mandatory for usage, it includes bunch of tips, tricks and good practices that we'd like to share, especially for system administrators, people packaging the ASF for usage in third-party repositories, as well as advanced users and alike.


systemd служба для Linux

In generic and linux variants, ASF comes with ArchiSteamFarm@.service file, which is a configuration file of the service for systemd. If you'd like to run ASF as a service, for example in order to launch it automatically after startup of your machine, then a proper systemd service is arguably the best way to do it, therefore we highly recommend it instead of managing it on your own through nohup, screen or alike.

Firstly, create the account for the user you want to run ASF under, assuming it doesn't exist yet. We'll use asf user for this example, if you decided to use a different one, you'll need to substitute asf user in all of our examples below with your selected one. Our service does not allow you to run ASF as root, since it's considered a bad practice.

su # or sudo -i
useradd -m asf

Next, unpack ASF to /home/asf/ArchiSteamFarm folder. The folder structure is important for our service unit, it should be ArchiSteamFarm folder in your $HOME, so /home/<user>. If you did everything correctly, there will be /home/asf/ArchiSteamFarm/ArchiSteamFarm@.service file existing. If you're using linux variant and didn't unpack the file on Linux, but for example used file transfer from Windows, then you'll also need to chmod +x /home/asf/ArchiSteamFarm/ArchiSteamFarm.

We'll do all below actions as root, so get to its shell with su or sudo -i.

Firstly it's a good idea to ensure that our folder still belongs to our asf user, chown -hR asf:asf /home/asf/ArchiSteamFarm executed once will do it. The permissions could be wrong e.g. if you've downloaded and/or unpacked the zip file as root.

Next, cd /etc/systemd/system and execute ln -s /home/asf/ArchiSteamFarm/ArchiSteamFarm\@.service ., this will create a symbolic link to our service declaration and register it in systemd. Symbolic link will allow ASF to update your systemd unit automatically as part of ASF update - depending on your situation, you may want to use that approach, or simply cp the file and manage it yourself however you'd like.

Afterwards, ensure that systemd recognizes our service:

systemctl status ArchiSteamFarm@asf

○ ArchiSteamFarm@asf.service - ArchiSteamFarm Service (on asf)
     Loaded: loaded (/etc/systemd/system/ArchiSteamFarm@.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: https://github.com/JustArchiNET/ArchiSteamFarm/wiki

Pay special attention to the user we declare after @, it's asf in our case. Our systemd service unit expects from you to declare the user, as it influences the exact place of the binary /home/<user>/ArchiSteamFarm, as well as the actual user systemd will spawn the process as.

If systemd returned output similar to above, everything is in order, and we're almost done. Now all that is left is actually starting our service as our chosen user: systemctl start ArchiSteamFarm@asf. Wait a second or two, and you can check the status again:

systemctl status ArchiSteamFarm@asf

● ArchiSteamFarm@asf.service - ArchiSteamFarm Service (on asf)
     Loaded: loaded (/etc/systemd/system/ArchiSteamFarm@.service; disabled; vendor preset: enabled)
     Active: active (running) since (...)
       Docs: https://github.com/JustArchiNET/ArchiSteamFarm/wiki
   Main PID: (...)
(...)

If systemd states active (running), it means everything went well, and you can verify that ASF process should be up and running, for example with journalctl -r, as ASF by default also writes to its console output, which is recorded by systemd. If you're satisfied with the setup you have right now, you can tell systemd to automatically start your service during boot, by executing systemctl enable ArchiSteamFarm@asf command. That's all.

If by any chance you'd like to stop the process, simply execute systemctl stop ArchiSteamFarm@asf. Likewise, if you want to disable ASF from being started automatically on boot, systemctl disable ArchiSteamFarm@asf will do that for you, it's very simple.

Please note that, as there is no standard input enabled for our systemd service, you won't be able to input your details through the console in usual way. Running through systemd is equivalent to specifying Headless: true setting and comes with all its implications. Fortunately for you, it's very easy to manage your ASF through ASF-ui, which we recommend in case you need to supply additional details during login or otherwise manage your ASF process further.

Переменные среды

It's possible to supply additional environment variables to our systemd service, which you'll be interested in doing in case you want to for example use a custom --cryptkey command-line argument, therefore specifying ASF_CRYPTKEY environment variable.

In order to provide custom environment variables, create /etc/asf folder (in case it doesn't exist), mkdir -p /etc/asf. We recommend to chmod 700 /etc/asf to ensure that only root user has access to read those files, because they might contain sensitive properties such as ASF_CRYPTKEY. Afterwards, write to a /etc/asf/<user> file, where <user> is the user you're running the service under (asf in our example above, so /etc/asf/asf).

The file should contain all environment variables that you'd like to provide to the process:

# Объявите только то что вам нужно
ASF_CRYPTKEY="my_super_important_secret_cryptkey"
ASF_NETWORK_GROUP="my_network_group"

# И любые другие интересующие вас

Никогда не запускайте ASF от имени администратора!

ASF includes its own validation whether the process is being run as administrator (root) or not. Running as root is not required for any kind of operation done by the ASF process, assuming properly configured environment it's operating in, and therefore should be regarded as a bad practice. This means that on Windows, ASF should never be executed with "run as administrator" setting, and on Unix ASF should have a dedicated user account for itself, or re-use your own in case of a desktop system.

For further elaboration on why we discourage running ASF as root, refer to superuser and other resources. If you're still not convinced, ask yourself what would happen to your machine if ASF process executed rm -rf /* command right after its launch.

Я запустил ASF через root потому что он не может записывать файлы

This means that you have wrongly configured permissions of the files ASF is trying to access. You should login as root account (either with su or sudo -i) and then correct the permissions by issuing chown -hR asf:asf /path/to/ASF command, substituting asf:asf with the user that you'll run ASF under, and /path/to/ASF accordingly. If by any chance you're using custom --path telling ASF user to use the different directory, you should execute the same command again for that path as well.

After doing that, you should no longer get any kind of issue related to ASF not being able to write over its own files, as you've just changed the owner of everything ASF is interested in to the user the ASF process will actually run under.

I run as root because I don't know how to do it otherwise

su # or sudo -i
useradd -m asf
chown -hR asf:asf /path/to/ASF
su asf -c /path/to/ASF/ArchiSteamFarm # or sudo -u asf /path/to/ASF/ArchiSteamFarm

That would be doing it manually, it's much easier to use our systemd service explained above.

I know better and I still want to run as root

As of V5.2.0.10, ASF no longer stops you from doing so, only displays a warning with a short notice. Just don't be shocked if one day due to a bug in the program it'll blow up your whole OS with complete data loss - you've been warned.


Запуск нескольких экземпляров

ASF поддерживает запуск нескольких экземпляров программы на одной и той же машине. Эти экземпляры могут быть полностью независимы или запущены из одного и того же исполняемого файла (в этом случае вам надо запускать их с разным аргументом командной строки --path).

При использовании нескольких одновременно работающих копий одного исполняемого файла имейте в виду, что в этом случае обычно стоит отключать авто-обновления во всех конфигурационных файлах, поскольку обновление не будет синхронизировано между копиями. Если вы хотите оставить авто-обновление включенным, мы рекомендуем отдельные копии файлов, но вы можете всё равно добиться работы обновлений, если сможете обеспечить чтобы все остальные экземпляры ASF были закрыты.

ASF будет по возможности использовать минимум обще-системных, меж-процессных взаимодействий с другими экземплярами ASF. Сюда входит проверка рабочей директории с конфигурационными файлами в сравнении с другими экземплярами, а также общие ограничители уровня процесса ядра заданные параметрами *LimiterDelay глобальной конфигурации, что обеспечит что несколько одновременно запущенных экземпляров ASF не приведут к ситуации срабатывания ограничения на частоту запросов. Что касается технической реализации — все платформы используют наш специальный механизм блокировок ASF, основанный на блокировках файлов во временной директории, в качестве которой используется C:\Users\<ВашеИмяПользователя>\AppData\Local\Temp\ASF под Windows, и /tmp/ASF под Unix.

Использование одинаковых параметров *LimiterDelay для всех запущенных экземпляров не является обязательным, они могут использовать различные значение, поскольку каждый экземпляр ASF будет добавлять собственную, заданную в конфигурационном файле, задержку до освобождения файла после его захвата. Если параметр *LimiterDelay задан равным 0, этот экземпляр ASF будет полностью игнорировать ожидание блокировки заданных ресурсов, разделяемых с другими экземплярами (которые могут потенциально поддерживать общую блокировку между собой). При установке любых других значений, ASF будет правильно синхронизироваться с любыми другими экземплярами ASF и будет ждать своей очереди, а затем снимать блокировку после заданной задержки, позволяя другим экземплярам продолжить работу.

ASF учитывает настройки WebProxy для принятия решения об использовании блокировок, то есть два экземпляра ASF, использующих разную настройку WebProxy не будут иметь общей блокировки между собой. Это сделано чтоб позволить конфигурациям с использованием WebProxy работать без излишних задержек, как ожидается от разных сетевых интерфейсов. Этого должно быть достаточно для большинства вариантов использования, однако, если ваша конфигурация специфична, например вы перенаправляете запросы самостоятельно каким-то другим образом, вы можете задать сетевую группу сами с помощью аргумента командной строки --network-group, позволяющего вам указывать группу ASF которая будет синхронизироваться с данным экземпляром. Имейте в виду, что пользовательские сетевые группы переопределяют внутреннюю группировку, а значит ASF больше не будет учитывать значение WebProxy для определения правильной группы, так как в этом случае вы полностью отвечаете за группировку.

If you'd like to utilize our systemd service explained above for multiple ASF instances, it's very simple, just use another user for our ArchiSteamFarm@ service declaration and follow with the rest of the steps. This will be equivalent of running multiple ASF instances with distinct binaries, so they can also auto-update and operate independently of each other.

Clone this wiki locally