OSX: синтаксис для загрузки одного агента запуска для текущего пользователя

Я пытаюсь загрузить список LaunchAgent одного пользователя. Все существующие файлы plist в каталоге имеют разрешения пользователя и группы пользователя по умолчанию,

Если я использую эти разрешения для своего файла plist и пытаюсь загрузить, я получаю

$ sudo launchctl load -w -F $HOME/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist
/Users/timothy/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist: Path had bad ownership/permissions

Если я устанавливаю разрешения на root:wheel, работает та же команда.

Я подумал, что загружаю неправильно, поэтому я попробовал это:

sudo launchctl load -D user ~/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist

# Similar result, just lots of `Operation not permitted` instead of `service already loaded`
launchctl load -D user com.ionic.python.ionic-fs-watcher.startup.plist

Но из сотен строк вывода похоже, что он пытается загрузить каждый существующий файл plist.

Документы из инструмента, похоже, указывают на то, что он будет ТОЛЬКО сканировать файлы plist в ~/Libraries (см. Ниже),

Как загрузить LaunchAgent для текущего пользователя?

$ launchctl help load
Usage: launchctl load <service-path, service-path2, ...>
        -w      If the service is disabled, it will be enabled. In previous
                versions of launchd, being disabled meant that a service was
                not loaded. Now, services are always loaded. If a service is
                disabled, launchd does not advertise its service endpoints
                (sockets, Mach ports, etc.).
        -F      Forcibly load the service. This flag will ignore the service's
                disabled state. In previous versions of launchd, this flag
                would also ignore the ownership and permissions of the
                specified launchd.plist. This is no longer the case. Note that,
                unlike the -w flag, this flag will not  modify the service's
                disabled state; it will instead only ignore it for the load
                operation.
        -S <session>
                This flag takes a single argument which is the name of a
                session and may only be used when loading agents. All daemons
                exist within the same session, which is the system session.
                Agents may designate which sessions they can be loaded in with
                the LimitLoadToSessionType key.
        -D <domain>
                Loads launchd.plist(5) files from the specified domain.
                Depending on the current execution context, launchctl will look
                in a LaunchDaemons or LaunchAgents directory for
                launchd.plists. When running in the system's execution context
                (i.e. when run as root via a root shell or with sudo), the
                LaunchDaemons directory is searched. When running in a user's
                context (i.e. run normally from a shell), the LaunchAgents
                directory is searched. Valid domains are:
                system
                Searches /System/Library for either daemons or agents.

                local
                Searches /Library for either daemons or agents.

                network
                Searches /Network. This session type is no longer valid.

                user
                Searches the home directory of the calling user for agents
                only. Daemons may not be loaded from this
                domain.

person turtlemonvh    schedule 15.03.2018    source источник
comment
Во-первых, вам, вероятно, следует использовать современные команды launchctl, если только вы не пытаетесь поддерживать устаревшие версии macOS. В частности, используйте команду bootstrap, а не load. В launchd много охраны. Я рекомендую вам начать с проверки права собственности на исполняемый файл, на который ссылается ваш .plist, и того, что ваш пользователь может получить доступ к этому ресурсу. Также вам нужно убедиться, что все ваши настройки .plist подходят для пользовательского агента, и вы не пытаетесь сделать что-то вроде установки UID на 0.   -  person James Bucanek    schedule 15.03.2018


Ответы (1)


Благодаря поддержке Джеймса и отличный пост в блоге, здесь показано, как работать с однопользовательскими LaunchAgents в OSX (или, по крайней мере, в 10.11).

Команды предполагают наличие файла plist в ~/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist.

# Enable/disable
launchctl enable user/`id -u`/com.ionic.python.ionic-fs-watcher.startup
launchctl disable user/`id -u`/com.ionic.python.ionic-fs-watcher.startup

# Loading / unloading
launchctl bootstrap gui/`id -u` ~/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist
launchctl bootout gui/`id -u`/com.ionic.python.ionic-fs-watcher.startup

# Starting
sudo launchctl kickstart -k -p gui/`id -u`/com.ionic.python.ionic-fs-watcher.startup

# Configure the next invocation of the service for debugging
# See `launchctl help debug` for more info 
sudo launchctl debug gui/`id -u`/com.ionic.python.ionic-fs-watcher.startup --stdout --stderr

# Stopping
# You can send any valid signal: https://linux.die.net/Bash-Beginners-Guide/sect_12_01.html
launchctl kill SIGTERM gui/`id -u`/com.ionic.python.ionic-fs-watcher.startup

# Get info for process
launchctl print gui/`id -u`/com.ionic.python.ionic-fs-watcher.startup
# For domain
launchctl print gui/`id -u`
# Enabled/disabled in domain
launchctl print-disabled gui/`id -u`
person turtlemonvh    schedule 15.03.2018