osx startupitems Shell脚本无法启动应用程序 [英] osx startupitems shell script does not launch application

查看:209
本文介绍了osx startupitems Shell脚本无法启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OSX 10.10.4上的shell脚本启动与相关项目的匿名服务器应用程序.

I'm trying to launch a faceless server application with it's associated project using shell script on OSX 10.10.4.

shell脚本已设置为可执行文件.

The shell script has been set to executable.

在启动时,启动Wakanda \ Server.app/Contents/MacOS/Wakanda \ Server不会发生任何事情.

On Startup nothing happens to launch Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server.

请帮助我完成这项工作.

Please help me make this work.

shell脚本位于:

The shell script is at:

Macintosh HD:Library:StartupItems:DispatchStartup:DispatchStartup.sh

此shell脚本的内容为:

The contents of this shell script is:

#!/bin/sh
. /etc/rc.common

# The start subroutine
StartService() {
    # Insert your start command below.  For example:
    /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server --solution=/Applications/Dispatch/Dispatch\ Solution/Dispatch.waSolution
    # End example.
}

# The stop subroutine
StopService() {
    # Insert your stop command(s) below.  For example:
    killall -TERM /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server
    sleep 15
    killall -9 /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server
    # End example.
}

# The restart subroutine
RestartService() {
    # Insert your start command below.  For example:
    killall -HUP /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server
    # End example.
}

RunService "$1"

//--------------------------------------------- ----------------------

//-------------------------------------------------------------------

//是StartParameters.plist //------------------------------------------------ --------------------

// next to the shell script is StartParameters.plist //--------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
    <dict>
        <key>Description</key>
        <string>Wakanda Server</string>
        <key>OrderPreference</key>

        <string>Late</string>
        <key>Provides</key>
        <array>
                <string>Web service to database and objects</string>
        </array>
        <key>Uses</key>
        <array>
                <string>Network</string>
        </array>
    </dict>
</plist>

推荐答案

不推荐使用启动项,而推荐使用

Startup items have been deprecated in favor of launch daemons since OS X v10.4, and they seem to have finally been disabled entirely in v10.10. The better option is... create a launch daemon instead. It'll be a property list (.plist) file in /Library/LaunchDaemons/ containing instructions about what to launch and when to launch it.

这会比平常复杂一些,因为已启动的系统喜欢跟踪已启动的作业,这要求它们掉入后台,而且我看不到任何可以防止Wakanda服务器自身后台运行的功能.您可以通过在.plist中添加说明以使其不处于活动状态并放弃"其进程组(即,不杀死其产生的任何剩余后台进程)来解决此问题. 可能也存在一个问题,因为没有好的方法告诉它等到网络启动.但是,如果它尝试侦听特定的IP地址或接口,这通常是一个问题.如果它仅侦听0.0.0.0(即计算机上的所有IP),则这不是问题,因为它将在出现接口时选择接口.

This'll be a little more complicated than usual because the launchd system likes to keep track of the jobs it's launched, which requires that they not drop into the background, and I don't see any to prevent Wakanda server from backgrounding itself. You can work around this by adding instructions to the .plist to not keep it alive, and to "abandon" its process group (i.e. not kill off any leftover background processes it spawns). There might also be a problem in that there's no good way to tell it to wait until the network's up. But this is mostly a problem if it tries to listen on specific IP addresses or interfaces; if it just listens on 0.0.0.0 (i.e. all IPs on the computer), this isn't a problem because it'll just pick up interfaces as they come up.

我认为.plist看起来像这样:

I think the .plist will look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Disabled</key>
        <false/>
        <key>Label</key>
        <string>local.wakanda-server</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Applications/Wakanda Server.app/Contents/MacOS/Wakanda Server</string>
                <string>--solution=/Applications/Dispatch/Dispatch Solution/Dispatch.waSolution</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <false/>
        <key>AbandonProcessGroup</key>
        <false/>
</dict>
</plist>

将其放入/Library/LaunchDaemons/local.wakanda-server.plist中,将所有权设置为root:wheel,将权限设置为644,然后重新启动或使用sudo launchctl load /Library/LaunchDaemons/local.wakanda-server.plist手动加载.

put it in /Library/LaunchDaemons/local.wakanda-server.plist, set ownership to root:wheel, permissions to 644, and then either reboot or load it manually with sudo launchctl load /Library/LaunchDaemons/local.wakanda-server.plist.

这篇关于osx startupitems Shell脚本无法启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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