我开发了一个在Mac启动时运行的Deamon,这个守护程序正常运行,直到我安装了一个新的OSX 10.8.5 [这个守护程序正确运行10.8.4]。
我不知道我的错误在哪里,
我创建了一个终端应用程序,可以编写如下字典:
KeepAlive = 1;
Label = "vetrya.ControlloPresenza";
MachServices = {
"vetrya.ControlloPresenza" = 1;
};
Program = "/System/Library/VetryaControllo/ControlloPresenza";
ProgramArguments = start;
RunAtLoad = 1;
StartInterval = 20;
inetdCompatibility = {
Wait = 0;
};
然后在这个目录中写下这个词:/ System / Library / LaunchDaemons /
但现在这个过程没有开始,有人知道这个的原因吗?
这是我怎么写dict和plist war的结果写得正确
NSMutableArray* arrayArguments = [[NSMutableArray alloc] initWithCapacity:1];
[arrayArguments addObject:@"/System/Library/VetryaControllo/ControlloPresenza"];
[arrayArguments addObject:@"start"];
NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:NO],@"Wait", nil];
NSDictionary* dictNew = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"vetrya.ControlloPresenza", nil];
[self.controlloPresenza setObject:@"vetrya.ControlloPresenza" forKey:@"Label"];
[self.controlloPresenza setObject:@"/System/Library/VetryaControllo/ControlloPresenza" forKey:@"Program"];
[self.controlloPresenza setObject:@"start" forKey:@"ProgramArguments"];
[self.controlloPresenza setObject:dict forKey:@"inetdCompatibility"];
[self.controlloPresenza setObject:dictNew forKey:@"MachServices"];
[self.controlloPresenza setObject:[NSNumber numberWithBool:YES] forKey:@"KeepAlive"];
[self.controlloPresenza setObject:[NSNumber numberWithBool:YES] forKey:@"RunAtLoad"];
[self.controlloPresenza setObject:[NSNumber numberWithInt:20] forKey:@"StartInterval"];
我现在已经做了一些改变,因为plist正在跟随:
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>vetrya.ControlloPresenza</string>
<key>MachServices</key>
<dict>
<key>vetrya.ControlloPresenza</key>
<true/>
</dict>
<key>Program</key>
<string>/System/Library/VetryaControllo/ControlloPresenza</string>
<key>ProgramArguments</key>
<string>start</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>20</integer>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
</dict>
</plist>
我已经在线发现要将守护进程注册到下次重启,我可以使用这个终端命令:
sudo chown root:wheel <name.plist>
sudo chmod 644 <name.plist>
但是当我像这样创建NSTask时:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath:_registrationPath];
[task setArguments: @[@"sudo", @"chown",@"root:wheel",@"vetrya.ControlloPresenza.plist"]];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
[task waitUntilExit];
task = [[NSTask alloc] init];
[task setLaunchPath:_registrationPath];
[task setArguments: @[@"sudo", @"chmod",@"644",@"vetrya.ControlloPresenza.plist"]];
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
file = [pipe fileHandleForReading];
[task launch];
[task waitUntilExit];
但最后我有这个错误:失败:22,“无效的参数”。 我怎么写这个命令?
此致
答案 0 :(得分:0)
您可能只是从问题中显示的示例中省略了这个,因为您说您正在写出值,但如果您在Daemons and Services上阅读了Apple文档,那么' ll看到plist要求你指定键和值,如下所示: -
<key>KeepAlive</key>
<integer>1</integer>
<key>Label</key>
<string>"vetrya.ControlloPresenza"</string>
此外,如果你正在做的事情,我看到你将程序参数设置为一个值,而不是一个字符串数组,这将使它成为:
<key>ProgramArguments</key>
<array>
<string>start</string>
</array>