Launchd 脚本自动挂载 AFP 共享

发布于 2024-11-27 19:49:07 字数 243 浏览 3 评论 0原文

我越来越多地使用 launchd 来自动化我的家庭服务器上的所有内容,并且我想在我的客户端计算机上利用它的一些功能。我基本上想弄清楚如何始终保持服务器的 AFP 共享挂载。我发现自己遇到的唯一真正问题是,当我位于法新社被阻止的网络上时,脚本会自行撞墙。我想尝试尝试 3 次然后放弃,但是当我离开网络时我必须重新启动脚本。我不太确定如何在 plist 中编写 if 构造以确保它可以连接,或检查卷是否已安装。到目前为止,我编写的唯一脚本是让 OS X 应用程序保持活动状态。

I've been getting more and more into using launchd to automate everything on my home server, and I'd like to harness some of it's power on my client machines. I basically want to figure out how to keep my server's AFP share mounted at all times. The only real issue I see myself running into is the script banging itself into a wall when I'm on a network that has AFP blocked. I'd think do something like try 3 times then give up, but then I'd have to restart the script when I left the network. I'm not quite sure how to write an if construct within the plist to make sure it can connect, or to check to see if the volume is already mounted. The only scripts I've written so far are to keep OS X applications alive.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-12-04 19:49:07

看看 LocationChanter。它使用的 plist 项是:

<key>WatchPaths</key>
<array>
    <string>/Library/Preferences/SystemConfiguration</string>
</array>

据我所知,每次网络更改时该目录中的文件都会更新。这会给你第一个触发点。另一个要查看的 plist 项目是“PathState”。 launchd.plist 手册页 有以下文档:

PathState <dictionary of booleans>
Each key in this dictionary is a file-system path. If the value of
the key is true, then the job will be kept alive as long as the
path exists.  If false, the job will be kept alive in the inverse
condition. The intent of this feature is that two or more jobs may
create semaphores in the file-system namespace.

我自己刚刚开始了解 launchd,但我认为您可以将其与 WatchPaths 结合使用来设置您要查找的内容。这个想法是监视已安装的驱动器,如果不存在则尝试安装它。

当然,您可能需要对此进行一些限制。特别是如果客户端计算机将连接到其他网络,但我认为这些元素应该可以帮助您入门。

Take a look at LocationChanter. The plist item it uses is:

<key>WatchPaths</key>
<array>
    <string>/Library/Preferences/SystemConfiguration</string>
</array>

From what I can tell, the files in that directory are updated each time your network changes. So that would give you your first trigger. The other plist item to look at is "PathState". The launchd.plist man page has the following documentation for it:

PathState <dictionary of booleans>
Each key in this dictionary is a file-system path. If the value of
the key is true, then the job will be kept alive as long as the
path exists.  If false, the job will be kept alive in the inverse
condition. The intent of this feature is that two or more jobs may
create semaphores in the file-system namespace.

I'm just getting into launchd myself, but I think you can use that in combination with the WatchPaths to setup what you're looking for. The idea being to watch for the mounted drive and if it's not there attempt to mount it.

Of course, you probably want some throttle on this. Especially if the client machine will ever connect to other networks, but I think those elements should get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文