• Uncategorized

About linux : I-cant-make-my-script-run-on-boot-with-any-method-presented-here-cron-rclocal-chkconfig-service—Oracle-Database-19C-SCRIPT

Question Detail

I’m currently trying to run my script on startup, being an Oracle 19C script for starting the database and the listener at system boot , I will paste it here (script.sh) . The way I’m trying to work is as manually as possible, I don’t want to include it in oratab or anything else. I’m currently working on a Virtual Machine with Oracle Linux 7.9 installed :

# /etc/init.d/script.sh
# chkconfig: 2345 85 60
source oraenv

sqlplus << EOF
connect / as sysdba
echo "Database opened"

 pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID"  | grep -v grep`
  if [ "$pmon" != "" ] ; then
    echo "${ORACLE_SID} already opeened."
  else startdatabase

 status=`lsnrctl status | grep "Connection refused"`
  if [ "$status" != "" ]; then
  lsnrctl start
        echo "Listener opened"
  else echo "Listener off"

The script is located in /etc/init.d with script.sh being its name. I tried to run it on startup using crontab :

 @reboot sh /etc/init.d/script.sh

or @reboot /etc/init.d/script.sh

I tried also with with article : https://unix.stackexchange.com/questions/188042/running-a-script-during-booting-startup-init-d-vs-cron-reboot but nothing seems to work, also if I do chkconfig –list it will show me this, as it should be running :

script.sh       0:off   1:off   2:on    3:on    4:on    5:on    6:off

The script is also executable, I’ve tried with rc.local file and also doesn’t work :

-rwxrwxr-x.  1 oracle oracle   900 Dec 29 15:16 script.sh

How can I make this work and run at startup ? It’s really frustrating, I’ve tried all the methods and it will not just load at boot and do its job. Any help would be much appreciated ! I’ve checked also for a lot of articles and none of them help. I want to mention also that the script works just fine when running normally. Thank you !

Question Answer

  1. Your script cannot and should not run in a crontab.

Because crontab script has no built in environment. Therefore everything need to be expressed in full/absolute path.

  1. Your script should not be located in /etc/init.d . Because it is not initialized automatically by SysV service nor by systemd service.

  2. Better put your script under user oracle home init folder (assuming oracle is the correct user for running Oracle RDBMS).

    mkdir -p /home/oracle/init
    mv /etc/init.d/script.sh /home/oracle/init
  3. Inject user oracle environment variables to your script.

    sed -i '4a source /home/oracle/.bash_profile' /home/oracle/init/script.sh
  4. Test running /home/oracle/init/script.sh from another effective user (use sudo or su command).

  5. Reboot.

  6. The correct and better design is to start Oracle RDBMS with a systemd service.

  7. It is possible to start Oracle RDBMS container with docker run ....

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.