LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Initscript (https://www.linuxquestions.org/questions/programming-9/initscript-376320/)

shahrokhnikou 10-24-2005 05:41 AM

Initscript
 
Can you please lead me, How can I write my own initscript in linux?
I'm very very new in Linux.


Regards,

Keruskerfuerst 10-24-2005 06:11 AM

Hello!

1. You have to choose your interpreter: usually sh or bash.
->#!/bin/sh or #!/bin/bash

2. A good choice is to have a look in the booscripts placed in /etc/init.d/rcx.d (x=1,2,3,4,5).

Greetings

shahrokhnikou 10-24-2005 07:06 AM

Hi again,

I've looked at /ect/rc3.d scripts, But my problem is I don't know how to write my own script for one my program to run (Weblogic admin server). Can you help in this regards?

Thanx,
Shahrokh

bathory 10-24-2005 08:14 AM

You can just create a symlink, line this:
Code:

ln -s /path/to/startWebLogic.sh /etc/rc3.d/S90startWebLogic

shahrokhnikou 10-24-2005 08:35 AM

Hi,
Thank you for your reply. But you know what? If I create a symlink it won't start adminserver, and problem is that on that script I have no start or stop, That's why I think I need to write a new script for it which I have no idea how to do that, Once I tried to use to command in order to run it, But it failed
and here is the original script from startWebLogic.sh
===========================================

#!/bin/sh

# WARNING: This file is created by the Configuration Wizard.
# Any changes to this script may be lost when adding extensions to this configur
ation.

# *************************************************************************
# This script is used to start WebLogic Server for the domain in the
# current working directory. This script simply sets the SERVER_NAME
# variable and starts server.
#
# To create your own start script for your domain, all you need to set is
# SERVER_NAME, then starts the server.
#
# Other variables that startWLS takes are:
#
# WLS_USER - cleartext user for server startup
# WLS_PW - cleartext password for server startup
# PRODUCTION_MODE - true for production mode servers, false for
# development mode
# JAVA_OPTIONS - Java command-line options for running the server. (These
# will be tagged on to the end of the JAVA_VM and MEM_ARGS)
# JAVA_VM - The java arg specifying the VM to run. (i.e. -server,
# -hotspot, etc.)
# MEM_ARGS - The variable to override the standard memory arguments
# passed to java
#
# For additional information, refer to the WebLogic Server Administration
# Console Online Help(http://e-docs.bea.com/wls/docs81/Con.../startstop.htm
l)
# *************************************************************************

# Initialize the common environment.

WL_HOME="/opt/bea/weblogic81"

PRODUCTION_MODE=""

JAVA_VENDOR="BEA"

JAVA_HOME="/opt/bea/jrockit81sp4_142_05"

# Call commEnv here AFTER setting the java_vendor to get common environmental se
ttings.

. ${WL_HOME}/common/bin/commEnv.sh

# Set SERVER_NAME to the name of the server you wish to start up.

SERVER_NAME="TunteellinenServeri"

CLASSPATH="${WEBLOGIC_CLASSPATH}:${POINTBASE_CLASSPATH}:${JAVA_HOME}/jre/lib/rt.jar:${WL_HOME}/server/lib/webservices.jar:${CLASSPATH}"
export CLASSPATH

# Call WebLogic Server

echo "."
echo "CLASSPATH=${CLASSPATH}"
echo "."
echo "PATH=${PATH}"
echo "."
echo "***************************************************"
echo "* To start WebLogic Server, use a username and *"
echo "* password assigned to an admin-level user. For *"
echo "* server administration, use the WebLogic Server *"
echo "* console at http://[hostname]:[port]/console *"
echo "***************************************************"

${JAVA_HOME}/bin/java ${JAVA_VM} ${MEM_ARGS} ${JAVA_OPTIONS} -Dweblogic.Name=${SERVER_NAME} -Dweblogic.ProductionModeEnabled=${PRODUCTION_MODE} -Djava.securi
ty.policy="${WL_HOME}/server/lib/weblogic.policy" weblogic.Server

bathory 10-24-2005 08:51 AM

OK my mistake. It should be:
Code:

ln -s /path/to/startWebLogic.sh /etc/init.d/rc3.d/S90startWebLogic
It does not need the "start" and "stop" options.

shahrokhnikou 10-24-2005 12:13 PM

Hi,

I did exactly what you said.
I made a symlink to


ln -s /opt/bea/domains/admin/startWebLogic.sh /etc/init.d/rc3.d/S90startWebLogic

And the I rebooted my server, But When I check my adminserver was not running. I did get my server run when I entered manually this command:

./startWebLogic.sh


What do you think, Do you have any suggestion?

Regards,
Shahrokh

sundialsvcs 10-24-2005 03:07 PM

What you need to do is, "when in Rome, do as the Romans do." That means...

(1) Look at the existing symbolic-links in /etc/rc.d/rc?.d and note where the scripts are located. Put your script in the same place, say /etc/init.d.

(2) Look at the existing initscripts on your system. Pick one and copy it, choosing an appropriate new name, keeping the same naming convention that they used. Observe the permissions that are set upon the file, and who owns it. Do the same.

(3) Strip the existing text out of the copied script and paste your existing logic into it, perhaps as a function at the top of the script. Follow the existing pattern of expecting to receive a start, stop, status parameter, and of dealing with unexpected parameters in a sensible way.

(4) Now you should be able to start or stop the service, i.e. test it all out, by using an existing command such as /sbin/service servicename start. This basically invokes the appropriate initscript.

(5) Be sure to document all of what you are doing! Put comments in your code, right now as you write it, so that you or someone else can easily remember what you did, when you did it, and why you did it.

crabboy 10-24-2005 03:23 PM

Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php

http://www.linuxquestions.org/questi...hreadid=376302


All times are GMT -5. The time now is 12:42 PM.