Skip to content

Commit

Permalink
Add a test run of the slave script to the tasks
Browse files Browse the repository at this point in the history
RE #62
  • Loading branch information
cailafinn committed Feb 8, 2023
1 parent a47619b commit 0673c18
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /bin/sh

AGENT_NAME=${1}
AGENT_SECRET=${2}


echo "Check if the secret or name has changed and kill the current java process if it has. "

cron_entry=$(crontab -l | grep jenkins-slave.sh)
cron_name_and_secret=$(echo "$cron_entry" | grep -o "$AGENT_NAME .*")

if [[ "$AGENT_NAME $AGENT_SECRET" != "$cron_name_and_secret" ]]; then
pgrep java | xargs kill -9
fi


echo "Run the agent startup script in the background. "

$HOME/jenkins-slave.sh $AGENT_NAME $AGENT_SECRET &


echo "Wait for the script to get to its hang point. "

sleep 5


echo "Check that the script has connected the agent to the controller. "

jenkins_json=$(curl https://builds.mantidproject.org/manage/computer/$AGENT_NAME/api/json)
is_offline=$(echo "$jenkins_json" | grep \"icon\":\"symbol-computer-offline\")

if [[ $is_offline ]]; then
echo "Agent failed to connect to Jenkins controller. "
exit 1
fi


echo "Agent connected successfully. "

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,59 @@

# Install Requirements

- name: Add user to sudoers on new macs
- name: Add user to sudoers on new macs.
shell: /Applications/Privileges.app/Contents/Resources/PrivilegesCLI --add
ignore_errors: true # Not all the macs have these, so don't panic if it fails.

- name: Install homebrew
include_role:
name: geerlingguy.mac.homebrew

- name: Make sure homebrew bin is in the path
- name: Make sure homebrew bin is in the path.
ansible.builtin.lineinfile:
path: /etc/paths
state: present
line: '/opt/homebrew/bin'
become: true
become_user: root

- name: Install git
- name: Install git.
community.general.homebrew:
name: git
state: latest

- name: Install Java 11
- name: Install Java 11.
community.general.homebrew:
name: java11
state: present

# Configure macOS Settings
# Configure macOS Settings.

- name: Disable screensaver
- name: Disable screensaver.
shell: defaults write com.apple.screensaver idleTime 0

- name: Disable saved application states to avoid dialog
- name: Disable saved application states to avoid dialog.
shell: defaults write org.python.python NSQuitAlwaysKeepsWindows -bool false

# TODO: Disable autolock (this seems to change between versions, so might not be possible to script)

- name: Download jenkins slave script
shell: curl -o ~/jenkins-slave.sh https://raw.githubusercontent.com/mantidproject/mantid/main/buildconfig/Jenkins/jenkins-slave.sh

- name: Start script as chrontab entry
# Test and start the agent. Note: Connection will only begin consistently every 5th minute if changes are made.

- name: Download jenkins slave script.
shell: curl -o $HOME/jenkins-slave.sh https://raw.githubusercontent.com/mantidproject/mantid/main/buildconfig/Jenkins/jenkins-slave.sh

- name: Make the slave script executable.
shell: chmod 777 $HOME/jenkins-slave.sh

- name: Check the Jenkins agent connection script.
script: ./check-connection.sh {{ agent_name }} {{ agent_secret }}

- name: Setup a chrontab entry to run the agent script every 5th minute.
ansible.builtin.cron:
name: "Run slave script"
minute: "*/5"
job: "$HOME/jenkins-slave.sh {{ agent_name }} {{ agent_secret }}"

- name: Remove user from sudoers on new macs
# Tidy up the evironment.

- name: Remove user from sudoers on new macs.
shell: /Applications/Privileges.app/Contents/Resources/PrivilegesCLI --remove
ignore_errors: true # Not all the macs have these, so don't panic if it fails.


0 comments on commit 0673c18

Please sign in to comment.