But it did not start.
I used this to add the service to systemd:
chkconfig -add myservice
I have other systems very similarly configured where it is working. I appear to have made some change which creates this problem but have a hard time debugging it because no errors are thrown and systemd claims to have done the right thing.
The only Journal entry created when I run the start command is:
Aug 09 16:41:19 hostname systemd[1]: Started LSB: myservice.
/var/log/messages did not provide any additional information
You never said what “service is started” means, so it is impossible to guess anything. The only factual information you provided that whatever process was started by your script exited.
There are others MySQL instances that are using almost the exact same script and start just fine. Again, no errors are ever throne and executing this script directly with “start” gets things moving properly. Systemctl start does nothing but claims it ran the init script with “start”.
#!/bin/sh
#
# MySQL This shell script takes care of starting and stopping
# the MySQL instance for WEB (001).
### BEGIN INIT INFO
# Provides: mysql-WEB
# Required-Start:
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: MySQL-WEB
# Description: MySQL-WEB
### END INIT INFO
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting MySQL for WEB (001): "
cd ~mysql-WEB
su - mysql-WEB -c "/usr/bin/mysqld_safe --defaults-file=/etc/mysql/WEB/my.cnf --socket=/var/lib/mysql/WEB/mysql.sock" &
RETVAL=$?
$RETVAL -eq 0 ] && touch /var/lock/subsys/mysql-WEB
echo
;;
stop)
# Stop daemons.
echo -n "Shutting down WEB (001): "
cd ~mysql-WEB
mysqladmin --user=shutdownUser --password=STV6DZqwaZ_cLEyi90CVyjqVB1RG7vdTUAm_olU0 --socket /var/lib/mysql/WEB/mysql.sock shutdown
RETVAL=$?
$RETVAL -eq 0 ] && rm -f /var/lock/subsys/mysql-WEB
echo
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: mysql {start|stop|restart}"
exit 1
esac
exit $RETVAL
/var/lib/mysql/WEB/ is where the log files show up, it is the data directory specified in my.cnf
Things have progressed somewhat, I can now get starting to work reliably but shutdown does not. No, I don’t know what changed. It seems that for the first run I must use /etc/init.d/ but after that I can use systemctl start.
The init script is below.
If I use
/etc/init.d/WEB stop
the process will stop as apparent by the removal of the .sock and the /var/lock/ file.
systemctl stop WEB
does not stop the process.
#!/bin/sh
#
# MySQL This shell script takes care of starting and stopping
# the MySQL instance for WEB (001).
### BEGIN INIT INFO
# Provides: mysql-WEB
# Required-Start:
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: MySQL-WEB
# Description: MySQL-WEB
### END INIT INFO
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting MySQL for WEB (001): "
cd ~mysql-WEB
su - mysql-WEB -c "/usr/bin/mysqld_safe --defaults-file=/etc/mysql/WEB/my.cnf --socket=/var/lib/mysql/WEB/mysql.sock" &
RETVAL=$?
$RETVAL -eq 0 ] && touch /var/lock/mysql-WEB
echo
;;
stop)
# Stop daemons.
echo -n "Shutting down WEB (001): "
cd ~mysql-WEB
mysqladmin --user=shutdownUser --password=gvikOrPIIcig2TJz2TEbgr6X5AdD_ZDtpNCaGYrR --socket /var/lib/mysql/WEB/mysql.sock shutdown
RETVAL=$?
$RETVAL -eq 0 ] && rm -f /var/lock/mysql-WEB
echo
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: mysql {start|stop|restart}"
exit 1
esac
exit $RETVAL
This output is for an instance that is currently running properly. Confirmed by connecting.
I guess that “Stopped LSB” is when the init script dies. As you can see in the previous post I use “&” because otherwise running systemctl start mysql-WEB would take focus on the shell forever. Should I move the & to systemctl start mysql-WEB and remove it from the init script?
mysql-WEB.service - LSB: MySQL-WEB
Loaded: loaded (/etc/init.d/mysql-WEB)
Active: failed (Result: exit-code) since Fri, 2013-08-09 20:44:24 UTC; 6min ago
Process: 3220 ExecStop=/etc/init.d/mysql-WEB stop (code=exited, status=1/FAILURE)
Process: 3215 ExecStart=/etc/init.d/mysql-WEB start (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/mysql-WEB.service
Aug 09 20:44:24 firewall-testing mysql-WEB[3215]: Starting MySQL for WEB (001):
Aug 09 20:44:24 firewall-testing systemd[1]: Started LSB: MySQL-WEB.
Aug 09 20:44:24 firewall-testing su[3216]: (to mysql-WEB) root on none
Aug 09 20:44:24 firewall-testing mysql-WEB[3220]: [80B blob data]
Aug 09 20:44:24 firewall-testing mysql-WEB[3220]: error: 'Can't connect to local MySQL serve...)'
Aug 09 20:44:24 firewall-testing mysql-WEB[3220]: Check that mysqld is running and that the ...s!
Aug 09 20:44:24 firewall-testing systemd[1]: Unit mysql-WEB.service entered failed state
Aug 09 20:44:24 firewall-testing mysql-WEB[3215]: Starting mysqld daemon with databases from...EB
Aug 09 20:44:32 firewall-testing systemd[1]: Stopped LSB: MySQL-WEB.
On 2013-08-09 21:36, ug2215 wrote:
>
> There are others MySQL instances that are using almost the exact same
> script and start just fine. Again, no errors are ever throne and
> executing this script directly with “start” gets things moving properly.
> Systemctl start does nothing but claims it ran the init script with
> “start”.
I’m unsure if Required-Start and Required-Stop are needed. And provides.
I’m unsure if would really work on systemv.
> /var/lib/mysql/WEB/ is where the log files show up, it is the data
> directory specified in my.cnf
You can also create echo lines to show in the logs.
–
Cheers / Saludos,
Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)
Please tell me you have downloaded my bash script SysdCmd. It will make such things a lot easier for you. The following terminal command will download and run the file for you:
What you have here is race condition. systemd expects one main process that represents service. Service is running as long as this process is running. In your case you fork “su” and exit immediately. systemd assumes what is left is the main process and declares “su” to be the service. Next su starts mysqld (as background process …) and exits. For systemd it means service has finished and it initiates cleanup.
One workaround is to declare PID file for a service. In this case systemd will wait until PID file appears and take the PID there as main pid. This can be done by adding PIDFile comment to INIT INFO block, like
### BEGIN INIT INFO
...
# PIDFile: /var/run/myservice.pid
...
### END INIT INFO
Of course, your service has to actually use PID file for this to be useful.
To correct myself - for legacy sysvinit service it does not do it by default. From your status output it looks like genuine MySQL configuration issue, unfortunately output is truncated so it is impossible to say what was missing.
On 2013-08-10 07:26, arvidjaar wrote:
> What you have here is race condition. systemd expects one main process
> that represents service. Service is running as long as this process is
> running. In your case you fork “su” and exit immediately. systemd
> assumes what is left is the main process and declares “su” to be the
> service. Next su starts mysqld (as background process …) and exits.
> For systemd it means service has finished and it initiates cleanup.
Wow! :-o
–
Cheers / Saludos,
Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)