[ale] creating an init.d script

Scott Plante splante at insightsys.com
Tue Feb 17 12:40:40 EST 2015


James' script is a good example. The basic idea is that you need a script that takes a parameter "start" to start the service and "stop" to stop it. You usually want a "status" and "restart" to tell you if it's up and restart it. There's often a "condrestart" or I think they're moving to "try-restart" that only restarts if the service is already running. You can add your own if there are some specific things you need--like a database might include an "init" for creating a blank default database (like Postgresql does or used to do). If you call the script with no params, or bad params, it's customary to print a usage message. 

A lot of service binaries don't provide a way to stop themselves, so James' script uses a common method of creating a PID file with the process ID, and using that to kill the process on a stop. From a quick Googling, it looks like your service doesn't want to be killed, and provides a command to stop itself. That's fine--just replace the stop logic in the script with your own stop command, such as: 

lmutil lmdown -q -c license_file_name 
The PID file may be useful for implementing the "status" unless lmutil has that function too, that you can just call. Also, you might follow the above command with a kill in your script if the above doesn't work for some reason, but then you're just getting fancy! 


The only other thing you probably need is some specially formatted comments. They are used by chkconfig and related commands for adding the service and making sure it gets started and stopped in the right spot. Here is a doc with some more info on the comment format. 


http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html 


Scott 
----- Original Message -----

From: "Todor Fassl" <fassl.tod at gmail.com> 
To: "Atlanta Linux Enthusiasts" <ale at ale.org> 
Sent: Tuesday, February 17, 2015 11:13:00 AM 
Subject: [ale] creating an init.d script 

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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20150217/e93e3da9/attachment.html>


More information about the Ale mailing list