...
5) فایلهای تنظیمات
فایل run-loop.ps1
...
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
$exePath = "D:\SMSSender\iMaster.ERP.SmsSender.Console.exe"
$processName = "iMaster.ERP.SmsSender.Console"
$intervalSeconds = 60
$logFile = "D:\SmsService\runner.log"
while ($true) {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
try {
$alreadyRunning = Get-Process -Name $processName -ErrorAction SilentlyContinue
if (-not $alreadyRunning) {
Add-Content $logFile "[$timestamp] Starting $exePath"
$process = Start-Process -FilePath $exePath -PassThru
$process.WaitForExit()
$exitCode = $process.ExitCode
Add-Content $logFile "[$timestamp] Finished with exit code $exitCode"
}
else {
Add-Content $logFile "[$timestamp] Process already running. Skipped."
}
}
catch {
Add-Content $logFile "[$timestamp] ERROR: $($_.Exception.Message)"
}
Start-Sleep -Seconds $intervalSeconds
} |
...
فایل فایل SmsRunnerService.xml
...
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
<service>
<id>SmsRunnerService</id>
<name>SMS Runner Service</name>
<description>Runs iMaster.ERP.SmsSender.Console.exe every 1 minute</description>
<executable>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</executable>
<arguments>-NoProfile -ExecutionPolicy Bypass -File "D:\SmsService\run-loop.ps1"</arguments>
<logpath>D:\SmsService\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<startmode>Automatic</startmode>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="30 sec"/>
<onfailure action="restart" delay="1 min"/>
</service> |
...
6) تست فعال بودن سرویس
روش 1: بررسی در Services
...