|
NAMEtcllauncher - Tcl application launcherSYNOPSIS::tcllauncher::pidfile_open ?filename? ?mode?::tcllauncher::pidfile_write ::tcllauncher::pidfile_mtime ::tcllauncher::pidfile_close ::tcllauncher::pidfile_remove ::tcllauncher::daemonize ?-noclose? ?-nochdir? ::tcllauncher::require_user userName ::tcllauncher::require_group groupName ::tcllauncher::require_user_and_group userName groupName DESCRIPTIONtcllauncher is a way to have Tcl programs run out of /usr/local/bin under their own name, be installed in one place with their support files, and provides commands to facilitate server-oriented application execution.Now you might think, why bother? I'll just put my script in there and do a #! thing to invoke Tcl. Well, OK, but this has certain problems:
You'd like to be able to have stuff show up as its script name. You could just copy or even link tclsh to the name of your program. Say, for instance, trackserver. But then you have to invoke trackserver with arguments and do stuff to prep it, like: cd ...somewhere... /usr/local/bin/trackserver main.tcl cp /usr/local/bin/tcllauncher /usr/local/bin/trackserver trackserver So when "tcllauncher" is installed as "trackserver" and you run trackserver, what happens "/usr/local/bin/trackserver" starts up like the Tcl shell, except that it sources in "/usr/local/lib/trackserver/main.tcl". Also, a global variable called launchdir is set containing the "launch directory," i.e. the directory where main.tcl was loaded from. ( In the above example, "/usr/local/lib/trackserver.") WHAT DIRECTORYTcllauncher doesn't change your directory behind your back, so wherever you are at when you run it, you're still in that directory.But a lot of times you want to go to your application directory, so you can just cd $::launchdir PROCESS GROUPIf you are going to fork off children, exec them, or whatever, you should probably become your own process group so hopefully your children might inherit your signals and Do The Right Thing.id process group set PID FILELots of apps write a file with the server's process ID in it. Upon relaunch, the program can come along and look in its own pid file to see if it's already alive or not, and also to potentially kill it.Our pidfile support is a studied Tcl-based copy of BSD's pidfile C library.
EXAMPLEset pid [::tcllauncher::pidfile_open "/var/run/daemon.pid" 0600] if {$pid > 0} { puts stderr "pid $pid already has the lock" exit 1 } ::tcllauncher::daemonize ::tcllauncher::pidfile_write ...do work... ::tcllauncher::pidfile_remove exit DAEMONIZESometimes you want your program to spawn itself off into the background in a way that when you logout it doesn't kill the process, etc. To daemonize a tcllauncher app,
USER AND GROUP ID MANAGEMENTIf a program needs to be run as a certain use, it can invoke
Note that if you require user first then require group, the process may have lost the privileges necessary to change groups after changing users. Either require the group ID first or use ::tcllauncher::require_user_and_group to do both. KEYWORDSbackground, daemon, daemonize, tcllauncherCOPYRIGHTCopyright (c) 2007-2014 FlightAware LLC (BSD Liscense)
Visit the GSP FreeBSD Man Page Interface. |