Making a program/service ( MySQL ) start up on boot ( FC3 )
FedoraThis forum is for the discussion of the Fedora Project.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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!
#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!
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'.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.