Last active
August 29, 2015 14:25
-
-
Save hyoshida/0b806fc6870c90ea0a38 to your computer and use it in GitHub Desktop.
Restart Jenkins from the build of Jenkins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
CWD=$WORKSPACE/.. | |
echo "cd $CWD" | |
cd $CWD | |
if [ `ruby queue_count.rb` -gt 0 ]; then | |
echo "Too busy..." | |
exit 1 | |
fi | |
echo "Restarting jenkins..." | |
# refs: https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build | |
daemonize -E BUILD_ID=${BUILD_ID} $CWD/restart-jenkins | |
echo "SUCCESS!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suid: restart_jenkins | |
sudo chown root restart_jenkins | |
sudo chmod u+s restart_jenkins | |
restart_jenkins: restart_jenkins.c | |
cc restart_jenkins.c -o restart_jenkins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
json = open('http://localhost/queue/api/json').read | |
hash = JSON.parse(json) | |
puts hash['items'].count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main() { | |
if (setuid(0) == -1) { | |
printf("setuid: %s\n", strerror(errno)); | |
return 1; | |
} | |
return system("service jenkins restart"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment