Introduction to running as service
Sometimes it may be needed to run SAWS as service - so it starts automatically once computer is turned on (even before any user logged into the computer). This is supported by SAWS on Windows and Mac. On Windows and Mac SAWS will run as some real user (not as some special system user).
Having enabled running as a service, you can also enable SAWS to listen on all IP addresses, so other computers are able to connect to SAWS too. To enable listening on all IP addresses, open your project in CDBuilder, go to Project ⇒ Site Settings ⇒ General ⇒ Server Proprties, and check a checkbox Accept connections from other computers too and then rebuild your Prototype.
Please note that intended purpose of SAWS is web server used only from the same computer, so remote security vulnerabilities are not fixed in SAWS at all. So by enabling access to SAWS from other computers may be a security risk.
Running SAWS as service on Windows
To run SAWS as service on Windows, go to site/stunnixwebsrv/tools/run-as-service/windows directory in Explorer and click on "generate scripts (run it first as normal user)" .bat file. It will generate 2 .bat files in the same directory - one for registering windows service (named SAWS), another one - for deregistering it. Both of the files have to be run as admin.
So just run "add service (run it as Admin)" file as Admin and you will see SAWS service in the list of services. Then open its properties in Services Management console and configure it to run as some real user (e.g. as yourself) - this is needed because default windows accounts for running services have very limited permissions, so SAWS won't start if you do not configure service to run as some real user!
Then you can start the service, stop it, restart it and configure it from Services Management Console. And of course you can configure it to start at boot (by default it won't be configured to start at boot).
To control it from php, just run these commands using exec()
net start SAWSand
net stop SAWSThese commands should be run as admin though (this is how Windows works) (see this for more info here).
To deregister service, just run file "remove service (run it as Admin)" - as admin.
If you will need to move SAWS to a different location, stop the service, run "remove service (run it as Admin)" first, then move SAWS, then run this script again to regenerate "add service .." and "remove service" s cripts.
Running SAWS as service works on Windows 8.x, Windows 7 and WinXP.
Running SAWS as service on MacOS X
To run SAWS as service on MacOS X, go to site/stunnixwebsrv/tools/run-as-service/macosx directory in Finder and run click either make-system-agent.command or make-system-service.command
- Run make-system-agent.command if you wish SAWS to be run as User Agent - i.e. so it's running while user is logged in.
- Run make-system-service.command if you wish SAWS to be run as daemon - i.e. upon startup of computer.
In both cases SAWS will be run under the account of current user.
To undo effect of running these programs, go to /Library/LaunchAgents or /Library/LaunchDaemons (depending on how you've installed SAWS - as a User Agent or as a Daemon) and remove file named com.stunnix.webserver.plist and then reboot computer.