Starting a service which may have port conflicts with existing service

0

Is there any way to start a service and force a service that is already running to stop if it uses the port that the service I want to start is going to be using?

I'm going to be installing apache and mysql, and want the services to be running without having to manually stopping existing services that use port 80/3306 such as existing apache/mysql services.

I'm using NSIS to make my installer.

Michael

Posted 2011-08-30T10:06:21.870

Reputation: 191

Answers

1

I made my installer abort if it found that the ports 80 or 3306 were in use.

I used a TCP plugin for NSIS, http://nsis.sourceforge.net/TCP_plug-in

I used it in this fashion,

...
TCP::CheckPort "80"
Pop $0
StrCmp $0 "free" port_ok
StrCmp $0 "socket_error" socket_error
StrCmp $0 "inuse" socket_inuse
Goto port_ok
socket_inuse:
    MessageBox MB_OK "Port 80 is in use by another application."
    Abort
socket_error:
    MessageBox MB_OK "Error connecting to port 80"
    Abort
port_ok:
...

Michael

Posted 2011-08-30T10:06:21.870

Reputation: 191

+1. It is better to abort and let the user know why, rather than stop existing services. If one did that to a server of mine, I'd have a French-Canadian fit. – Patrick Seymour – 2011-11-28T23:10:48.867