Running selenium bash script from an osx daemon - linux

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.

Related

Remote creation of Custom actions in Thunar

I'm using Thunar as file browser for a linux network composed of 100 CentOS 7.2 machines. We are managing the installation of those workstations with a PXE server and SaltStack installation.
I need to create those custom actions during the installation.
Currently, Thunar is installed on every workstations, the script is available on a share but I need to create the custom action on each machine. Open Thunar, Edit > Create custom actions and it launches my script in xterm for the selected folder:
xterm -e "/path/to/my/script.sh %f"
Is there a way to create Thunar's custom actions from command lines or by editing a file so that I will be able to launch them through Salt cmd.run?
Thanks for your help.
I've found out that those Custom actions are store in this file:
cat ~/.config/Thunar/uca.xml
Here is an example of the syntaxe:
<?xml encoding="UTF-8" version="1.0"?>
<actions>
<action>
<icon>script.png</icon>
<name>My custom action</name>
<unique-id>1479309009025049-2</unique-id>
<command>xterm -e "/path/to/my/script.sh %f"</command>
<patterns>*</patterns>
<startup-notify/>
<directories/>
<audio-files/>
<image-files/>
<other-files/>
<text-files/>
<video-files/>
</action>
</actions>
That way, I can create this template file and copy it in the user folder.

OSX launchctl , how to stop a job upon unload

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

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.

zookeeper zkServer.sh can not start persistently

we use hudson ci to trigger a build.xml which invoke a shell script in linux via Ant exec command.
From the console output shows the zookeeper successfully started
After checked the zookeeperPID,its valid after the zookeeper started.But just few seconds later,the process disappeared without any notes.
I have checked my build.xml ,shell script,os env and investigate the ant source code regarding exec task,but still not any clue.
The shell and build.xml can work smoothly by commands on linux but problematic by hudson job trigger.
Any help would be great appreciated!
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="default">
<target name="default" description="description">
<exec executable="/bin/bash">
<arg value="test.sh"/>
</exec>
</target>
</project>
test.sh
#!/bin/bash
cd ${target_dir}/zookeeper-3.4.3/bin
sh zkServer.sh start
due to the hudson process handling,the spawning process will be killed which caused this issue.
RefUrlLink: https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller
The work around is setting the java parameter to disable related class file
-Dhudson.util.ProcessTreeKiller.disable=true

Resources