OSX launchctl , how to stop a job upon unload - node.js

Currently I am starting aGhost npm server using forever and a LaunchAgent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>rhino.forever.ghost</string>
<key>ProgramArguments</key>
<array>
<string>..../bin/node</string>
<string>..../bin/forever</string>
<string>start</string
<string>-w</string>
<string>..../index.js</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
starting it with :
launchctl load -w ~/Library/LaunchAgents/rhino.forever.ghost.plist
But it does not stop when unloading it :
launchctl unload ~/Library/LaunchAgents/rhino.forever.ghost.plist
Is there anyway to stop it when unloading ???
thanks for feedback

I resolved to start | stop | restart my ghost app 'rhino' with aliases in .bash_aliases
alias rhino.dev.start="nginx.start;
cd /Users/..../myghostapp;
~/.../bin/forever start -aw --uid 'rhino' index.js;
forever list"
alias rhino.dev.stop="forever stop 'rhino' ; nginx.stop"
alias rhino.dev.restart="forever restart 'rhino' ; nginx.restart"
running fine now

Related

Running a node.js script with launchd

I'm trying to run a web scraper I made with node.js. node app.js runs the file successfully, but I cannot get launchd to run the script. Here is my plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.username.kijijiscraper</string>
<key>Program</key>
<string>/usr/local/bin/node</string>
<key>ProgramArguments</key>
<array>
<string>/Users/username/documents/nodeprojects/scraper/app.js</string>
</array>
<key>StandardOutPath</key>
<string>/Users/username/documents/nodeprojects/scraper/launchdOutput.log</string>
<key>StandardErrorPath</key>
<string>/Users/username/documents/nodeprojects/scraper/launchdErrors.log</string>
</dict>
</plist>
I then load it with launchctl load /Users/username/library/launchagents/com.username.kijijiscraper.plist which is where the plist file is saved.
Eventually it will be run on an interval, but for now I'm trying to test it with launchctl start com.username.kijijiscraper.
The expected behaviour - receiving an email based on the result of the scrape - doesn't happen, and no errors are in the log file. Again, the webscraper works from the terminal.
You need start the service by:
launchctl start com.username.kijijiscraper
after load plist, or just append this:
<key>RunAtLoad</key>
<true/>
and this if you need:
<key>KeepAlive</key>
<true/>

Where is init folder in macs from where I can load my .conf file based jobs

I just migrated from linux, and trying to run one of my solutions in mac,
at my linux i had a .conf files while was used to change the "run level" and start a supervisor job at the start of machine.
Is there a similar implementation somewhere at the mac as well, if not then what's the alternative.
my .conf based job was used to look like this
description "myJob"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec supervisord --nodaemon --configuration <path to my config file>
The closest equivalent on OS X would be a launch daemon -- a property list file in /Library/LaunchDaemons that tells launchd when to launch your program. If I understand what your .conf file does, the equivalent would be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.myJob</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/your/script</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
Name that local.myJob.plist, put it in /Library/LaunchDaemons, set the owner to root and permissions to 644, and then either reboot or load it with sudo launchctl load /Library/LaunchDaemons/local.myJob.plist.
See man launchd.plist and Apple's developer document "Creating Launch Daemons and Agents"for more info and options. You can also look at the Apple-provided daemons in /System/Library/LaunchDaemons for more examples.

Running selenium bash script from an osx daemon

I have created a bash file that will kick off testing my website in Safari using selenium. I would like to have to instance occur every night at 5:55pm. To do so I have created a daemon in in /System/Library/LaunchDaemons. For some reason I never see the bash script start my selenium code. I'm wondering if anyone has had any experience with this? When I run my selenium bash script safari will open and my automated tests will run fine. I'm just a little confused why the same thing is not happening when calling the bash script from a daemon. I have already started the daemon using launchctl.
runselenium.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.runselenium.daemon</string>
<key>ProgramArguments</key>
<array>
<string>bash</string>
<string>/Users/admin/Desktop/workspace/runSelenium.bash</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>17</integer>
<key>Minute</key>
<integer>55</integer>
</dict>
</dict>
</plist>
runSelenium.bash
#!/bin/bash
source /Users/admin/Desktop/workspace/set-selenium-classpath.bash
java selenium.Main
The current error I am seeing in the console is com.apple.launchd: (com.runselenium.daemon[479]) Exited with code: 1
The deamon does not use your environment settings, specifically your user PATH. Make sure your script explicitly defines everything: PATH (or use only global paths), variables, etc. If this does not work, post your script and any errors.

jaxb binding customization without having xsd

I've a wsdl (I dont have the .xsd file) and I want to generate the classes from it.
Using wsimport I get a tree of classes that is the standard mapping of the webservice schemas itself and of its dependencies.
I obtain something like com->(microsoft,mycompany), org->(apache).
However I need to remap the package com.mycompany and all the classes inside into com.mycompany.test.
So I've tried to use the option of -b of ws import creating a a docbinding.xml that is Schema Customization XML. The content is :
<jxb:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings node="wsdl:definitions/wsdl:types/xsd:schema[#targetNamespace='http://mycompany.com/test/']">
<jaxb:package name="com.mycompany.test"/>
</jxb:bindings>
</jxb:bindings>
launching wsimport with this syntax :
wsimport -p com.mycompany -b docbinding.xml https://mycompany.com/nicews/test.svc?wsdl
I obtain a initial error that stops the generation of the classes:
[ERROR] XPath error: null
...
How can I fix the binding XML ?
If the types are in seperate XSD files. This is the way to do it.
Create two configuration files.
wsdl.jxb
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="https://mycompany.com/nicews/test.svc?wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:package name="com.mycompany.wsdl"/> <!-- namespace what you want here -->
</jaxws:bindings>
xsds.jxb
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<!-- This is used becuase we don't need to differentiate between absent and nil elements, you may want to differentiate. If so, remove this binding -->
<jaxb:globalBindings generateElementProperty="false">
<xjc:simple />
</jaxb:globalBindings>
<!-- REPEAT THIS SECTION FOR EACH XSD, replacing schemaLocation and package with whatever you want -->
<jaxb:bindings
schemaLocation="http://mycompany.com/someWsdlIncludeLocation?xsd=xsd0"
node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.mycompany.dto.saml" />
</jaxb:schemaBindings>
</jaxb:bindings>
<!-- END SECTION -->
</jaxb:bindings>
Create a batch file in the same directory
rmdir /S /Q build
rmdir /S /Q dist
rmdir /S /Q src
mkdir build
mkdir dist
mkdir src
"%JAVA_HOME%\bin\wsimport.exe" -b wsdl.jxb -b xsds.jxb -s src -d build -keep http://mycompany.com/someWSDLlocation?wsdl
"%java_home%\bin\jar" cf dist/mycompanyClient.jar -C build/ .
"%java_home%\bin\jar" cf dist/mycompanyClient-src.jar -C src/ .
See if that works for you. Make sure to edit the JXB files appropriately for your wsdl/xsd locations, and packages you want.

Associate an iphone app for kml and kmz google earth files

I'm trying to write an iOS app that should be able to open kml and kmz files from google earth.
I have added the following lines in the cfg file , but should be wrong ( I can't see my application listed when I try to open a kml file from another app, i.e. Mail) :
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/vnd.google-earth.kml+xml</string>
</array>
<key>CFBundleTypeExtensions</key>
<array>
<string>kml</string>
</array>
<key>CFBundleTypeName</key>
<string>Google Kml</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
Please help me to find the error...
Add these lines to Info.plist:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>Google Earth KML Document</string>
<key>LSItemContentTypes</key>
<array>
<string>com.google.earth.kml</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeDescription</key>
<string>Google Earth KML Document</string>
<key>UTTypeIdentifier</key>
<string>com.google.earth.kml</string>
<key>UTTypeReferenceURL</key>
<string>http://earth.google.com/kml/</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>GKml</string>
<key>public.filename-extension</key>
<array>
<string>kml</string>
</array>
<key>public.mime-type</key>
<string>application/vnd.google-earth.kml+xml</string>
</dict>
</dict>
</array>

Resources