[ previous ] [ next ] [ threads ]
 
 From:  Claude Morin <klodefactor at gmail dot com>
 To:  Adrian Basescu <adrianeli at gmail dot com>
 Cc:  m0n0wall at lists dot m0n0 dot ch
 Subject:  using the kill command [was Re: [m0n0wall] How can I run a command after the wan link is up and kill it after the wan link is down?]
 Date:  Mon, 18 Apr 2005 10:48:48 -0400
I don't know why myexec isn't working as you expect, but I have some advice 
about the kill command for those with less UNIX experience:
In general one should never use kill -9 (SIGKILL) unless nothing else works 
first. Instead, to terminate processes, send a hangup signal (SIGHUP): kill 
-HUP or a termination signal (SIGTERM): kill -TERM. BTW, kill -9 sends a 
"kill" signal (SIGKILL).
 
The problem with SIGKILL is that it doesn't give processes a chance to clean 
up after themselves, and can result in various process state files, 
temporary files, etc. being left lying around, for each time you used 
SIGKILL.

One last bit of advice about terminating processes: use the symbolic forms:
kill -HUP, kill -TERM (or just kill, since the default signal is SIGTERM), kill 
-KILL
 
instead of the numeric forms:
kill -1, kill -15 (or just kill), kill -9
 
The reason is best given with a classic (though apocryphal) example: a 
sysadmin wanted to make his UNIX operating system's startup monitor program 
(named init, with process id 1) re-read its config file, which is done by 
sending the process a SIGHUP. He meant to type kill -1 1, but in a 
fumble-fingered moment typed kill 1 1 (leaving out the minus sign in front 
of the signal number). This form sends (the default) SIGTERM to processes 1 
and 1.

The upshot is that he shut down his multi-user system, with predictable 
results. Let's just hope it wasn't a remote system. :-)

Depending on which UNIX he was using, he might have been saved if he'd left 
off the minus sign on the symbolic form: kill HUP 1. With any luck, his kill 
command would have refused to continue once it hit the invalid process id 
"HUP".

-klode

On 4/18/05, Adrian Basescu <adrianeli at gmail dot com> wrote:
> 
> Hello,
> I am trying to find a way to run a command after the wan link is up
> and kill it after the link is down. I have tried changing the file
> /etc/inc/interfaces.inc which seems to have the subroutine for taking
> up and down the wan link.
> 
> I have tried adding my command in a form similar to the command used
> in the script to set the default route and configure the interface
> inside the function
> "function interfaces_wan_configure":
> 
> mwexec("/usr/local/sbin/myexec");
> 
> and for killing myexec I have tried adding a command similar to the
> ones in the interfaces.inc file, immediately after the similar lines
> that kill dhcp client and the PPPoE client:
> 
> killbypid("/path/to/pid/myexed.pid");
> 
> BUT after all this, my process is not starting and it is not stopped
> if it was started when the wan goes up/down.
> 
> I have uploaded myexec into my m0n0wall and I have run it manually.
> It runs fine and I can kill it by pid number( kill -9 pidnumber).
> 
> What can I do further to automate this action, as my changes to the
> script seem to be useless?
> 
> Thanks!
> --
> Adrian
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: m0n0wall dash unsubscribe at lists dot m0n0 dot ch
> For additional commands, e-mail: m0n0wall dash help at lists dot m0n0 dot ch
> 
>