PDA

View Full Version : StartupItems in Tiger


pthomson
09-07-2005, 11:31 PM
I'm having trouble figuring out how to make a startup item in Tiger. I have installed a program called gnump3d (www.gnu.org/gnump3d) and I want it to start at boot time. Based on what I've read about launchd, I've put a directory called GNUMP3D in /System/Library/StartupItems/. In this directory, I put some files that came with the software package: there's a script called GNUMP3D, which contains the following code:


#!/bin/sh

. /etc/rc.common

PATH=$PATH:/usr/local/bin

StartService ()
{
if ! pid=`GetPID gnump3d` ; then
ConsoleMessage "Starting GNUMP3 server"
gnump3d --quiet &
echo $! > /var/run/gnump3d.pid
else
ConsoleMessage "GNUMP3 server is already running"
fi
}

StopService ()
{
if pid=`GetPID gnump3d` ; then
ConsoleMessage "Stopping GNUMP3 server"
kill -TERM $pid
else
ConsoleMessage "GNUMP3 server is not running"
fi
}

RestartService () { StopService; sleep 1; StartService; }

RunService "$1"


Then there's a plist file, which contains this code:


{
Description = "gnump3d";
Provides = ("gnump3d");
OrderPreference = "none";
Messages =
{
start = "Starting GNUMP3 server";
stop = "Stopping GNUMP3 server";
};
}


Then there's a directory called Resources. In this directory is another one called English.lproj, and in that directory is a file called Localizable.strings, which contains this code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Starting GNUMP3 server</key>
<string>Starting MP3 server</string>
<key>Stopping GNUMP3 server</key>
<string>Stopping GNUMP3 server</string>
<key>GNUMP3 server is already running</key>
<string>GNUMP3 server is already running</string>
<key>GNUMP3 server is not running</key>
<string>GNUMP3 server is not running</string>
</dict>
</plist>


But even with these items in /System/Library/StartupItems/, gnump3d won't start at boot time. I've also tried these files in /Library/StartupItems/ and ~/Library/StartupItems/, but also to no avail. What am I doing wrong?

Raven
09-08-2005, 10:48 AM
Is there a .app file for that install ? How do you start it up when you simply want to start it while logged in ?

hayne
09-08-2005, 11:34 AM
It's probably just not finding the 'gnump3d' executable.
You should use a full path when you invoke it.

Another thing that could go wrong is that it depends on something that isn't running yet.

pthomson
09-08-2005, 12:24 PM
Is there a .app file for that install ? How do you start it up when you simply want to start it while logged in ?

It's a daemon (i.e., a server), so it runs from the command line. The path is /usr/bin/gnump3d

pthomson
09-08-2005, 12:26 PM
You should use a full path when you invoke it.

Where should I specify that?

hayne
09-08-2005, 12:43 PM
Where should I specify that?
Umm - at the place in the StartupItem script where you invoke 'gnump3d'

pthomson
09-08-2005, 11:44 PM
OK, even after fixing the script to include the full path, I get this when I run the startup script after the system has booted:


Apples-PowerBook-G4-15:/System/Library/StartupItems/GNUMP3D phil$ ./GNUMP3D
./GNUMP3D: line 30: $1: unbound variable


What does this mean and how do I fix it?

hayne
09-09-2005, 02:47 AM
OK, even after fixing the script to include the full path, I get this when I run the startup script after the system has booted:


Apples-PowerBook-G4-15:/System/Library/StartupItems/GNUMP3D phil$ ./GNUMP3D
./GNUMP3D: line 30: $1: unbound variable


What does this mean and how do I fix it?

The StartupItems scripts are not designed to be run manually.
They are run by /sbin/SystemStarter which supplies a command-line parameter.
If you need to, you can use SystemStarter to run your script manually.
Read 'man SystemStarter'

hayne
09-09-2005, 09:12 AM
By the way, you shouldn't be installing things under /System/Library - that is supposed to be reserved for Apple-supplied stuff. Your startup item should go under /Library/StartupItems (you may need to create this folder)

pthomson
09-09-2005, 12:28 PM
You're right, but as I mentioned above, the script doesn't work no matter where it is.

I've tried "sudo /sbin/SystemStarter start gnump3d" with absolutely no result. The server still doesn't start. I don't get any error message or anything, but when i go to localhost, port 8888 in a browser, it says "connection refused", which I assume mean that the server hasn't started, because usually when the server is running it's accessible through a browser.

In /var/log/gnump3d/error.log, there's an entry that says:


Caught a SIGTERM at /System/Library/Perl/5.8.6/darwin-thread-multi-2level/IO/Socket.pm line 183


But no errors related from after I moved the startup item to /Library/StartupItems. Is there some other error log I can look at? I find it frustrating that I get absolutely no feedback at all, just a silent refusal to start the server with no explanation.

hayne
09-09-2005, 12:50 PM
What happens when you start the server manually, with the command:
sudo gnump3d --quiet

It is strange that (if I have understood you properly) you get an error when the startup script is under /System/Library/StartupItems but not when it is under /Library/StartupItems

pthomson
09-09-2005, 01:07 PM
When I run "sudo gnump3d --quiet", the server starts and works fine, though I do get this error message:


main::sanitizePath() called too early to check prototype at /usr/bin/gnump3d line 913.
main::sanitizePath() called too early to check prototype at /usr/bin/gnump3d line 947.

hayne
09-09-2005, 01:46 PM
When I run "sudo gnump3d --quiet", the server starts and works fine, though I do get this error message:


main::sanitizePath() called too early to check prototype at /usr/bin/gnump3d line 913.
main::sanitizePath() called too early to check prototype at /usr/bin/gnump3d line 947.


Those are Perl warning messages - they indicate (small) bugs in the programming - nothing to worry about.

You need to add more debugging print statements to the startup item script.
You said earlier that you didn't see any result from running
sudo /sbin/SystemStarter start gnump3d
You should at least have seen the results of the statement
ConsoleMessage "Starting GNUMP3 server"
Maybe it is in the console.log or system.log ?
(Access the logs via /Applications/Utilities/Console.app)
Add more such ConsoleMessage statements to convince yourself that the script is getting run. Maybe add some ordinary "echo" statements just for troubleshooting.
And try using the debugging facilities of SystemStarter (see man page) - e.g. the "-v", "-D", "-n" options.

pthomson
09-09-2005, 03:58 PM
I found these lines in the log:


Sep 9 10:26:49 Apples-PowerBook-G4-15 SystemStarter[341]: Unknown service: GNUMP3D
Sep 9 10:26:57 Apples-PowerBook-G4-15 SystemStarter[342]: Unknown service: gnump3d
Sep 9 10:45:36 Apples-PowerBook-G4-15 SystemStarter[356]: Unknown service: gnump3d
Sep 9 10:48:23 Apples-PowerBook-G4-15 SystemStarter[386]: Unknown service: gnump3d


Running "sudo SystemStarter -D start gnump3d" gives me a bunch of info, including this first line: ""/Library/StartupItems" failed security check: not owned by GID 0". Could this be the issue? Do I need to set the ownership on that dir to GID 0? I tried "sudo chgrp root /Library/StartupItems" but that doesn't work. I'm not actually sure what GID 0 is in Darwin.

hayne
09-09-2005, 08:26 PM
Running "sudo SystemStarter -D start gnump3d" gives me a bunch of info, including this first line: ""/Library/StartupItems" failed security check: not owned by GID 0". Could this be the issue? Do I need to set the ownership on that dir to GID 0? I tried "sudo chgrp root /Library/StartupItems" but that doesn't work. I'm not actually sure what GID 0 is in Darwin.

If you run the command:
nidump group /
you will see that group 'wheel' has id 0

pthomson
09-09-2005, 08:39 PM
Works now. Thanks for your help!