====== Datenbank unter Linux 6 und Linux 7 automatisch starten ====== ** 10.2016 ** Zuvor darauf achten das auch eine "/etc/oratab" Datei angelegt wurde! etc/oratab: GPIDB:/opt/oracle/products/12.1.0.2/dbhome_1:Y DB SID : Oracle Home : Soll die DB gestartet werden ---- ==== Start Linux Version 7 ==== === Start/Stop Scripte anlegen === Start Script unter "/opt/oracle/scripts/startStop.sh" als user "oracle" anlegen #!/bin/sh # edit the oracle home and user to your needs # ORACLE_HOME="/opt/oracle/product/12.1.0.2/dbhome_1" #set the Listner Home ORACLE_HOME_LISTNER=$ORACLE_HOME ############################# #dbstart exists? if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ] then echo "Oracle startup: cannot start" exit 1 fi ############################# # Datenbank starten oder stoppen case "$1" in start) # Oracle listener and instance startup echo -n "Starting Oracle: " $ORACLE_HOME/bin/dbstart $ORACLE_HOME_LISTNER #touch /var/lock/subsys/oracle echo "OK" ;; stop) # Oracle listener and instance shutdown echo -n "Shutdown Oracle: " $ORACLE_HOME/bin/dbshut $ORACLE_HOME_LISTNER #rm -f /var/lock/subsys/oracle echo "OK" ;; reload|restart) $0 stop $0 start ;; *) echo "Usage: $0 start|stop|restart|reload" exit 1 esac exit 0 Start/stop Scripts anlegen als user oracle vi /opt/oracle/scripts/startdb.sh #!/bin/sh /opt/oracle/scripts/startStop.sh start >> /opt/oracle/scripts/startup.log 2>&1 vi /opt/oracle/scripts/stopdb.sh #!/bin/sh /opt/oracle/scripts/startStop.sh stop >> /opt/oracle/scripts/shutdown.log 2>&1 chmod 777 stopdb.sh chmod 777 startdb.sh chmod 777 startStop.sh #Scripte als Oracle User testen! === Service anlegen === **User root** Datei "/lib/systemd/system/dbora.service" anlegen: [Unit] Description=The Oracle Database Service After=syslog.target network.target [Service] Type=simple RemainAfterExit=yes User=oracle Group=oinstall ExecStart=/opt/oracle/scripts/startdb.sh ExecStop=/opt/oracle/scripts/stopdb.sh [Install] WantedBy=multi-user.target Link anlegen: ln -s /lib/systemd/system/dbora.service /etc/systemd/system/dbora.service Reload systemd systemctl daemon-reload Starten und einschalten des Service: #Starten systemctl start dbora.service #Auto Start aktivieren systemctl enable dbora.service #Status prüfen systemctl status dbora.service -l #Stoppen systemctl stop dbora.service #prüfen ob die Start Reichenfolge auch passt: systemd-analyze critical-chain dbora.service Problem: Failed at step EXEC spawning ... Exec format error Oct 01 20:49:38 dns01.pipperr.local systemd[810]: Failed at step EXEC spawning /home/oracle/scripts/startdb.sh: Exec format error Oct 01 20:49:38 dns01.pipperr.local systemd[1]: dbora.service: main process exited, code=exited, status=203/EXEC => **"#!/bin/sh"** am Anfang vom Script nicht vergessen! ===Quellen=== Siehe auch * https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/chap-Managing_Services_with_systemd.html * https://oracle-base.com/articles/linux/linux-services-systemd * https://fedoraproject.org/wiki/How_to_debug_Systemd_problems * https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files ---- ==== Start Script für init.d bis Linux Version 6 ==== Wiedermal ein Script um die DB zu starten. hier gibt es wohl tausende von Varianten. \\ Es wird das Original Start / Stopp Script von Oracle dbstart / dbshut verwendet. Durch die Übergabe des Listener Homes als ersten Parameter wird auch entsprechend der Listener gestartet/gestoppt. Dazu muss die Datei "/etc/oratab" angelegt und die DB entsprechend auf Autostart konfiguriert werden (Beispiel anbei).\\ \\ Damit das ganze funktioniert, müssen entweder die richtigen Links von Hand gesetzt werden (System-V style) oder mit dem jeweiligen Runlevel Editor der Autostart aktiviert werden. \\ In Debian kann das einfach mit "rcconf" erfolgen. \\ Beispiel für die orginal oratab von Oracle: # # This file is used by ORACLE utilities. It is created by root.s # and updated by the Database Configuration Assistant when creating # a database. # A colon, ':', is used as the field terminator. A new line terminates # the entry. Lines beginning with a pound sign, '#', are comments. # # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:: # # The first and second fields are the system identifier and home # directory of the database respectively. The third filed indicates # to the dbstart utility that the database should , "Y", or should not, # "N", be brought up at system boot time. # # Multiple entries with the same $ORACLE_SID are not allowed. # # DB01:/opt/oracle/product/11.2.0/dbhome_1:Y Beispiel für ein Startscript: #!/bin/bash # # Run-level Startup script Oracle Instance und Listener # # ### BEGIN INIT INFO # Provides: Oracle DB Start # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop Oracle DB # Description: Start, stop and save Oracle DB ### END INIT INFO # # install # create file /etc/init.d/oracle # rights # chmod 777 /etc/init.d/oracle # add # chkconfig --add oracle # check # chkconfig | grep oracle ############################### # edit the oracle home and user ORACLE_HOME="/u01/app/oracle/product/10.2.0.5/dbhome_1" ORACLE_USER="oracle" ORACLE_HOME_LISTNER=$ORACLE_HOME ############################# #dbstart exists? if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ] then echo "Oracle startup: cannot start" exit 1 fi ############################# # Datenbank starten oder stoppen case "$1" in start) # Oracle listener and instance startup echo -n "Starting Oracle: " su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME_LISTNER" touch /var/lock/subsys/oracle echo "OK" ;; stop) # Oracle listener and instance shutdown echo -n "Shutdown Oracle: " su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME_LISTNER" rm -f /var/lock/subsys/oracle echo "OK" ;; reload|restart) $0 stop $0 start ;; *) echo "Usage: $0 start|stop|restart|reload" exit 1 esac exit 0 Die richtigen Rechte auf das Startscript vergeben! chmod u+rwx,g+rx-w,o+rx-w oracle ==== Log Files ==== Die Log Files liegen unter $ORACLE_HOME. cd $ORACLE_HOME ls -la *.log listener.log shutdown.log startup.log ==== Quellen ==== * https://oracle-base.com/articles/linux/linux-services-systemd