Changes

Jump to navigation Jump to search

Coral: cron srvstart utility

77 bytes removed, 16:18, 14 November 2011
Punctuation and grammatical changes.
<span style="margin-bottom:5px;font-size:25px;color: #31799F;">CRON - SrvStart utility tutorial</span>
This short tutorial covers using the SrvStart utility written by Nick Rozanski. It allows you to run a script as a service!
'''What is a Service?'''<br />
A Windows Service is automatically started when your PC starts. Services automatically recover from program crashes and Standby or hibernation Hibernation modes. Installing software as a Service service requires Administrator permissions.
'''Complexity'''<br />
Programs (An application) program designed to run as a service contain contains code that interface interfaces to the Windows service manager. Running a script as a service requires additional code that allows it to access the Windows service manager. This code registers your script , allowing it to be run as a service in . In addition it must provide responses to command requests from the service manager and have the ability to provide your scripts script's status.
Not It's not a trivial exercise however , but this complexity is hidden when using SrvStart.
* svc.exe
We are interest only interested in files '''srvstart.exe''', '''srvstart.dll''' and '''logger.dll'''<br />For this tutorial , create a new folder c:\'''service_test''' and copy the above three files into it.
'''Note 1:'''<br />
The documentation states says to copy files srvstart.exe, srvstart.dll, logger.dll and msvcrt.dll to C:\WINDOWS\system32 (system path). For XP onwards msvcrt.dll is already installed on a system path. Other The other three files do not need not to be installed on a system path ; see below.
We are going to run srvstart.exe from its installation folder. This allows it to be portable by not installing anything on a host PC (assumes running from memory stick).
'''Note 2:'''<br />
When Notwithstanding the above, when installing a service , it does write to the registry hence , so you must remember to stop and uninstall the service you create especially if running from it resides on an external drive or a memory stick.
 
'''''[[#top | Top]]'''''
==Script to run==
For this tutorial we require a script to run. Create a new text document named '''my_script.vbs''' with the following content:
</pre>
|
This is an annoying VBScript it which just produces beeps when runit runs
Double click on my_script.vbs and confirm that it produces two beeps.
|}
'''''[[#top | Top]]'''''
===Limitation===
An application to be run as a service must have one of the following file extensions : .exe, .com or .bat . The script we want to run has an extension of .vbs hence so it cannot be run directly.
At first this looks very restrictive , however a batch file will run any application.To run our script as a service , create a batch file named my_script.bat with the following content:
{|
</pre>
|
'''start''' Runs our vb script and closes. It does not wait for our vb script to finish.<br />
Double click on my_script.bat and confirm it produces two beeps.
|}
'''Note 1:''' Running my_script.bat a command window opens for a short time. When run as a service this is hidden.<br />
'''Note 2:''' Removing the "start" keyword , our vb script runs and the command window remains open until vb script finishes. Again , when run as a service , this is hidden.
'''''[[#top | Top]]'''''
==SrvStart configuration file==
To create our application (script) service SrvStart requires a configuration file.
|}
'''''[[#top | Top]]'''''
==Control_batch_files==
We are now ready to install and run our service this . This can be done using a command prompt and issuing the appropriate commands.
I prefer to put these commands into separate batch files as follows:
|}
'''''[[#top | Top]]'''''
==Test - Perceived problems==
{|
Run '''z_service_start.bat'''
|
Confirm two bleeps beeps are produced. Note the following messages:
* The z_test service is starting.
* The z_test service could not be started.
* The service did not report an error.
* More help is available by typing NET HELPMSG 3534.
With the confirmation of two beeps , our script was successfully run. Reason The reason for '''could not be started message'''; the batch file closes immediately when run. Srvstart regularly checks the running status of an application it started, it immediately sees the script is no longer running and reports back to the service control that it could not be started.
The service did not report an error because it’s not an error.
|-valign="top"
* The z_test service is not started.
* More help is available by typing NET HELPMSG 3521.
The batch file is not running , hence the service is reported as reported is not running ; see above.Above The above is not a problem its ; it's the way we want to run our scripscript.
|-valign="top"
|
Confirms correct operation
|}
'''Note:''' The above results may be a little confusing, remember . Rremember our VBScript does not run continuously its ; it's a run -once program. Its purpose is to familiarise yourself with the Srvstart SrvStart program.
'''''[[#top | Top]]'''''
==Service Status==
With the service created, it will now appear in the Windows Services list and can be configured like any other Windows Service.
* It is set to Manual startup.
* It starts using LocalSystem and has no dependencies.
* If It cannot interact with the desktop.
===Manual startup===
Service The service start type specifies the services service's behavior after reboot:
* Auto - Automatically start after a re-boot
* Disabled - Deactivated
We want our script to start when the PC is powered up. Either change the Manual state to Auto using service manger., orAlternatively use a script to set the service state. Create a new file named '''start_automatic.vbs''' with the following content:
<pre>
For testing , this script starts our service and changes it to Automatic.
<pre>
</pre>
'''''[[#top | Top]]'''''
==Simulating service program crash==
Our batch file is ideal for simulating a service program crash and demonstrating recovery. The batch file only runs once (simulating a program crash), srvstat can be set to automatically restart the program using directive '''auto_restart=y''', setting '''restart_interval=seconds''' will pause before starting.
|}
'''Note 1:''' auto_restart will restart the service program if it exits for any reason. If restart_interval is defined, then before restarting, SRVSTART will wait seconds the specified seconds.
'''Note 2:''' auto_restart does not; restart the service program if it is stopped by request (eg NET STOP or Control Panel|Services).
'''Note 3:''' auto_restart does not restart the service program if it thinks that Windows NT is shutting down. If you are irritated by services restarting during Windows NT shutdown, then increase the value of restart_interval to, say, a minute.
'''''[[#top | Top]]'''''
==Conclusion==
The above has shown how to run a simple VBScipt as a service.
When The Uniform Server is installed as a permanent installation , the concepts outlined above can be used for kicking portable cron into life.
Portable cron is intended to be run from a memory stick and still requires manually starting.
==Where to next==
Related to the above service is The Uniform Server Cron both . Both portable cron and running as a service have been implemented for . For the details , see [[Coral: cron intro|Cron]].   
'''''[[#top | Top]]'''''
----
[[Category: Uniform Server 8-Coral]]

Navigation menu