Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tlug: Auto run at boot time



>>>>> "Darren" == Darren Cook <darren@example.com> writes:

    Darren> 1.A command to run once at boot-time, eg. to make a backup
    Darren> of all the files in a directory.

/etc/rc.d/rc.local

rc.sysinit was mentioned; don't use that file.  rc.local is guaranteed 
not to be touched by upgrades of init.  This means that (a) your mods
won't get munged by the upgrade and (b) your mods won't confuse the
upgrade and cause it to fail.  rc.sysinit is owned by the
distribution's package manager.

    Darren> 2.Run apache (or some similar server) so it will be
    Darren> listening even if I don't log in. I found the init.d
    Darren> directory, but I couldn't find where I specify which
    Darren> daemons I want to be started. [*]

If you have a Debian system, read /etc/init.d/README.  RH and TL don't
provide a /etc/rc.d/init.d/README last I checked.  :-(  For ease of
maintenance, the scripts which start and stop daemons are all placed
in .../init.d/.  For flexibility, they are not run from there.
Instead, each "runlevel" has a rc$LEVEL.d directory, and coded
symlinks are used.  Find out what runlevel you normally use (grep
initdefault /etc/inittab), and make appropriate links in
.../rc$LEVEL.d.  Since your system is running fine without the server, 
it is probably appropriate to use the "S99" prefix to indicate it
should be started very late (Debian has an official list of prefixes
apprpriate to various servers and system daemons, if your distro has
such a thing it's best to conform).

The main advantage to using x?inetd is that you can use tcpwrappers to
check security.  This is normally not that big an issue with HTTPds,
by design of protocol and server implementation.  Most of them now
provide many features like those of tcpwrappers, but on a much more
fine-grained basis (per file is usually possible).  Of course if you
only get one request per day for a service it seems silly to run a
server 7x24.

    Darren> 3.A command to run when I log-in as a "darren" but not any
    Darren> other user. Is it possible to differentiate between the
    Darren> first time I log-in (maybe to backup some files) and each
    Darren> time after that (I don't want it running a backup if I'm
    Darren> just opening another virtual console to run man or ls).

Put

if [ ! -f /tmp/.Darren-slept-here ] ; then
 # set semaphore
 touch /tmp/.Darren-slept-here
 # Once when you log in duties go here
fi

in .bash_profile (warning, this may not work if your normal "login
terminal" is a xterm, because some people don't like all their xterms
appearing when they do finger and are too lazy to fix it so that the
first xterm is a login shell; if your distro was put together by
someone like that, put it in .bashrc).  That's FYI; it's pretty clear
you're not running X on this box.

# clear semaphore
rm /tmp/.Darren-slept-here

in .bash_logout (won't work if it's not a login shell) or
/etc/rc.d/rc.local.  The former will occasionally do extra backups if
you log that bash session out for some reason but don't shut the
machine down.  The latter cleans it up at boot, so session is defined
by the kernel uptime, not by the bash process.

It seems to make more sense for the backup application to do it in
.bash_logout or by creating an rc.local-shutdown script that gets run 
in the reboot and shutdown runlevels (often 6 and 0 respectively).

To do it in .bash_logout you need to do some preparation in
.bash_login:

# identify yourself
if [ ! -f /tmp/.Darren-slept-here ] ; then
 # put bash's process ID where you'll know how to find it
 echo $$ >/tmp/.Darren-slept-here
fi

Then in .bash_logout

if [ "$$" = `cat /tmp/.Darren-slept-here` ]; then
 # clear semaphore, we're going down!
 rm /tmp/.Darren-slept-here
 # do what ya gotta do
fi

-- 
University of Tsukuba                Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Institute of Policy and Planning Sciences       Tel/fax: +81 (298) 53-5091
__________________________________________________________________________
__________________________________________________________________________
What are those two straight lines for?  "Free software rules."
-------------------------------------------------------------------
Next Technical Meeting: February 13 (Sat), 12:30 place: Temple Univ.
** presentation: XEmacs, by Steven Baur and Martin Buchholz
Next Nomikai: March 19 (Fri), 19:30   Tengu TokyoEkiMae 03-3275-3691
-------------------------------------------------------------------
more info: http://tlug.linux.or.jp                     Sponsor: PHT


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links