Last active
August 7, 2018 19:17
-
-
Save ThiagoGarciaAlves/91f217b70f261e804e5d16867fcddfe4 to your computer and use it in GitHub Desktop.
Startup script example
This file contains hidden or 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/bash | |
| ### BEGIN INIT INFO | |
| # Provides: jenkins_slave | |
| # Required-Start: $local_fs $remote_fs $network $syslog | |
| # Required-Stop: $local_fs $remote_fs $network $syslog | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: Start/Stop Jenkins Slave | |
| ### END INIT INFO | |
| . /etc/init.d/functions | |
| cd /jenkins | |
| case $1 in | |
| start) | |
| echo "starting..." | |
| export PID=$(ps -ef | grep java | grep slave-agent.jnlp | awk '{print $2}') | |
| if [ "$PID" != "" ] | |
| then | |
| failure | |
| echo "jenkins_slave already running..." | |
| exit 1 | |
| fi | |
| /bin/java -jar agent.jar -jnlpUrl http://<IP:PORT>/computer/slave1/slave-agent.jnlp -workDir /jenkins & | |
| success | |
| echo "jenkins_slave running..." | |
| ;; | |
| stop) | |
| echo "stopping..." | |
| export PID=$(ps -ef | grep java | grep slave-agent.jnlp | awk '{print $2}') | |
| if [ "$PID" == "" ] | |
| then | |
| failure | |
| echo "jenkins_slave is not running..." | |
| exit 1 | |
| fi | |
| kill -9 $PID | |
| success | |
| echo "jenkins_slave is stopped" | |
| ;; | |
| *) | |
| echo "use : $0 <start/stop>" | |
| ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment