<div dir="ltr">Here's a skeleton I wrote:<div><br></div><div>```</div><div><div>#!/bin/bash</div><div>#</div><div># Skeleton service start-stop script</div><div>#</div><div># chkconfig: 345 85 15</div><div># description: Created via a generic script. It should be edited.</div><div>#</div><div># Script version = 0.1-2014-01-16</div><div> </div><div># Set this to the name of the service. For example, if this script will</div><div># manage the "foobar" service, set this to "foobar". Note: you can create</div><div># a "/etc/sysconfig/foobar" file and this service script will source it. So,</div><div># if you need to define any environment variables for the application, define</div><div># them there (using `export` as necessary).</div><div>APPNAME="foobar"</div><div> </div><div># Set this to the full path of the binary/script to run.</div><div>APPBINARY=/usr/local/bin/foobar</div><div> </div><div># Specify arguments to be passed to the program on startup via this variable.</div><div># For example, if "foobar" has a "-pidfile" argument, you could do:</div><div># `APPARGUMENTS="-pidfile /var/run/foobar.pid"`</div><div>APPARGUMENTS=</div><div> </div><div># Set this to the command necessary to stop the service. For example, if the</div><div># "foobar" service must be shut down with `foobar -stop` then set this to</div><div># "foobar -stop"</div><div>APPSTOPCMD="${APPBINARY} -stop"</div><div> </div><div># Set this to the user that the application will run under. This script</div><div># _will not_ run applications as root. Thus, this variable _must_ be set to</div><div># a valid user than can run the application in question.</div><div>USER="auser"</div><div> </div><div># Set this to the name of a function defined in /etc/sysconfig/${APPNAME}. This</div><div># function will be called after `service ${APPNAME} start` has completed.</div><div>STARTUP_CALLBACK=</div><div> </div><div># Set this to the name of a function defined in /etc/sysconfig/${APPNAME}. This</div><div># function will be called after `service ${APPNAME} stop` has completed. You can</div><div># use this feature to run any special cleanup operation your application might</div><div># need (i.e. any shit Ellucian apps leave behind).</div><div>SHUTDOWN_CALLBACK=</div><div> </div><div>source /etc/init.d/functions</div><div> </div><div>if [ -r /etc/sysconfig/${APPNAME} ]; then</div><div> source /etc/sysconfig/${APPNAME}</div><div>fi</div><div> </div><div>LOCAL_PIDFILE=/var/run/${APPNAME}_service.pid</div><div> </div><div>function start_service {</div><div> echo -n "Starting ${APPNAME}: "</div><div> status -p ${LOCAL_PIDFILE} ${APPNAME} > /dev/null && failure && exit</div><div> </div><div> daemon --pidfile=${LOCAL_PIDFILE} --user=${USER} ${APPBINARY} ${APPARGUMENTS}</div><div> ${STARTUP_CALLBACK} 2>&1 > /dev/null</div><div> echo</div><div>}</div><div> </div><div>function stop_service {</div><div> echo -n "Stopping ${APPNAME}: "</div><div> status -p ${LOCAL_PIDFILE} ${APPNAME} > /dev/null</div><div> </div><div> if [ ! $? -eq 0 ]; then</div><div> failure</div><div> echo</div><div> exit</div><div> fi</div><div> </div><div> ${APPSTOPCMD}</div><div> killproc -p ${LOCAL_PIDFILE} ${APPBINARY}</div><div> </div><div> ${SHUTDOWN_CALLBACK} 2>&1 > /dev/null</div><div> echo</div><div>}</div><div> </div><div>case "$1" in</div><div> start)</div><div> start_service</div><div> ;;</div><div> stop)</div><div> stop_service</div><div> ;;</div><div> restart)</div><div> stop_server</div><div> start_server</div><div> ;;</div><div> status)</div><div> status -p ${LOCAL_PIDFILE} ${APPNAME}</div><div> ;;</div><div> *)</div><div> echo "Usage: $0 {start|stop|restart|status}"</div><div> exit 1</div><div> ;;</div><div>esac</div></div><div>```</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 17, 2015 at 11:13 AM, Todor Fassl <span dir="ltr"><<a href="mailto:fassl.tod@gmail.com" target="_blank">fassl.tod@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
______________________________<u></u>_________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org" target="_blank">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/<u></u>listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/<u></u>listinfo</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>James Sumners<br><a href="http://james.sumners.info/" target="_blank">http://james.sumners.info/</a> (technical profile)</div><div><a href="http://jrfom.com/" target="_blank">http://jrfom.com/</a> (personal site)</div><div><a href="http://haplo.bandcamp.com/" target="_blank">http://haplo.bandcamp.com/</a> (band page)</div></div></div></div></div>
</div>