# [REQUEST] - HowTo setup startup services on Jaguar (10.2.3)



## wiz (Jan 1, 2003)

could someone ceate a [HowTo] on this?

thanks

for some reason my mysql setup won't work. 

i've added the MYSQL=-YES- in the /etc/hostconfig

and created the folder /Library/StartupItems/MySQL
created file MySQL 
created file StartupParametres.plist



but still it dosen't work

the problem seems to be, 
  the MYSQL env var is not not being read or its set to -NO- although i explictly set it to -YES- 
and hence the mysqld is never initialized

otherwise everything is fine


----------



## slur (Jan 2, 2003)

Did you install MySQL using the packages available at entropy.ch? These make it a lot easier.

So to troubleshoot...

- In my (entropy) installed version of MySQL there's also a "Resources" folder containing an "English.lproj" file. I'm not sure if this is necessary.

- The MySQL script has to be executable. Is it?

- The MySQL script should contain something like this:

#!/bin/sh

. /etc/rc.common

if [ "${MYSQL:=-YES-}" = "-YES-" ]; then

	ConsoleMessage "Starting MySQL database server"

        cd /usr/local/
		REALDIR=`perl -e 'print readlink "mysql"'`
		cd $REALDIR

        ulimit -n 6000

        if [ -e ./bin/safe_mysqld ]; then
			./bin/safe_mysqld --user=mysql &
		elif [ -e ./bin/mysqld_safe ]; then
			./bin/mysqld_safe --user=mysql &
	else
		ConsoleMessage "Found neither safe_mysqld nor mysqld_safe"
	fi

fi

- My StartupParameters.plist file has these contents. How does it compare to yours?:

{
  Description   = "MySQL database server";
  Provides      = ("MySQL");
  Requires      = ("Resolver");
  Preference    = "Late";
  Messages =
  {
    start = "Starting MySQL";
    stop  = "Stopping MySQL";
  };
}


----------



## LordCoven (Jan 3, 2003)

.... if you can start / stop the service manually with the SystemStarter command:

SystemStarter start MySQL
or
SystemStarter stop MySQL

If you get any errors with this (which I did), then you'll have to get this to work first. In my case, the script was using the default MySQL environment for startup, whereas the version directly from MySQL has to be configured slightly different. I can post my version of the script here later if you want.

C


----------



## wiz (Jan 3, 2003)

well actually i got it working !!!
using the Jaguar style startup script!!
(/Library/StartupItems/MySQL/MySQL)

here my script...

```
#!/bin/sh

##
# MySQL Database Server
##

. /etc/rc.common

StartService ()
{
    if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
	ConsoleMessage "Starting MySQL"
	cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe --user=mysql &
    fi
}

StopService ()
{
    ConsoleMessage "Stopping MySQL"
    /usr/local/mysql/bin/mysqladmin shutdown
}

RestartService ()
{
    if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
	ConsoleMessage "Restarting MySQL"
	StopService
	StartService
    else
	StopService
    fi
}

RunService "$1"
```

this is cool actually since u can manually start/stop/restart the service by just typing this at command line

```
sudo /Library/StartupItems/MySQL/MySQL start
sudo /Library/StartupItems/MySQL/MySQL restart
sudo /Library/StartupItems/MySQL/MySQL stop
```


----------



## wiz (Jan 3, 2003)

but tryin the system starter i get the following  error: 
Unable to load localization strings for 

i guess thats because i don't have that English.lproj file


----------



## wiz (Jan 3, 2003)

here is my StartupParameter.plist contents tooo, Jaguar style... (XML actually)
(/Library/StartupItems/MySQL/StartupParameter.plist)


```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Description</key>
	<string>MySQL Database Server</string>
	<key>OrderPreference</key>
	<string>Late</string>
	<key>Provides</key>
	<array>
		<string>MySQL</string>
	</array>
	<key>Requires</key>
	<array>
		<string>Network</string>
	</array>
</dict>
</plist>
```


----------



## roguephp (Jan 11, 2003)

so wiz,

to get your startup XML script to work, I create a directory inside System/Library/StartupItems called mySQL and put your script in there with the correct path to my mySQL directory?

Thanks


----------



## wiz (Jan 11, 2003)

ditto

but the script might not work with MySQL 3.x
to get it working...

just replace the

```
StartService ()
{
    if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting MySQL"
        cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe --user=mysql &
    fi
}
```

with 

```
StartService ()
{
    if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting MySQL"
        cd /usr/local/mysql ; /usr/local/mysql/bin/safe_mysqld --user=mysql &
    fi
}
```

notice it's changed from mysqld_safe (4.x) to safe_mysqld for (3.x).

NOTE: some newer binary releases of 4.x have a link name safe_mysqld that links to mysqld_safe

also don't forget to add the MYSQL=-YES- in the /etc/hostconfig   
replacing it with MYSQL=-NO- will stop initializing the mysql server on startup

TIP: backup that hostconfig file, it's safer


----------



## roguephp (Jan 13, 2003)

Wiz,

I am trying to get MySQL to start as in your example but it doesn't start when I boot. So... I was digging around the forums looking for clues and I found a way to see what is happening at startup by typing:

sudo SystemStarter restart 

anyhow... when I do this and watch the terminal, I get this:

<snip>
Starting NetInfo
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Waiting for MySQL Database Server
Resetting Directory Services
Starting printing services
Tuning system
/usr/sbin/apachectl stop: httpd (no pid file) not running
Restarting system log
boot-command    mac-boot
kern.maxvnodes: 24880 -> 36656
kern.sysv.shmmax: 4194304 -> 4194304
kern.sysv.shmmin: 1 -> 1
kern.sysv.shmmni: 32 -> 32
kern.sysv.shmseg: 8 -> 8
kern.sysv.shmall: 1024 -> 1024
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
MySQL Database Server (614) did not complete successfully.
Waiting for AppleTalk networking
Startup complete.


Anyone have any thoughts?

Thanks
ck


----------



## wiz (Jan 15, 2003)

your mysql server did not startup, so SystemStarter cannot technically restart it.

when you  execute: sudo SystemStarter restart
SystemStarter, trys to stop the running instance of the MySQL server, which does not exist.

try this...
sudo SystemStarter start MySQL

check the results


----------



## wiz (Jan 15, 2003)

(the details)

Create the dir *MySQL* in */Library/StartupItems/*

Add both those scripts (above).

Set the executable bit of the MySQL script.

Set the group of the MySQL dir, and contents to: *admin*

Add *MYSQL=-YES-* to the */etc/hostconfig* file

Type this: *sudo SystemStarter start MySQL*
--it works?--

restart the computer.
--did mysqld startup?--

login using the client typing: */usr/local/mysql/bin/mysql*
--it works?--

It should all work.

But i must say before i typed in "SystemStarter start MySQL" I did try  restarting the mac. 
I logged in using the client typing: */usr/local/mysql/bin/mysql*
--it did not work--
Funny? hmm... It seems that SystemStarter registers it as a startup daemon or something (i could be wrong), although just adding the *MYSQL=-YES-* to the */etc/hostconfig* file, is supposed to do the trick.


----------



## gatorparrots (Jan 17, 2003)

Here is a very good how-to on creating StartupItems:
http://www.macfora.com/forums/showthread.php?s=&threadid=6314


----------

