1827703 Members
2853 Online
109967 Solutions
New Discussion

user defined service

 
Tonatiuh
Super Advisor

user defined service

Red Hat Enterprise Linux 4

I have added a "user defined service" named orainfra. I created in /etc/init.d/orainfra script to startup and stop some application services.

I have added the service with:

chkconfig --add orainfra

[root@svr04 ~]# chkconfig --list |grep orainfra
orainfra 0:off 1:off 2:off 3:on 4:off 5:on 6:off

After this it added the corresponding links in rcX.d correct levels.

This line (into the script) defines the levels to run:

# chkconfig: 35 98 11

At the start of the server I can see that is trying with my service (orainfra) but the service (script) does not executes succesfully. AT startup it does not shows any messages about the succesfull or not of the service execution.

Eventhough once started the server, if I execute manually the service (orainfra) it wors fine:

service orainfra start
or
service orainfra stop

Any idea about why it is not working at the starting up of the server?
24 REPLIES 24
Ivan Ferreira
Honored Contributor

Re: user defined service

Check your database log files. Where did you configured the kernel parameters for the database? If /etc/sysctl.conf is right, if /etc/rc.local is wrong and database may not start because the kernel parameters are not configured yet.

Also, check your environment variables definition. Ensure that the scripts has all variables needed to sucessfully start the database.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Tonatiuh
Super Advisor

Re: user defined service






Hello Ivan,

The services that the script should startup automatically does not generate any log file. This is, the startup of the services is not really executed I think.

I think that all environment variables are correct because when I execute the "service orainfra start" with root user, everything works OK.

Any other idea?
Ivan Ferreira
Honored Contributor

Re: user defined service

Redirect your script output to a log file, the start section, check the log file to verify what is happening.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Stuart Browne
Honored Contributor

Re: user defined service

The environment during the boot phase isn't the same as after it's booted and you've logged in.

Things to make sure of:

- All executables you're calling in your script are either fully-pathed, or you've re-defined the PATH at the start of your script.

- The hash-bang (#!) is set correctly.

- The script executes fine with a hash-bang of '#!/bin/sh'.

If all of this is ok, do you have any objections to attaching the script to a post so we can have a look through it ?
One long-haired git at your service...
Tonatiuh
Super Advisor

Re: user defined service

I have attached the scripts.

The /home/oracle/orainfra.log is generated OK.

The /home/oracle/dbstart1.log is generated empty (0 bytes)

The /home/oracle/dbstart2.log is not generated. This is the line 'echo ...' in script /home/oracle/scripts/dbstart does not executes, so that I think the script is not really executed from /etc/init.d/orainfra

Ivan Ferreira
Honored Contributor

Re: user defined service

Use the following redirection:

>> /home/oracle/orainfra.log 2>>&1

> /home/oracle/dbstart1.log 2>&1
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Tonatiuh
Super Advisor

Re: user defined service

The 2>>&1 redirection generates no logfile. This is, it does not send anything to logfile.
Stuart Browne
Honored Contributor

Re: user defined service

'2>>&1' isn't right, it should just be '2>&1'. The appending is handled by file-descriptor 1's redirection ('>> /home/...').

That being said, it all looks good. Things to double-check:

Ensure that the appropriate log files are either pre-created and owned by the appropriate users ('oracle' for all logs in this case), and that the user has enough permissions to create files in '/home/oracle/'.

Also ensure that script '/home/oracle/scripts/dbstart' is executable (+x). Given that you say this works if you run it out of the start-up routines however, I'm picking it is, but can't hurt to be doubly-sure.

It all looks good though. Odd.
One long-haired git at your service...
Ivan Ferreira
Honored Contributor

Re: user defined service

Yes, it was in a hurry, the real command should look like:

su - $ORA_OWNER -c "$USR_HOME/scripts/dbstart" >> /home/oracle/dbstart1.log 2>&1
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Tonatiuh
Super Advisor

Re: user defined service

I am afraid that the 2>&1 does not generate logfile.

I have double checkd all mentioned.

Any other idea?
Ivan Ferreira
Honored Contributor

Re: user defined service

Try removing the - from the su (su oracle -c), add to dbstart script the sourcing of the user profile. I remember an error like "not a tty" when using "su -" from startup scripts.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Tonatiuh
Super Advisor

Re: user defined service

I have removed the "-c" with same result.

How can I add to dbstart script the sourcing of the user profile?
Ivan Ferreira
Honored Contributor

Re: user defined service

Use dot-space-path_to_profile, like this:

. /home/oracle/.bash_profile

You can also use

source /home/oracle/.bash_profile
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Tonatiuh
Super Advisor

Re: user defined service

I did it with ". /home/oracle/.bash_profile" without better result.

I think the switch to oracle user (su - oracle) is the thing that is not working.

Any idea?
Stuart Browne
Honored Contributor

Re: user defined service

If that were the case, you'd be getting an error when you 'su' which would be visible.

Change the '#!/bin/bash' in both scripts to be '#!/bin/bash -x'.

This is for debugging, and will make things very noisy when they run. You should be able to the shell list every line of the script one-by-one, so you can see if it's actually getting into the 'dbstart' routine (I agree it doesn't look like it is). Hopefully, it'll spit something out that makes sense.
One long-haired git at your service...
Tonatiuh
Super Advisor

Re: user defined service

The "-x" option shows line-by-line the execution of the script but only when it is exeucted manually (after startup process finished).

No difference at startup execution of the script.
Tonatiuh
Super Advisor

Re: user defined service

The "-x" option shows line-by-line the execution of the script but only when it is exeucted manually (after startup process finished).

No difference in execution of the script at startup time.
Tonatiuh
Super Advisor

Re: user defined service

I have modified the orainfra script (service) to execute all oracle commandos directly with oracle user and in that case all es executed (with wrong results because it must be execute with oracle, but it is execute).

But all I tray to execute wiht "su - oracle..." is not executed.

Stuart Browne
Honored Contributor

Re: user defined service

That's not right!

Any echo's that the start-routine's do should go to the console, so should be seen during the boot-proces.

What does the output of this look like:

ls -al /etc/{rc?,init}.d/*orainfra

Basically, just manually confirm these links point to the right spots.
One long-haired git at your service...
Tonatiuh
Super Advisor

Re: user defined service

The console show that is running my service (at startup) and then it shows a blank screen and does not respond (in the console).

I can work through a ssh session.
Stuart Browne
Honored Contributor

Re: user defined service

What was the output from that 'ls' command?

And it's not giving you a login on the console ?!? I'd consider that a greater issue. Is it stopping/blanking when it gets to this startup routine, or before it?
One long-haired git at your service...
Tonatiuh
Super Advisor

Re: user defined service

[root@svr04 ~]# ls -al /etc/init.d/*orainfra
-rwxr-xr-x 1 root root 996 Mar 23 17:08 /etc/init.d/orainfra
[root@svr04 ~]# ls -al /etc/rc5.d/*orainfra
lrwxrwxrwx 1 root root 18 Mar 23 13:26 /etc/rc5.d/S98orainfra -> ../init.d/orainfra
Stuart Browne
Honored Contributor

Re: user defined service

Ok, after the boot, what do /var/log/boot.log, 'dmesg' and /var/log/messages look like?
One long-haired git at your service...
Ivan Ferreira
Honored Contributor

Re: user defined service

I believe that the key is the logging. Try with the minimally modified version of the scripts attached. I would like the orainfra.log, dbstart1.log, dbstart2.log.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?