Startup Commands and Items

Hello,

I got some commands that I would like Mac OS X to run at startup. How can I do that. In Windows I just create file.bat and add it to the startup folder.

Some commands include

sudo apachectl start
sudo apachectl graceful
sudo apachectl configtest
sudo postfix start
sudo imaps
hostname -s $hostname$

and more!

Mateusz

Posted on Oct 14, 2005 5:34 PM

Reply
8 replies

Oct 14, 2005 10:39 PM in response to Mateusz Rajca

None of these commands need to be put into a startup item. Even if they were they wouldn't work since sudo would require authentication before running the commands.

Instead, edit /etc/hostconfig
Here you'll find controls for most of the standard system daemons such as apache and postfix. Just edit this file to say '-YES-' against all the options you want and you're set.

As for the script file question, did you change the file mode to mark it as executable?

Oct 14, 2005 11:08 PM in response to Mateusz Rajca

Mateusz--

Since you're on Tiger, you need to look at Apple's System Startup Programming Topics. Also, search the Unix discussions here for "launchd".

Starting Postfix when the system starts up is covered on this page, and it also has an example Startup Item for Tiger. Note: I haven't tried any of this, though I used the Panther Postfix instructions on that page with success.

best,

charlie

Oct 15, 2005 11:52 AM in response to Mateusz Rajca

Hi Mateusz,
The StartupItems are the closest thing to the Windoze startup folder. It's a little more complicated because it's run earlier in the startup process when order matters. You can create scripts for it that will be run at boot. However, mechanisms for starting the two services you mentioned, Apache and Postfix, already exist.

Whether or not they are actually started is controlled by the /etc/hostconfig file, exactly as Camelot described. In fact, the startup of Apache can be controlled by the checkbox beside "Personal Web Sharing" in the "Sharing" pane of "System Preferences". Of course that simply edits the /etc/hostconfig file as Camelot describes.
--
Gary
~~~~
The chat program is in public domain. This is not the GNU
public license. If it breaks then you get to keep both pieces.
(Copyright notice for the chat program)

Oct 15, 2005 10:52 PM in response to Mateusz Rajca

What was the first line of the file run.sh?

If it wasn't something along the lines of

#!/bin/sh

that would, I think, be part of the explanation.


And did you make it into an executable file, using a command like

chmod +x run.sh

?

Even so, using StartupItems, as others have mentioned, is the proper way to do it.

If you do end up doing this with a shell script as a login item, then note also that login items run when you login, not when you boot. So consider what will happen if you logout without shutting down, and then what if you login again, without having shut down.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Startup Commands and Items

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.