[ale] creating an init.d script

James Sumners james.sumners at gmail.com
Tue Feb 17 11:56:30 EST 2015


Here's a skeleton I wrote:

```
#!/bin/bash
#
# Skeleton service start-stop script
#
# chkconfig: 345 85 15
# description: Created via a generic script. It should be edited.
#
# Script version = 0.1-2014-01-16

# Set this to the name of the service. For example, if this script will
# manage the "foobar" service, set this to "foobar". Note: you can create
# a "/etc/sysconfig/foobar" file and this service script will source it. So,
# if you need to define any environment variables for the application,
define
# them there (using `export` as necessary).
APPNAME="foobar"

# Set this to the full path of the binary/script to run.
APPBINARY=/usr/local/bin/foobar

# Specify arguments to be passed to the program on startup via this
variable.
# For example, if "foobar" has a "-pidfile" argument, you could do:
# `APPARGUMENTS="-pidfile /var/run/foobar.pid"`
APPARGUMENTS=

# Set this to the command necessary to stop the service. For example, if the
# "foobar" service must be shut down with `foobar -stop` then set this to
# "foobar -stop"
APPSTOPCMD="${APPBINARY} -stop"

# Set this to the user that the application will run under. This script
# _will not_ run applications as root. Thus, this variable _must_ be set to
# a valid user than can run the application in question.
USER="auser"

# Set this to the name of a function defined in /etc/sysconfig/${APPNAME}.
This
# function will be called after `service ${APPNAME} start` has completed.
STARTUP_CALLBACK=

# Set this to the name of a function defined in /etc/sysconfig/${APPNAME}.
This
# function will be called after `service ${APPNAME} stop` has completed.
You can
# use this feature to run any special cleanup operation your application
might
# need (i.e. any shit Ellucian apps leave behind).
SHUTDOWN_CALLBACK=

source /etc/init.d/functions

if [ -r /etc/sysconfig/${APPNAME} ]; then
  source /etc/sysconfig/${APPNAME}
fi

LOCAL_PIDFILE=/var/run/${APPNAME}_service.pid

function start_service {
  echo -n "Starting ${APPNAME}: "
  status -p ${LOCAL_PIDFILE} ${APPNAME} > /dev/null && failure && exit

  daemon --pidfile=${LOCAL_PIDFILE} --user=${USER} ${APPBINARY}
${APPARGUMENTS}
  ${STARTUP_CALLBACK} 2>&1 > /dev/null
  echo
}

function stop_service {
  echo -n "Stopping ${APPNAME}: "
  status -p ${LOCAL_PIDFILE} ${APPNAME} > /dev/null

  if [ ! $? -eq 0 ]; then
    failure
    echo
    exit
  fi

  ${APPSTOPCMD}
  killproc -p ${LOCAL_PIDFILE} ${APPBINARY}

  ${SHUTDOWN_CALLBACK} 2>&1 > /dev/null
  echo
}

case "$1" in
  start)
    start_service
    ;;
  stop)
    stop_service
    ;;
  restart)
    stop_server
    start_server
    ;;
  status)
    status -p ${LOCAL_PIDFILE} ${APPNAME}
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac
```

On Tue, Feb 17, 2015 at 11:13 AM, Todor Fassl <fassl.tod at gmail.com> wrote:

> My department runs a FlexLM license server for 2 mathematical programs,
> maple and matlab. I want to write some init.d scripts to restart the
> license server instances if we reboot the license server. Right now, I have
> to login and type the command. I can easily put it in a script but I want
> to do it right.
>
> I googled for examples but they all seem so complicated. I tried copying
> an existing script and modifying it (apprort) but after spending, I dunno,
> 10 minutes or so modifying it, I found it wasn't suitable as an example.
>
> What's a good generic init.d script to start with? Any good tutorials you
> are aware of? I don't want to spend all day learning how to write lsb
> scripts. An hour or 2 maybe but not all day. If I can't learn how to do it
> right in an hour or so, I'm just going to quick-and-dirty it.
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>



-- 
James Sumners
http://james.sumners.info/ (technical profile)
http://jrfom.com/ (personal site)
http://haplo.bandcamp.com/ (band page)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20150217/58280710/attachment.html>


More information about the Ale mailing list