Add an HTTP hook for updating code on the puppet server
[cacert-puppet.git] / sitemodules / profiles / files / puppet_server / git-pull-hook.init.sh
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides: git-pull-hook
4 # Required-Start: $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: CAcert puppet git pull hook
9 # Description: CAcert puppet git pull hook
10 ### END INIT INFO
11
12 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
13
14 BASE=git-pull-hook
15
16 GIT_PULL_HOOK=/usr/local/sbin/git-pull-hook
17 GIT_PULL_HOOK_PIDFILE=/var/run/$BASE.pid
18 GIT_PULL_HOOK_LOGFILE=/var/log/$BASE.log
19 GIT_PULL_HOOK_DESC="Puppet git pull hook"
20
21 # Get lsb functions
22 . /lib/lsb/init-functions
23
24 # Check git-pull-hook is present
25 if [ ! -x $GIT_PULL_HOOK ]; then
26 log_failure_msg "$GIT_PULL_HOOK not present or not executable"
27 exit 1
28 fi
29
30 fail_unless_root() {
31 if [ "$(id -u)" != '0' ]; then
32 log_failure_msg "$GIT_PULL_HOOK_DESC must be run as root"
33 exit 1
34 fi
35 }
36
37 case "$1" in
38 start)
39 fail_unless_root
40
41 touch "$GIT_PULL_HOOK_LOGFILE"
42 chown root:adm "$GIT_PULL_HOOK_LOGFILE"
43
44 log_begin_msg "Starting $GIT_PULL_HOOK_DESC: $GIT_PULL_HOOK"
45 start-stop-daemon --start --background --no-close \
46 --exec "$GIT_PULL_HOOK" \
47 --pidfile "$GIT_PULL_HOOK_PIDFILE" \
48 --chdir "/" \
49 --make-pidfile \
50 >> "$GIT_PULL_HOOK_LOGFILE" 2>&1
51 log_end_msg $?
52 ;;
53
54 stop)
55 fail_unless_root
56 if [ -f "$GIT_PULL_HOOK_PIDFILE" ]; then
57 start-stop-daemon --stop --pidfile "$GIT_PULL_HOOK_PIDFILE" --retry 5
58 log_end_msg $?
59 else
60 log_warning_msg "$GIT_PULL_HOOK_DESC already stopped - file $GIT_PULL_HOOK_PIDFILE not found."
61 fi
62 ;;
63
64 restart)
65 fail_unless_root
66 git_pull_hook_pid=`cat "$GIT_PULL_HOOK_PIDFILE" 2> /dev/null`
67 [ -n "$git_pull_hook_pid" ] \
68 && ps -p $git_pull_hook_pid > /dev/null 2>&1 \
69 && $0 stop
70 $0 start
71 ;;
72
73 force-reload)
74 fail_unless_root
75 $0 restart
76 ;;
77
78 status)
79 status_of_proc -p "$GIT_PULL_HOOK_PIDFILE" "$GIT_PULL_HOOK" "$GIT_PULL_HOOK_DESC"
80 ;;
81
82 *)
83 echo "Usage: service git-pull-hook {start|stop|restart|force-reload|status}"
84 exit 1
85 ;;
86 esac