github.com/pquerna/agent@v2.1.8+incompatible/packaging/linux/root/usr/share/buildkite-agent/lsb/buildkite-agent.sh (about) 1 #!/bin/sh 2 # 3 ### BEGIN INIT INFO 4 # Provides: buildkite-agent 5 # Required-Start: $network $local_fs $remote_fs 6 # Required-Stop: $remote_fs 7 # Should-Start: $named 8 # Should-Stop: 9 # Default-Start: 2 3 4 5 10 # Default-Stop: 0 1 6 11 # Short-Description: The Buildkite Build Agent 12 # Description: The Buildkite Build Agent 13 ### END INIT INFO 14 15 user="buildkite-agent" 16 cmd="/usr/bin/buildkite-agent start" 17 18 name=`basename $0` 19 pid_file="/var/run/$name.pid" 20 log="/var/log/$name.log" 21 stderr_log="/var/log/$name.err" 22 23 get_pid() { 24 cat "$pid_file" 25 } 26 27 is_running() { 28 [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1 29 } 30 31 case "$1" in 32 start) 33 if is_running; then 34 echo "Already started" 35 else 36 echo "Starting $name" 37 sudo -u "$user" $cmd >>"$log" 2>&1 & 38 echo $! > "$pid_file" 39 if ! is_running; then 40 echo "Unable to start, see $log" 41 exit 1 42 fi 43 fi 44 ;; 45 stop) 46 if is_running; then 47 echo -n "Stopping $name.." 48 kill `get_pid` 49 for i in {1..10} 50 do 51 if ! is_running; then 52 break 53 fi 54 55 echo -n "." 56 sleep 1 57 done 58 echo 59 60 if is_running; then 61 echo "Not stopped; may still be shutting down or shutdown may have failed" 62 exit 1 63 else 64 echo "Stopped" 65 if [ -f "$pid_file" ]; then 66 rm "$pid_file" 67 fi 68 fi 69 else 70 echo "Not running" 71 fi 72 ;; 73 restart) 74 $0 stop 75 if is_running; then 76 echo "Unable to stop, will not attempt to start" 77 exit 1 78 fi 79 $0 start 80 ;; 81 status) 82 if is_running; then 83 echo "Running" 84 else 85 echo "Stopped" 86 exit 1 87 fi 88 ;; 89 *) 90 echo "Usage: $0 {start|stop|restart|status}" 91 exit 1 92 ;; 93 esac 94 95 exit 0