LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 06-26-2005, 08:09 AM   #1
karmazilla
LQ Newbie
 
Registered: Apr 2005
Posts: 13

Rep: Reputation: 0
Making a program/service ( MySQL ) start up on boot ( FC3 )


Situation:
I have configured an Apache 2 webserver, a MySQL server and a MediaWiki site on my Fedora Core 3 box, and made Apache listen on the 127.0.0.1:80 loop-back.
And I have fought battles against SELinux, the RPM system, and a change in the MySQL authentication protocol since 4.1 that turned out to not be supported by MediaWiki (so I now run 4.0).
All of this, so I could get my own personal little wiki to play with (notekeeping and information management).
And I have been victorious so far, in my effort.

Everything is up and running, and working as desired - with the exception of one little missing bit:

Problem:
I want to make my MySQL server start up when I boot my computer.
In reality, I want this command:
Code:
mysqld_safe --user=mysql
to be invoked as a service, along with all the other services running on my box (including the Apache server).
I don't want to be refered to system-config-services.
I want to be directed to a (conf?) file when I and my favorite text-editor can make the above happen - if that actually is possible.

That is all.
 
Old 06-26-2005, 08:41 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Do you have some reason why you can't just put the command in /etc/rc.sysinit or, better, /etc/rc.d/rc.local?
 
Old 06-26-2005, 02:39 PM   #3
karmazilla
LQ Newbie
 
Registered: Apr 2005
Posts: 13

Original Poster
Rep: Reputation: 0
First, the reason why I didn't is because of a big black hole in my knowledge regarding how linux boots.

Now that I have tried the above, I know why I can't: the mysqld_safe script runs for as long as the MySQL server, and does not return until the server shuts down.
This behavior hangs GRUP because GRUP expects it to report back (probably in exit code) whether or not the attempt to start a service was successful.

Appart from that, it was a great suggestion; the system began to boot as it useually does, GRUP starts to init the services one by one having each and every init result in a green "OK" text, until it comes to a service named 'local'. The service begins to init, and the MySQL server starts, runs and keep running, while GRUP just sit there waiting for it to stop and return an exit code.
 
Old 06-27-2005, 08:41 AM   #4
karmazilla
LQ Newbie
 
Registered: Apr 2005
Posts: 13

Original Poster
Rep: Reputation: 0
This is starting to give me gray hairs...

I have created a special daemon script - adapted from the script the NetworkManager uses:

Code:
#!/bin/sh
#
# MySQL        MySQL 4.x daemon startup script.
#
# This script was developed and tested on Fedora Core 3 with MySQL 4.0.
# Use at your OWN risk and RESPONSABILITY!
# No warranty supplied nor implied.
# This script was adapted from the NetworkManager script - if anyone cares.
#
# chkconfig: - 84
# description:  The MySQL 4.x Database server.
#
# processname: MySQL
# pidfile: /var/run/NetworkManager.pid
#

# the MySQL bin path (is by default pointing at the default MySQL bin path.
# for your distribution, you might wanna change this!)
binpath=/usr/local/mysql/bin

# Make shure this is at all possible
[ -x $binpath/mysql_safe ] || exit 1

# In order to stop again, we'll mysqladmin since kill signals are trapped
[ -x $binpath/mysqladmin ] || exit 1

# Source function library.
. /etc/rc.d/init.d/functions

# so we can rearrange this easily
servicename=mysqld_safe --user=mysql

# we need a MySQL user with SHUTDOWN privileges
user=root
# and his password
password= 

RETVAL=0

start()
{
	echo -n $"Starting MySQL server: "
	daemon $servicename
	RETVAL=$?
	# I don't think that this is really need, but who knows?
	# commented out anyways.
	#[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename 
	echo
	return $RETVAL
}

stop()
{
	echo -n $"Stopping MySQL server: "
	# killproc $servicename -TERM # kills are trapped so we have to use mysqladmin
	# mysqladmin handles all that .pid stuff so we have our hands free
	$binpath/mysqladmin shutdown --user=$user --password=$password
	RETVAL=$?
	echo
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status $processname
		RETVAL=$?
		;;
	restart)
		stop
		start
		;;
#	condrestart)
#		if [ -f /var/lock/subsys/$servicename ]; then
#			stop
#			start
#		fi
#		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart}" #|condrestart}"
		;;
esac
exit $RETVAL
This script exists in the file /etc/rc.d/init.d/MySQL and that directory (init.d) contains scripts for all the other services on my box.

Second, I have also created a link to that script in /etc/rc.d/rc5.d/S84MySQL so one should expect that this means it gets executed when I boot into run-level 5.

BUT IT DOSN'T! And system-config-services stiff-necked instist that there's no such thing as a "MySQL" service!

Grrr..! This certainly ain't easy.
 
Old 06-27-2005, 09:57 AM   #5
karmazilla
LQ Newbie
 
Registered: Apr 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Cool Problem Solved

Problem Solved:

mysql_starter.c:
Code:
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	int status;
	pid_t pid;
	
	pid = fork ();
	if (pid == 0)
	{
		status = system("mysqld_safe --user=mysql");
	}
	else if (pid < 0)
		status = -1;
	return status;
}
Compile the above with something like: g++ mysql_starter.c -o mysql_starter
That'll produce an executable called mysql_starter, which can be put in, i.e. the /sbin directory.
Then add the line "mysql_starter" to the file /etc/rc.d/rc.local and it's done!
 
Old 06-27-2005, 10:03 AM   #6
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally posted by karmazilla
[snip]
Now that I have tried the above, I know why I can't: the mysqld_safe script runs for as long as the MySQL server, and does not return until the server shuts down.
This behavior hangs GRUP because GRUP expects it to report back (probably in exit code) whether or not the attempt to start a service was successful.
[snip]
Check out the "&" argument at the end to a command line in a script to run a command aynchronously.

See info bash under "Lists of commands," section 3.2.3 which says, in part
Quote:
If a command is terminated by the control operator `&', the shell
executes the command asynchronously in a subshell. This is known as
executing the command in the BACKGROUND. The shell does not wait for
the command to finish, and the return status is 0 (true). When job
control is not active, the standard input for
asynchronous commands, in the absence of any explicit redirections, is
redirected from `/dev/null'.
 
Old 06-27-2005, 10:19 AM   #7
karmazilla
LQ Newbie
 
Registered: Apr 2005
Posts: 13

Original Poster
Rep: Reputation: 0
hmm..... that is also an option. ty.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get service to start at boot zaichik Linux - Newbie 12 08-27-2008 09:15 PM
BOINC as a service to start at boot purelithium Linux - General 14 11-18-2005 09:04 PM
Network service start at boot? King of Japan Linux - Networking 2 09-01-2005 10:23 AM
how to start a service at boot senthilkumar Slackware 2 07-19-2004 07:33 AM
start the service for every boot time yuva_mca Linux - General 3 03-09-2004 01:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration