Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
<<root|red:/etc>># ls -l rc5.d/S95mysystem
lrwxrwxrwx. 1 root root 18 Jun 8 13:03 rc5.d/S95mysystem -> ../init.d/mysystem
but still not ...
then i added command to /etc/rc.local
Code:
<<root|red:/etc>># cat rc.local
#!/bin/bash
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
service mysystem start
touch /var/lock/subsys/local
but still not ...
if i start service via command line it's works.
what i did wrong ?
i've raplaced service mysystem start to mysystem start in /etc/rc.local
and here is /var/log/boot.log tail :
Code:
Starting MySystem: Starting libvirtd daemon: 2015-06-08 19:02:33.890+0000: 2506: info : libvirt version: 0.10.2, package: 29.el6 (CentOS BuildSystem <http://bugs.centos.org>, 2013-11-23-13:07:07, c6b8.bsys.dev.centos.org)
2015-06-08 19:02:33.890+0000: 2506: warning : virGetHostname:2294 : getaddrinfo failed for 'red': Name or service not known
[ OK ]
Starting up CIM server: [ OK ]
Starting certmonger: [ OK ]
/etc/rc5.d/S99local: line 6: mysystem: command not found
i've raplaced service mysystem start to mysystem start in /etc/rc.local
and here is /var/log/boot.log tail :
Code:
Starting MySystem: Starting libvirtd daemon: 2015-06-08 19:02:33.890+0000: 2506: info : libvirt version: 0.10.2, package: 29.el6 (CentOS BuildSystem <http://bugs.centos.org>, 2013-11-23-13:07:07, c6b8.bsys.dev.centos.org)
2015-06-08 19:02:33.890+0000: 2506: warning : virGetHostname:2294 : getaddrinfo failed for 'red': Name or service not known
[ OK ]
Starting up CIM server: [ OK ]
Starting certmonger: [ OK ]
/etc/rc5.d/S99local: line 6: mysystem: command not found
Get the path for mysystem and put it in explicitly in the script.
which didn't found mysystem, i've just put it into /etc/init.d/
Code:
<<root|red:~>># which mysystem
/usr/bin/which: no mysystem in (/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
Is there an actual mysystem program other then the startup script you created. Are you just wanting to check the status of mysql and restart the computer if not running? Does mysql frequently crash on boot up?
You could just move that part of the script to rc.local.
No, there is no actual mysystem program, this is just script. i want to check if there wasn't normal system down, this is marked as 'crash' in first line last command output , then i try to remove old mysql.sock, which is automatically created at next system boot by mysql. this is case of webserver 24/7 uptime. sometimes occours power loss.
this might be solved in different ways. but i want to know why is not working ?
There isn't a path environment yet so your if statement is failing (if [ "$(last | head -1 | grep -c 'still')" == 1 ]). You can add the path like below to your script.
There isn't a path environment yet so your if statement is failing (if [ "$(last | head -1 | grep -c 'still')" == 1 ]). You can add the path like below to your script.
PATH=/usr/bin
so i changed my script to this:
Code:
[laser@red~]$ cat mysystem2
#!/bin/bash
PATH=/usr/bin:/sbin:/bin:/home/laser
echo "-------------------------------" >> /home/laser/mysystem2.log
echo "$PATH" >> /home/laser/mysystem2.log
echo "mysystem2 is running" >> /home/laser/mysystem2.log
if [ "$(last | head -1 | grep -c 'still')" == 1 ]
then
echo "last, head, grep succeed" >> /home/laser/mysystem2.log
$(service mysqld stop)
echo "service mysqld status" >> /home/laser/mysystem2.log
$(mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bakup)
if [ $? == 0 ]
then
echo "mv succeed" >> /home/laser/mysystem2.log
fi
$(rm -f /var/lib/mysql/mysql.sock)
if [ $? == 0 ]
then
echo "rm succeed" >> /home/laser/mysystem2.log
fi
$(shutdown -r 2)
fi
<<root|red:/home/laser>># cat /etc/rc.local
#!/bin/bash
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
/home/laser/mysystem2
touch /var/lock/subsys/local
mysystem2.log :
Code:
<<root|red:/home/laser>># cat mysystem2.log
-------------------------------
/usr/bin:/sbin:/bin:/home/laser
mysystem2 is running
and extra :
/var/log/boot.log last 3 lines
Code:
Starting up CIM server: [ OK ]
Starting certmonger: [ OK ]
Get more fundamental and debug with some coherence.
You say the script runs when you execute it manually and also that you're having difficulties in running it out of rc.local and/or trying to run it as part of the rc5.d init sequence. So debug piece by piece.
Write a very simple script that just echo's a log to a file
Call that script from rc.local and verify that it does or doesn't work
Similarly verify that you can create a symbolic link in rc5.d and cause that test script to run, or if that doesn't work
Presuming that you can successfully invoke a script from rc.local or rc5.d, then what is next is to determine why your particular script does not run correctly when invoked from rc.local
Incorporate added debug to show that you've entered your script
Add debug to determine the result codes for when you run specific commands and also output that information to a log file
Determine the environment circumstances for when you run the script manually to assist you in why the script works manually but not via rc.local
When running manually, add a "set -xv" line to the top of your script, but below the #!/bin/bash line. This will enable debug and show you verbose output as to what happens when you run locally, and this may give you an idea where the path for things are, or what defined variables are of consequence when running the script
See the My Bash Blog link in my signature for added tips on BASH scripting
mistake was at the very top in script -> Note: for testing purpose i grep -c 'still'
that has been flowing to down.
i amended the first line :
Code:
#!/bin/bash -xv
and this showed up that evaluation of expression
Code:
[ "$(last | head -1 | grep -c 'still')" == 1 ]
was false, because until logged in system, there is no line in last command output containing - still,
very top line is
Code:
reboot system boot 2.6.32-431.el6.x Tue Jun 9 15:17 - 15:38 (00:21)
Code:
last | head -1 | grep -c 'still')"
last | head -1 | grep -c 'still')
last | head -1 | grep -c 'still'
++ grep -c still
++ last
++ head -1
+ '[' 0 == 1 ']'
So it's solved !
from /etc/init.d/mysystem works also.
i solved this by myself, but thanks anyway.
Last edited by crocodile9; 06-09-2015 at 09:41 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.