OSX:用于为当前用户加载单个启动代理的语法 [英] OSX: Syntax for loading a single launchagent for current user

查看:106
本文介绍了OSX:用于为当前用户加载单个启动代理的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载单个用户的LaunchAgent plist.目录中所有现有的plist文件都具有用户和用户默认组的权限,

I am trying to load a single user's LaunchAgent plist. All existing plist files in the directory have the permissions of the user and the user's default group,

如果我将这些权限用于我的plist文件并尝试加载,我会得到

If I use those permissions for my plist file and try to load, I get

$ 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,则相同的命令有效.

If I set the permissions to root:wheel the same command works.

我认为我打算以错误的方式加载,所以我尝试了以下方法:

I figured I was going about loading the wrong way, so I tried this:

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

但是从100行的输出看来,这似乎是在尝试加载每个存在的plist文件.

But from the 100s of lines of output it looks like that is trying to load every plist file that exists.

该工具中的文档似乎表明,这只会扫描~/Libraries中的plist文件(请参见下文)

The docs from the tool seem to indicate that this would ONLY scan for plist files in ~/Libraries (see below),

如何为当前用户加载LaunchAgent?

How do I load a LaunchAgent for the current user?

$ 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.

推荐答案

感谢 James 这篇出色的博文,这里是如何在OSX上(或至少在10.11上)与单用户LaunchAgents一起使用.

Thanks to the prodding from James and this excellent blog post, here is how to work with single user LaunchAgents on OSX (or at least on 10.11).

命令假定~/Library/LaunchAgents/com.ionic.python.ionic-fs-watcher.startup.plist中有一个plist文件.

The commands assume a plist file in ~/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`

这篇关于OSX:用于为当前用户加载单个启动代理的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆