0

This question already has an answer here:

I wrote a java application, want to register it as a service, so wrote a bash script in /etc/init.d/. Here is the script:

#!/bin/sh
#
# chkconfig: 345 50 83
#
### BEGIN INIT INFO
# Short description: Trigger Beamer on system startup
# Description: Trigger blupay beamer on system start up
### END INIT INFO

#Source function library
. /etc/rc.d/init.d/functions

#targets beamer config file
if [ -f /etc/sysconfig/beamer ]; then
    /etc/sysconfig/beamer
fi


#start httpd in the C locale by default.
BEAMER_LANG=${BEAMER_LANG-"java"}

# Path to beamer.
beamer=/home/blupayss/Desktop/BeamerApp
prog=beamer
pidfile=${PIDFILE-/var/run/httpd/beamer.pid}
lockfile=${LOCKFILE-/var/lock/subsys/beamer}
RETVAL=0

start() { 
    echo -n "starting $prog"
    LANG=${BEAMER_LANG}
    RETVAL=$?
    java -jar ${beamer}/Beamer.jar
    echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d  $beamer
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$BEAMER_LANG $beamer $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $beamer due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $beamer -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"beamer shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $beamer
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  force-reload|reload)
        reload
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart||force-reload|reload|status}"
        RETVAL=2
esac

exit $RETVAL

When I execute it as sudo service beamer start, then java applicaition gets launched successfully. However it returns an error:
/etc/sysconfig/beamer: Permission denied
How can I make my script access /etc/sysconfig/beamer?

marked as duplicate by Mark Kirby, Videonauth, Ravan, Pilot6, David Foerster May 28 '16 at 9:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Do you really want to execute /etc/sysconfig/beamer? Considering the directory name and position in the script I suppose you actually want to source it. – David Foerster May 28 '16 at 9:12
  • FWIW I voted to close as unclear not as duplicate. – David Foerster May 28 '16 at 9:12
  • 1
    Sourcing /etc/sysconfig/beamer fixed it, thank you – Ajay Kulkarni May 30 '16 at 4:57