Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Pokretanje sh skripte pri bootanju sistema?

[es] :: Linux :: Pokretanje sh skripte pri bootanju sistema?

[ Pregleda: 2451 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nikol@c
tu i tamo

Član broj: 73969
Poruke: 343
79.143.169.*



+4 Profil

icon Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 14:55 - pre 171 meseci
Pozdrav,

na CentOS sistemu imam instaliran jedan server za neke mape (da ne ulazim u detalje :)), taj server se startuje pokretanjem bash skripte:

Code:

# sh /putanja/do/fajla/run.sh


Htio bih da se ova skripta pokrene pri bootanju.

Probao sam sljedece korake:

1. kopirao sam skriptu u /etc/init.d/
2. dodjelio prava za izvrsavanje
3. linkovao:
Code:

# cd /etc/rc.d/rc3.d
# ln -s /etc/init.d/run S99run

4. dodao skriptu u servise:
Code:

chkconfig --add run



I sad kada probam da startujem skriptu:
Code:

# service run start


on skriptu pokrene ali server se ne startuje, provjerio sam sve pathove u skripti, neke sam i izmjenio jer su javljali gresku ali serverov status pokazuje da nije startovan.

Iz ovog razloga nisam ni podesio da se skripta izvrsava pri bootu.

Code:

# chkconfig run on


Da li mislite da sam nesto propustio?
Hvala.

P.S.
Korake sam namjerno naveo, mozda nekome ovo i uspije :)
...ko se jednom o mlijeko opece taj i u jogurt duva...
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
93.86.111.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 15:01 - pre 171 meseci
Mozda je lakse preneti komandu u /etc/rc.local
make love - !war
 
Odgovor na temu

Srđan Pavlović
Specijalna Edukacija i Rehabilitacija MNRO
Vojvodina, Bačka Palanka

Član broj: 139340
Poruke: 5571
77.46.145.*

Sajt: www.oligofrenolog.com


+382 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 15:04 - pre 171 meseci
Citat:
on skriptu pokrene ali server se ne startuje


Pa onda je problem u tome sta je u skripti, ako si siguran da je pokrenuta skripta, ali se nesto ne izvrsava.

Ako hoces postavi skriptu ovde, mozda bude od pomoci...
 
Odgovor na temu

nikol@c
tu i tamo

Član broj: 73969
Poruke: 343
79.143.169.*



+4 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 15:08 - pre 171 meseci

<vezano za /etc/rc.local>
Hvala na brzom odgovoru, razmisljao sam o toj opciji ali nisam bio siguram da li ce to da funkcionise na CentOSu.

Da li ovo radi na svim distribucijama?
</vezano za /etc/rc.local>

I da, jos jedan mali detalj, pokretanje ove skripte ne izvrsava root user, kako mogu da podesim da to izvrsi neki npr map user:
Code:

# su map
# sh /putanja/run.sh


[Ovu poruku je menjao nikol@c dana 11.02.2010. u 16:27 GMT+1]
...ko se jednom o mlijeko opece taj i u jogurt duva...
 
Odgovor na temu

nikol@c
tu i tamo

Član broj: 73969
Poruke: 343
79.143.169.*



+4 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 15:23 - pre 171 meseci
Evo skripte:

Code:

#! /bin/sh

# chkconfig: 345 99 01
#
# Skeleton sh script suitable for starting and stopping 
# wrapped Java apps on the Solaris platform. 
#
# Make sure that PIDFILE points to the correct location,
# if you have changed the default location set in the 
# wrapper configuration file.
#

#-----------------------------------------------------------------------------
# These settings can be modified to fit the needs of your application

# Application
APP_NAME="${SERVER}"
APP_LONG_NAME="PTV xMap Server 1.8.1.1"

# Wrapper
WRAPPER_CMD="/opt/ptv/xmap/bin/xMapWrapper"
WRAPPER_CONF="/opt/ptv/xmap/conf/wrapper.conf"

# Priority at which to run the wrapper.  See "man nice" for valid priorities.
#  nice is only used if a priority is specified.
PRIORITY=

# Location of the pid file.
PIDDIR="."

# If uncommented, causes the Wrapper to be shutdown using an anchor file.
#  When launched with the 'start' command, it will also ignore all INT and
#  TERM signals.
#IGNORE_SIGNALS=true

# If specified, the Wrapper will be run as the specified user when the 'start'
#  command is passed to this script.  When running with the 'console' command
#  the current user will be used.
# IMPORTANT - Make sure that the user has the required privileges to write
#  the PID file and wrapper.log files.  Failure to be able to write the log
#  file will cause the Wrapper to exit without any way to write out an error
#  message.
# NOTE - This will set the user which is used to run the Wrapper as well as
#  the JVM and is not useful in situations where a privileged resource or
#  port needs to be allocated prior to the user being changed.
#RUN_AS_USER=

# Do not modify anything beyond this point
#-----------------------------------------------------------------------------

# Get the fully qualified path to the script
case $0 in
    /*)
        SCRIPT="$0"
        ;;
    *)
        PWD=`pwd`
        SCRIPT="$PWD/$0"
        ;;
esac

# Change spaces to ":" so the tokens can be parsed.
SCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
# Get the real path to this script, resolving any symbolic links
TOKENS=`echo $SCRIPT | sed -e 's;/; ;g'`
REALPATH=
for C in $TOKENS; do
    REALPATH="$REALPATH/$C"
    while [ -h "$REALPATH" ] ; do
        LS="`ls -ld "$REALPATH"`"
        LINK="`expr "$LS" : '.*-> \(.*\)$'`"
        if expr "$LINK" : '/.*' > /dev/null; then
            REALPATH="$LINK"
        else
            REALPATH="`dirname "$REALPATH"`""/$LINK"
        fi
    done
done
# Change ":" chars back to spaces.
REALPATH=`echo $REALPATH | sed -e 's;:; ;g'`

# Change the current directory to the location of the script
cd "`dirname "$REALPATH"`"

# Process ID
ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
PIDFILE="$PIDDIR/$APP_NAME.pid"
pid=""

# Resolve the location of the 'ps' command
PSEXE="/usr/bin/ps"
if [ ! -x $PSEXE ]
then
    PSEXE="/bin/ps"
    if [ ! -x $PSEXE ]
    then
        echo "Unable to locate 'ps'."
        echo "Please report this message along with the location of the command on your system."
        exit 1
    fi
fi

# Build the nice clause
if [ "X$PRIORITY" = "X" ]
then
    CMDNICE=""
else
    CMDNICE="nice -$PRIORITY"
fi

# Check the configured user
if [ "$RUN_AS_USER" != "ptv" ]
then
    # Resolve the location of the 'id' command
    IDEXE="/usr/xpg4/bin/id"
    if [ ! -x $IDEXE ]
    then
        IDEXE="/usr/bin/id"
        if [ ! -x $IDEXE ]
        then
            echo "Unable to locate 'id'."
            echo "Please report this message along with the location of the command on your system."
            exit 1
        fi
    fi

    if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
    then
        # Already running as the configured user.  Avoid password prompts by not calling su.
        RUN_AS_USER=""
    fi
fi

# Set Display and Library variables (Display is only needed for graphics
# servers accessing X11, such as xmap)
export DISPLAY=:0.0

# collect all directories containing shared libraries and put them
# into LD_LIBRARY_PATH to avoid unresolved symbol errors
for d in `find . -name lib`
do
    export LD_LIBRARY_PATH=$d:$LD_LIBRARY_PATH
done

getpid() {
    if [ -f $PIDFILE ]
    then
        if [ -r $PIDFILE ]
        then
            pid=`cat $PIDFILE`
            if [ "X$pid" != "X" ]
            then
                # Verify that a process with this pid is still running.
                pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
                if [ "X$pid" = "X" ]
                then
                    # This is a stale pid file.
                    rm -f $PIDFILE
                    echo "Removed stale pid file: $PIDFILE"
                fi
            fi
        else
            echo "Cannot read $PIDFILE."
            exit 1
        fi
    fi
}

testpid() {
    pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
    if [ "X$pid" = "X" ]
    then
        # Process is gone so remove the pid file.
        rm -f $PIDFILE
    fi
}

console() {
    echo "Running $APP_LONG_NAME..."
    getpid
    if [ "X$pid" = "X" ]
    then
        if [ "X$IGNORE_SIGNALS" = "X" ]
        then
            exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.pidfile=$PIDFILE
        else
            exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE
        fi
    else
        echo "$APP_LONG_NAME is already running."
        exit 1
    fi
}
 
start() {
    echo "Starting $APP_LONG_NAME..."
    getpid
    if [ "X$pid" = "X" ]
    then
        if [ "X$IGNORE_SIGNALS" = "X" ]
        then
            if [ "X$RUN_AS_USER" = "X" ]
            then
                exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.pidfile=$PIDFILE wrapper.daemonize=TRUE
            else
                su -m $RUN_AS_USER -c "exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.pidfile=$PIDFILE wrapper.daemonize=TRUE"
            fi
        else
            if [ "X$RUN_AS_USER" = "X" ]
            then
                exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE wrapper.ignore_signals=TRUE wrapper.daemonize=TRUE
            else
                su -m $RUN_AS_USER -c "exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE wrapper.ignore_signals=TRUE wrapper.daemonize=TRUE"
            fi
        fi
    else
        echo "$APP_LONG_NAME is already running."
        exit 1
    fi
}
 
stopit() {
    echo "Stopping $APP_LONG_NAME..."
    getpid
    if [ "X$pid" = "X" ]
    then
        echo "$APP_LONG_NAME was not running."
    else
        if [ "X$IGNORE_SIGNALS" = "X" ]
        then
            # Running so try to stop it.
            kill $pid
            if [ $? -ne 0 ]
            then
                # An explanation for the failure should have been given
                echo "Unable to stop $APP_LONG_NAME."
                exit 1
            fi
        else
            rm -f $ANCHORFILE
            if [ -f $ANCHORFILE ]
            then
                # An explanation for the failure should have been given
                echo "Unable to stop $APP_LONG_NAME."
                exit 1
            fi
        fi

        # We can not predict how long it will take for the wrapper to
        #  actually stop as it depends on settings in wrapper.conf.
        #  Loop until it does.
        savepid=$pid
        CNT=0
        TOTCNT=0
        while [ "X$pid" != "X" ]
        do
            # Loop for up to 5 minutes
            if [ "$TOTCNT" -lt "300" ]
            then
                if [ "$CNT" -lt "5" ]
                then
                    CNT=`expr $CNT + 1`
                else
                    echo "Waiting for $APP_LONG_NAME to exit..."
                    CNT=0
                fi
                TOTCNT=`expr $TOTCNT + 1`

                sleep 1

                testpid
            else
                pid=
            fi
        done

        pid=$savepid
        testpid
        if [ "X$pid" != "X" ]
        then
            echo "Timed out waiting for $APP_LONG_NAME to exit."
            echo "  Attempting a forced exit..."
            kill -9 $pid
        fi

        pid=$savepid
        testpid
        if [ "X$pid" != "X" ]
        then
            echo "Failed to stop $APP_LONG_NAME."
            exit 1
        else
            echo "Stopped $APP_LONG_NAME."
        fi
    fi
}

status() {
    getpid
    if [ "X$pid" = "X" ]
    then
        echo "$APP_LONG_NAME is not running."
        exit 1
    else
        echo "$APP_LONG_NAME is running ($pid)."
        exit 0
    fi
}

dump() {
    echo "Dumping $APP_LONG_NAME..."
    getpid
    if [ "X$pid" = "X" ]
    then
        echo "$APP_LONG_NAME was not running."

    else
        kill -3 $pid

        if [ $? -ne 0 ]
        then
            echo "Failed to dump $APP_LONG_NAME."
            exit 1
        else
            echo "Dumped $APP_LONG_NAME."
        fi
    fi
}

case "$1" in

    'console')
        console
        ;;

    'start')
        start
        ;;

    'stop')
        stopit
        ;;

    'restart')
        stopit
        start
        ;;

    'status')
        status
        ;;

    'dump')
        dump
        ;;

    *)
        echo "Usage: $0 { console | start | stop | restart | status | dump }"
        exit 1
        ;;
esac

exit 0





nadam se da ovo nije previse koda. Poenta je da pri startovanju on ispise echo da je server startovan, ali u stvari nije :).
...ko se jednom o mlijeko opece taj i u jogurt duva...
 
Odgovor na temu

combuster
Ivan Bulatovic
Kraljevo

Član broj: 151351
Poruke: 4563
93.86.111.*

Sajt: www.linuxsrbija.org


+104 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 16:09 - pre 171 meseci
Cekaj jel to ovo? http://wrapper.tanukisoftware.org/doc/english/download.jsp

Koliko sam ja razumeo ovo nije nikakav daemon niti servis, ovo je samo wrapper za java aplikacije pomocu koje pokreces tu tvoju aplikaciju. Ako je to tako tj koristis ga za samo jednu aplikaciju onda ga je kao user vrlo lako pokrenuti odmah po login-u, ili u tvom home-u u .bashrc-u ili ako hoces globalno da vazi za sve usere u /etc/profile


make love - !war
 
Odgovor na temu

maksvel

Moderator
Član broj: 107376
Poruke: 2417

Jabber: maksvel
Sajt: maksvel.in.rs


+161 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?11.02.2010. u 16:14 - pre 171 meseci
^To, a ima i ova simptomatična napomena:
Citat:

# IMPORTANT - Make sure that the user has the required privileges to write
# the PID file and wrapper.log files. Failure to be able to write the log
# file will cause the Wrapper to exit without any way to write out an error
# message.

A kao korisnik map, možeš i iz rc.d da pokreneš skript sa
su -map -c /putanja/skript.sh
A možda ti to i ne treba, ako odkomentarišeš RUN_AS_USER= i staviš map-a.

[Ovu poruku je menjao maksvel dana 11.02.2010. u 17:35 GMT+1]
 
Odgovor na temu

nikol@c
tu i tamo

Član broj: 73969
Poruke: 343
79.143.169.*



+4 Profil

icon Re: Pokretanje sh skripte pri bootanju sistema?12.02.2010. u 09:35 - pre 171 meseci
Htio bih da mi se skripta izvrsi nakon podizanja svih servisa prije logovanja, dakle u /etc/rc.d/rc.local dodao sam komandu za izvrsavanje skripte, ali nakoon restarta racunara zeljeni server nije startovan. Komanda je ista kao i ona koju kucam u konzoli.
...ko se jednom o mlijeko opece taj i u jogurt duva...
 
Odgovor na temu

[es] :: Linux :: Pokretanje sh skripte pri bootanju sistema?

[ Pregleda: 2451 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.