# How to intercept net.ethX stop ?

## Beju

Just like in the subject. Is there a way to execute custom function before network interface is being stopped, and abort the procedure under certain conditions?

----------

## chithanh

Yes, see the predown() function in net.example.

----------

## Beju

I saw it, but it will be triggered also when I do 'restart'. Is there a way to distinguish between 'restart' and 'stop' ?

----------

## Hu

Do you need to allow restart to run through?  If I recall correctly, both will result in the interface being fully down for a moment, so if you need to prevent the interface from coming down, I would expect that you want to intercept both stop and restart.

----------

## Beju

Yes, but that's not the case. What really matters is not the fact that the interface goes down in both cases, but rather that after stop it's not going to be brought back again.

----------

## Hu

After a stop, it is likely that it will not come back.  However, it is not guaranteed that it will come back after a restart.  Consider the case of a DHCP-configured system that issues a restart while the DHCP server is down.  The stop phase may work fine, but then the attempt to acquire an address will fail and the interface will be down.

----------

## Beju

Yes, I am aware of that. The risk of interface startup failures caused by third-party reasons has been reduced to a minimum, which is acceptable for me. If the startup will fail because of a harware or module error, then it's a bad luck - I'll have to fix it somehow. However, In case of 'stop', the risk of the interface being down after the procedure is raised to almost 100%, which is unacceptable.

----------

## madchaz

in both cases, the work is the same, but you also gain a minimal advantage in the case of a restart.

However, if you want to check if you are doing a start/stop/restart, I suggest looking at the arguments of the init script. (/etc/init.d/net.lo as all others are a link to it)

You can customise from there. You want to be carefull if you are going to catch the stop "at the last minute" as it were. Remember that on shutdown/restart of the system, you will do a stop and you might hang your system. 

If what you are trying to do is prevent some users from doing a stop of the interface, but allow them to restart, you might want to look into using sudo instead of letting them use root directly.

----------

## Beju

Thanks:) I've already checked the net.lo file, but the problem is that it's not executed by bash but by a runscript program. I have some difficulties with figuring out how does the runscript work.

----------

