Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #172 (closed enhancement: fixed)

Opened 9 years ago

Last modified 4 years ago

[RESOURCE] A LSB-compliant initscript for Linux

Reported by: Jorge Godoy <jgodoy@…> Owned by: Chris Arndt
Priority: normal Milestone: 1.0.x bugfix
Component: Documentation Version:
Severity: normal Keywords: reviewed
Cc: ezio2@…

Description

This adds a LSB compliant initscript that can be used on Linux. Only two lines need to be modified on each project. Using this as a template and filling it when creating a new project isn't all that hard.

Two informations need to be filled up:

  • deployment place -> where the files will be installed at the production server
  • project name -> what is the project's name

This starts the server in production mode.

Attachments

initscript-example Download (3.1 KB) - added by Jorge Godoy <jgodoy@…> 9 years ago.
LSB compliant initscript
initscript.project Download (4.0 KB) - added by godoy 9 years ago.
An improved initscript that has the functions: start, stop, status and restart.
rc.status Download (8.3 KB) - added by godoy 9 years ago.
SuSE's rc_* functions…
lsb-initscript.project Download (3.2 KB) - added by godoy 9 years ago.
LSB-compliant initscript

Change History

Changed 9 years ago by Jorge Godoy <jgodoy@…>

LSB compliant initscript

comment:1 Changed 9 years ago by SuperJared <jared.kuolt@…>

Should this be part of the distribution or docs...? Both?

comment:2 Changed 9 years ago by bloodearnest@…

  • Cc jgodoy@… added

Some thoughts;

  • I think start_daemon is the new name for startproc in LSB 1.3. But then, it's not actually being used here as far is I can see.
  • On Fedora 4/Debian Unstable (all I have to hand) the lsb init functions are not available by default. However, they're in /lib/lsb/init-functions to source if needed, which some scripts seem to do. I presume this is defined in the LSB.
  • /etc/rc.status functions *seems* to be Suse specific (I have never used Suse) That being said, I'm not sure of a clean way to return the appropriate retvals.

HTH

comment:3 Changed 9 years ago by godoy

I've made a few changes since I wrote this. I'll attach a new version and then see if I can address your comments.

Changed 9 years ago by godoy

An improved initscript that has the functions: start, stop, status and restart.

comment:4 Changed 9 years ago by godoy

  • Summary changed from A LSB compliant initscript for Linux to An initscript for Linux

Changing the title since this is not LSB compliant anymore... I'll try making it compliant and working...

Changed 9 years ago by godoy

SuSE's rc_* functions...

comment:5 Changed 9 years ago by godoy

Even though there's no explicit license on the rc.status attachment, it is said to be GPL in the package. I'm uploading it here to help people have a fast start until I post an LSB-only script.

godoy@jupiter ~ % rpm -qf /etc/rc.status aaa_base-10.0-28 godoy@jupiter ~ % rpm -qi aaa_base Name : aaa_base Relocations: (not relocatable) Version : 10.0 Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany Release : 28 Build Date: Sex 09 Set 2005 13:10:13 BRT Install date: Seg 31 Out 2005 19:17:55 BRST Build Host: orff.suse.de Group : System/Fhs? Source RPM: aaa_base-10.0-28.src.rpm Size : 305578 License: GPL Signature : DSA/SHA1, Sex 09 Set 2005 13:35:58 BRT, Key ID a84edae89c800aca Packager :  http://www.suse.de/feedback Summary : SuSE Linux base package Description : This package installs several important configuration files. Central scripts like SuSEconfig are also in this package.

Authors:


Werner Fink <werner@…> Rüdiger Oertel <ro@…> Burchard Steinbild Florian La Roch Martin Scherbaum

Distribution: SUSE LINUX 10.0 (i586)

comment:6 Changed 9 years ago by godoy

(Fixing last post)

godoy@jupiter ~ % rpm -qf /etc/rc.status 
aaa_base-10.0-28
godoy@jupiter ~ % rpm -qi aaa_base
Name        : aaa_base                     Relocations: (not relocatable)
Version     : 10.0                              Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany
Release     : 28                            Build Date: Sex 09 Set 2005 13:10:13 BRT
Install date: Seg 31 Out 2005 19:17:55 BRST      Build Host: orff.suse.de
Group       : System/Fhs                    Source RPM: aaa_base-10.0-28.src.rpm
Size        : 305578                           License: GPL
Signature   : DSA/SHA1, Sex 09 Set 2005 13:35:58 BRT, Key ID a84edae89c800aca
Packager    : http://www.suse.de/feedback
Summary     : SuSE Linux base package
Description :
This package installs several important configuration files. Central
scripts like SuSEconfig are also in this package.



Authors:
--------
    Werner Fink <werner@suse.de>
    Rüdiger Oertel <ro@suse.de>
    Burchard Steinbild
    Florian La Roch
    Martin Scherbaum
Distribution: SUSE LINUX 10.0 (i586)

comment:7 Changed 9 years ago by godoy

  • Summary changed from An initscript for Linux to An LSB-compliant initscript for Linux

OK, now I believe this should work on all LSB-compliant systems since I'm only using LSB functions. :-) If not, please, point the errors to me and I'll try fixing it.

Changed 9 years ago by godoy

LSB-compliant initscript

comment:8 Changed 9 years ago by godoy

  • Summary changed from An LSB-compliant initscript for Linux to A LSB-compliant initscript for Linux

comment:9 Changed 9 years ago by godoy

  • Cc jgodoy@… removed
  • Summary changed from A LSB-compliant initscript for Linux to [RESOURCE] A LSB-compliant initscript for Linux

comment:10 Changed 9 years ago by kevin

  • Milestone set to 0.9

comment:11 Changed 8 years ago by jorge.vargas

  • Keywords reviewed added
  • Cc jgodoy@… added
  • Component changed from Deployment to Docs
  • Milestone changed from 0.9 to 1.0

why not provide this as a quickstart template, other then that I don't see how this could be distributed with TG.

I'm moving this to docs because I think a little howto is necessary, maybe pack it up and get it to the cheeseshop?

comment:12 Changed 8 years ago by ezio

A strange (for me!) thing happens: when I start the application, using command line or the init script, i have two process (running fedora4, tg trunk):

# ./start-astcdr.py &
[1] 13868
# ps -e -o user,pid,comm,cmd | grep astcdr
root     13868 start-astcdr.py /usr/bin/python ./start-astcdr.py
root     13869 python          /usr/bin/python ./start-astcdr.py
# kill -2 13868
# ps -e -o user,pid,comm,cmd | grep astcdr
root     13869 python          /usr/bin/python ./start-astcdr.py

To stop the application I've to kill them both. The same thing happens in the initscript and killing the process saved with echo $! > $PIDFILE

Now repeat, looking at the process group (pgid)

# ./start-astcdr.py &
[1] 14041
# ps -e -o user,pid,pgid,comm,cmd | grep astcdr
root     14041 14041 start-astcdr.py /usr/bin/python ./start-astcdr.py
root     14042 14041 python          /usr/bin/python ./start-astcdr.py

They have the same pgid, 14041. From kill man page a hypen (-) before pid means all process in the group:

# kill -2 -14041

works. Now with the init script:

# ./tg-astcdr start
Starting astcdr                                            [  OK  ]
# ps -e -o user,pid,pgid,comm,cmd | grep astcdr
root     14140 14137 start-astcdr.py /usr/bin/python /home/ezio/web_works/astcdr/start-astcdr.py /home/ezio/web_works/astcdr/dev.cfg
root     14142 14137 python          /usr/bin/python /home/ezio/web_works/astcdr/start-astcdr.py /home/ezio/web_works/astcdr/dev.cfg

The pgid number is 14137, where came out this number? Where can I find this number? Happens only to me???

comment:13 Changed 8 years ago by ezio

  • Cc jgodoy@… added; jgodoy@… removed

comment:14 Changed 8 years ago by godoy

  • Cc ezio2@… added; jgodoy@… removed

It doesn't happen to me. Neither with the start script nor with the initscript I put above.

comment:15 Changed 8 years ago by alberto

  • Milestone changed from 1.0 to 1.1

comment:16 Changed 8 years ago by khorn

Seems like this init script won't work on any redhat/fedora/centos distro since, AFAICT, none of them have the "checkproc" or "startproc" functions. Gentoo (at least my box) also seems to be missing these functions.

Seems very SUSE-centric. Please correct me if I'm wrong here...

comment:17 Changed 8 years ago by godoy

@ezio: I don't get two instances of the script running, just one. I can't say why you get two of them...

comment:18 Changed 8 years ago by godoy

@khorn: For LSB 3.1 you're correct.  http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html

"startproc" is "start_daemon" and "checkproc" is "pidofproc". Those functions (with the same name I used) were available in other distributions, but the change can be made to use the documented names by the LSB spec with no pain.

If this gets into the docs -- or someone gets here --, I believe the changes above should be painless and work out of the box. I have no time to test them right now, but I'll add this to my todo list and upload new scripts with the LSB standards name.

BTW, you have to be sure that your distribution is LSB compliant (e.g. by installing all lsb packages) since some make this optional or require extra steps.

Thanks for the correction. This really looks like a SuSE-born behavior that has somehow spread a little.

comment:19 follow-up: ↓ 20 Changed 8 years ago by khorn

for the benefit of those who get here via google...

checkproc and startproc are SUSE utilities, though they can work on some other distros

checkproc <> pidofproc...I could not get this to work at all. checkproc's behavior is very different from pidofproc

I ended up using a modified version of this script that I found in the mailing list:  http://groups.google.com/group/turbogears/msg/7a279713a5b1fdc7

the script linked above should work for most RH-derived distros, but it has some limitations:

  1. it doesn't check to see whether the TG app is already running
  2. it doesn't have a "restart" function

it would be really nice to have an init script that is cross distro, though this seems non-trivial...

maybe there should be a collection of init scripts posted on docs.turgogears.org?

maybe I'll post that (or something like it) later on...

comment:20 in reply to: ↑ 19 Changed 8 years ago by godoy

Replying to khorn:

checkproc <> pidofproc...I could not get this to work at all. checkproc's behavior is very different from pidofproc

If you have the patience and time to work on this "bug" this weekend we can end up with a solution to that. Anyway, I'll come back to this on Saturday :-) (or Friday night -- having a girlfriend that is far from me allows me those extra hacking time ;-))

comment:21 Changed 8 years ago by alberto

  • Milestone changed from 1.1 to __unclassified__

Batch moved into unclassified from 1.1 to properly track progress on the later

comment:22 Changed 7 years ago by Chris Arndt

  • Owner changed from anonymous to Chris Arndt

comment:23 Changed 7 years ago by Chris Arndt

  • Status changed from new to closed
  • Resolution set to fixed

I have uploaded example scripts (from the mailing list and the attachments here) for Redhat, Debian, Gentoo and Suse to this page on the doc wiki:

 http://docs.turbogears.org/1.0/RoughDocs/InitScripts

Since Linux init scripts are inherently platform specific and don't work well for non-root users, they won't get included in the TurboGears distribution. If somebody wants to build a quickstart template extension package, we will be glad to host it in our SVN repository.

comment:24 Changed 4 years ago by chrisz

  • Milestone changed from __unclassified__ to 1.0.x bugfix
Note: See TracTickets for help on using tickets.