I have a simple app (below) that assures that a web server is running. (For one command I'm using Teminal.app since, for some reason, it doesn't work if I use an ordinary "do shell script"-command there). At startup, the app also assures that the app itself is a login item.
Now, this simple app seems to eat a lot of virtual memory! Virtual memory for this simple app is growing conutiously, reaching above one GB after a few days!
I have a couple of other – huge – applescript applications running on servers, and I would not be surprised if one of them where eating memory - but that is not the case. More surprisingly, this small one is very hungry…
property dbLogPath : "~/WebServer/baristaciao_db.log"
property prefsDomain : "se.tt.ciaobarista"
property myNameKey : "myPrettyName"
on run
my startWeb()
global myPath, gMyPosixPath, gMyName
tell application "System Events"
set myPath to (path to me)
set gMyPosixPath to POSIX path of myPath
set gMyName to (name of myPath)
set AppleScript's text item delimiters to "."
set gMyName to first text item of gMyName
set AppleScript's text item delimiters to ""
end tell
my assureMeLoginItem()
do shell script "defaults write " & prefsDomain & space & myNameKey & space & the quoted form of gMyName
end run
on assureMeLoginItem()
-- Add as login item if not there:
tell application "System Events"
if (login item (my gMyName) exists) is false then make new login item at end of login items with properties {path:my gMyPosixPath, hidden:true, kind:application, name:my gMyName}
end tell
end assureMeLoginItem
on idle
my startWeb()
return 60
end idle
on reopen
my startWeb()
end reopen
on startWeb()
local psParas, processNames
set processNames to {}
set psParas to paragraphs of (do shell script "ps uxc")
repeat with aPara in psParas
set end of processNames to last word of aPara
end repeat
-- Start webservice
if "mongod" is not in processNames then do shell script "~/Utils/mongodb/bin/mongod --fork --logpath " & dbLogPath
-- Start database
if "node" is not in processNames then
try
tell application "Terminal"
activate
tell front window
do script "cd webserver;node_modules/forever/bin/forever start server.js"
repeat until contents contains "Forever processing"
activate
tell me to delay 1
end repeat
tell me to delay 2
close saving no
end tell
end tell
on error errT
if errT does not contain "Terminal" then set errT to ("Terminal: " & errT)
error errT
end try
if "Terminal" is not in processNames then -- quit Terminal if it was not running from the begionning
try
quit application "Terminal"
end try
end if
set {psParas, processNames} to {{}, {}} -- should not be necessary...
end if
end startWeb