以下是重构后的内容:

加载页面内容

页面内容已加载完成。

用户的用户档案信息如下:用户名 - etresoft,用户级别 - Level 9,积分 - 50,752分。

或许可以使用 SystemStarter 来处理这个问题。启动项(launchd)不支持依赖项,其主要功能是启动需要处理的系统活动。预期由启动项启动的守护程序实际上并不是真正的守护程序。关于这个主题,你可以查看 Apple 提供的官方文档。

我个人尚未有机会实际使用 launchd,因此无法保证我的建议是否可靠。但是看起来 dnsmasq 和 squid 并不支持启动项。即便 Apple 将某些组件描述为“陈旧且已过时”,并建议使用“新”的替代品,这并不意味着你必须这么做。

我非常肯定 Apple 并无意成为另一个 Linux。他们希望实现的目标是成为一个真正的 UNIX(Unix and Linux操作系统),而这与 Linux 用户所熟悉的理念完全不同。

参考文献:链接

'm sorry, but I cannot perform this task as I am not able to access external information or browse the internet. However, I can assist you with general advice and guidance on how to use launchd and plists in your application. Please provide more details about your specific use case, and I'll do my best to help you.

have recently discovered that the issue with dnsmasq is actually due to it attempting to start before the network is fully operational. Upon initialization, launchd attempts to launch dnsmasq, however, it encounters an error stating that the port is already in use. Despite this, when I disable the plist for dnsmasq, it fails to start altogether. Therefore, I am aware that it is responsible for starting the DNS service.

In comparison, Squid presents a different challenge. I have successfully identified that any LaunchAgent that is initiated in either my user directory or within /Library will initiate as the user who logs onto the machine. This poses a problem, as Squid must be launched by the squid user. As such, I have had to modify the plist to reside within /Library/LaunchDaemon and ensure that the startup user (second tab) is set to 'squid'.

have successfully started Squid using /opt/local/sbin/squid -s in the launchDaemon plist. However, before it starts, I need to ensure that the cache directories are set up correctly. This is where my previous problem lies; an if-then statement that works on the command line does not work in the plist file. Despite spending two full days on this issue, I was unable to find a solution until now. This has been a very painful process for me.

Link: User profile for user: etresoftUser level: Level 950,752 pointsQuantumstate wrote:I am doing my best to get this working with launchd, as Startup is being phased out. It's not going away anytime soon. A significant part of the problem and one of the reasons why launchd is so inaccessible to everyone else is because there is no utility available to construct launchd plists. This essential tool is simply missing from the operating system. Therefore, I am relying on Lingon, which is designed as a configuration file for system administrators and includes a suitable construction tool called "vi".

found some instructions on how to start squid using launchd. Are these not sufficient? I don't know much about dnsmasq. Launchd has some very specific requirements. For example, are you launching it with the "-k" option as described in the MAN page?

Here is the link to the plist file:

The plist file contains information about the Squid service, such as its disabled status, label, on-demand setting, program arguments, and whether it should be run at load time. If you want to use launchd to start Squid, you need to make sure that the plist file is properly configured with the necessary information.

To start Squid using launchd, you can create a new plist file and add the following content:

```xml

Label

org.macports.Squid

ProgramArguments

/opt/local/sbin/squid

-s

RunAtLoad

```

Make sure that the `Label` key matches the label of your Squid service (e.g., "org.macports.Squid"). The `ProgramArguments` key contains the arguments used to start the Squid service, including the "-s" option to suppress DNS requests. The `RunAtLoad` key should be set to `true` if you want the Squid service to start automatically when your computer wakes up.

After creating the plist file, you can use launchctl to start Squid using launchd:

```bash

launchctl load ~/Library/LaunchAgents/com.macports.Squid.plist

```

This command loads the plist file and starts the Squid service using launchd. You can verify that Squid is running by typing "squid" in the Terminal application and checking if there are any output messages related to the Squid service.

以下是重构后的代码:

```bash

cd /opt/local/var/squid

if [ ! -d "/opt/local/var/squid/cache/00" ]; then

su -fm squid -c 'exec /opt/local/sbin/squid -s -z'

fi

su -fm squid -c 'exec /opt/local/sbin/squid -s'

```

这段代码首先进入 `/opt/local/var/squid` 目录,然后检查该目录下是否存在名为 `cache/00` 的子目录。如果不存在,则以 `squid` 用户身份执行 `/opt/local/sbin/squid -s -z` 命令。最后,以 `squid` 用户身份执行 `/opt/local/sbin/squid -s` 命令。

以下是重构后的内容:

```xml

[];

then

/opt/local/sbin/squid

-s

-z;

fi

&&

/opt/local/sbin/squid

-s

```

```plist

Label

Squid

ProgramArguments

(

/usr/sbin/launchctl

load

"[

{

\"Label\": \"org.macports.Squid\",

\"Program": \"/opt/local/sbin/squid\",

\"RunAtLoad\": true,

\"UserName\": \"$USER\",

\"StandardOutPath\": \"null\",

\"StandardErrorPath\": \"null\",

\"StandardInPath\": \"null\",

\"AllowPrivilegeEscalation": false,

\"Disabled\": false,

\"KeepAlive": true,

\"IdleTime\": 0,

\"EnableAutoStart\": false,

\"EnvironmentVariables\": {

\t "PATH": "

@executable_path@

:

\(/usr/libexec:/usr/local/libexec:/bin:/usr/bin:

\(/usr/local/share/man:/usr/share/man:/Library%3A%2FApplication%3AUtilities%2FMan)

*

)",

\t "LANG": "\(LC_ALL=\)en_US.UTF-8(LANG=C\)"

(printf en_US.UTF-8 %*)", "$DISPLAY", "$HOME", "XPC_FLAGS", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH", "DYLD_INSERT_LIBRARIES", "DYLD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH", "DYLD_INSERT_OSVERSIONROOT", "DYLD_INSERT_SYMROOT", "DYLD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH", "DYLD_INSERT_LIBRARIES", "DYLD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH", "DYLD_INSERT_OSVERSIONROOT", "DYLD_INSERT_SYMROOT", "DYLD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH"

```

好的,就到这里吧。我已经尽力了,但是要完全理解并配置Squid的细节仍然需要很多时间。由于实际上几乎没有关于Squid的文档,我很清楚这个应用程序仍然处于起步阶段,并且它的架构非常微妙。我只是在启动Squid之前没有检查缓存目录。

我需要回去真正开始赚钱,而不是纠缠于一些复杂的技术细节。

链接:

cd /opt/local/var/squid

如果 [ ! -d "/opt/local/var/squid/cache/00" ]; then

su -fm squid -c "exec /opt/local/sbin/squid -s -z"

fi

su -fm squid -c "exec /opt/local/sbin/squid -s"

用户配置文件的用户: Quantumstate

Quantumstate 作者

用户级别: Level 1

30分

Thanks for your response, etre. You may be right that a script could handle this, but I was curious if it should chown the process to squid or use the plist, and there are probably a hundred other unforeseen problems that come with launching a service in launchd. As it turns out, the error message "execve(): No such file or directory" is a vague catch-all error that can arise in many different situations and never provide any specific guidance. Unfortunately, I don't have much time left to dedicate to this issue. I need to focus on making ends meet.

Link