Commit 9788fbd5855629b6d7481dd2c9f05ca247a7c976
Exists in
master
and in
39 other branches
Merge branch 'master' of github.com:TracyWebTech/colab
Showing
14 changed files
with
529 additions
and
223 deletions
Show diff stats
puppet/hieradata/common.yaml
| @@ -10,3 +10,5 @@ postfix::admin_email: test@test.test | @@ -10,3 +10,5 @@ postfix::admin_email: test@test.test | ||
| 10 | nginx::worker_processes: 8 | 10 | nginx::worker_processes: 8 |
| 11 | nginx::error_log: '/var/log/nginx/error.log' | 11 | nginx::error_log: '/var/log/nginx/error.log' |
| 12 | nginx::access_log: '/var/log/nginx/access.log' | 12 | nginx::access_log: '/var/log/nginx/access.log' |
| 13 | + | ||
| 14 | +# Remember to replace the id_rsa and id_rsa.pub on colab/files |
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | +-----BEGIN RSA PRIVATE KEY----- | ||
| 2 | +MIIEpAIBAAKCAQEAuCnJ7elkn0ZoMiZZIbZ8wigD1gcMwKyTVrPfnel9eNK9c/8R | ||
| 3 | +6QsE6xrNoNQmjTsbGJF88RZkz7cYxX9YFIXatL+Wckq+GUirWMUm/2zIR8rqo31X | ||
| 4 | +l/0E/nXWED3k9L3ZZwB3PzY15vDhkt+Gv+zpdYQkL6Jj23IAeDM1Q5/cq3Ha2z5l | ||
| 5 | +1L0z7wN+rttfE879Jxv7plC3ceVzm7jj5aYRH2dZFgkjgr3DmAI0fh+15To4apkQ | ||
| 6 | +fw/tvGPfogIDRhQybts5UvY2UnK4/ize+IswBTgTlNV864bLqpkgcY8drdX04Kxu | ||
| 7 | +34qBG1FGtj4MDP3kjJdoFOolV4vn+5nGQ0A6awIDAQABAoIBAGO7ZbpskWxb8aNu | ||
| 8 | +9wf1znxKtUEb0kEpdCUZBfl7b9KVtblyoZ1ltUUo38DAAxyqrJLSfyoEaZW/Xy/d | ||
| 9 | +NbLvhjAqLOw6I9aHbxuEsQjUPWX7srPU9jG9+Q1gfQuQqUQM6AYKz4kw72HggxhJ | ||
| 10 | +6qxXPVrBs+MD+zXk9/IgMTEtCpDhDVNdy1bEsiguEeUFOIvDCDqN4DN1iWy5i1Xn | ||
| 11 | +aJTYp/JPbGqohp9XJ1vQPhQin5s0el21OxW61xJRR12Y2VAxKpmwXC5SdAT+z7bY | ||
| 12 | +k2TXbujyP68MZKmnruhouRy5gtFwZpehGgoycuBWrwG2S2iEvJy7AsPFe90wEbQb | ||
| 13 | +4xYjOtkCgYEA30jPvOurvRyM5Kpl6zhN9E1x4kqtuJsuRvGCqXfQtVZXD2b6hkGF | ||
| 14 | +PHKVsCUco9t+86ZQZ2xoyMDuLxEelCnbktX0P8RfH/e1CqADo3NIxkd+vJsS/PYo | ||
| 15 | +wEUcEYFaTKEzJJaG1ZApf4m14scSeMvirTy3sfVyZRWhcHRB9hLknncCgYEA0yWU | ||
| 16 | +HMGC57GMXO3Wc0Bs7oaC2N7WbPk+reQ4rVxVLu1qOtpkzwpfwUFQBqn7LIpIX9Jc | ||
| 17 | +B3MFOe9ndA5jNRwECMPoMd1d9t+OkTjf3cpiPwludph/cReIho1bouW2xzuR7XO0 | ||
| 18 | +J1dLnmeYCKZQ1lKysK0bGbkRoXAz6yzK8oBc/K0CgYBV7YpstPF5rLQYB++DDz8I | ||
| 19 | +xokOQhkK00WC7cyP9VkvgBOvDL1az3o74gjzKcUU1hLMJ3QH6TOGFqFTIa537Ifg | ||
| 20 | +wU/m/mZxQf29IglkbKhUDg2a/b7X9M+H9tCvd+1NUjgBW6B2La2atF93746PSD9q | ||
| 21 | +1dQHu2KTvjhLs6Hy1iB/TwKBgQCmLU4rb5VSOmdJABqmbE8PTygN/Rtvep59B0Ag | ||
| 22 | +GKomG85ecWGjnPuNwpR0GjXHcTHS0GGDr1+uoB+gtG4Z72mxaFYHYLzCPmIbI1L1 | ||
| 23 | +YIIAMLESf6TVYfseQoSbaQV4Ogb4hfaEe+zUx51dOWAnvcBK0oKgtQoOL5t8/Kzh | ||
| 24 | +PGtypQKBgQDfMeSWp6Xztv3EAoBpuh6+T5nfcqEJ7FgkddxBVxDCJCOljDjZrjOk | ||
| 25 | +YR3Yz7n3hN/0OfXxByL+EnP3EL3sIiIvc/IKxw3E2faU8iPXWyXmYbL/vHDs5+BX | ||
| 26 | +h29DcOwAoANga1DxlQrJ6uGSb4yKkxaamTIJJMSJ5G9UUf90ie3Y2w== | ||
| 27 | +-----END RSA PRIVATE KEY----- | ||
| 28 | + |
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4Kcnt6WSfRmgyJlkhtnzCKAPWBwzArJNWs9+d6X140r1z/xHpCwTrGs2g1CaNOxsYkXzxFmTPtxjFf1gUhdq0v5ZySr4ZSKtYxSb/bMhHyuqjfVeX/QT+ddYQPeT0vdlnAHc/NjXm8OGS34a/7Ol1hCQvomPbcgB4MzVDn9yrcdrbPmXUvTPvA36u218Tzv0nG/umULdx5XObuOPlphEfZ1kWCSOCvcOYAjR+H7XlOjhqmRB/D+28Y9+iAgNGFDJu2zlS9jZScrj+LN74izAFOBOU1XzrhsuqmSBxjx2t1fTgrG7fioEbUUa2PgwM/eSMl2gU6iVXi+f7mcZDQDpr demouser@demoserver |
| @@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
| 1 | + | ||
| 2 | +class colab::cronjobs { | ||
| 3 | + | ||
| 4 | + $virtualenv_python = "/home/colab/.virtualenvs/colab/bin/python" | ||
| 5 | + $manage_colab = "$virtualenv_python colab/src/manage.py" | ||
| 6 | + | ||
| 7 | + Cron { | ||
| 8 | + user => colab, | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + cron { 'update-haystack-index': | ||
| 12 | + command => "$manage_colab update_index --age=1", | ||
| 13 | + minute => '*', | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + cron { 'rebuild-haystack-index': | ||
| 17 | + command => "$manage_colab rebuild_index --noinput", | ||
| 18 | + hour => '2', | ||
| 19 | + minute => '34', | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + cron { 'import-mailman-messages': | ||
| 23 | + command => "$manage_colab import_emails --archives_path=/usr/local/django/colab/mnt/archives/ --exclude-list=saberes-divulgacao --exclude-list=pml --exclude-list=mailman --exclude-list=lexml-anuncios", | ||
| 24 | + hour => '*', | ||
| 25 | + minute => '*', | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + file { '/mnt/mailman/': | ||
| 29 | + ensure => directory, | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + file { '/mnt/mailman/archives/': | ||
| 33 | + ensure => directory, | ||
| 34 | + require => File['/mnt/mailman/'], | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + cron { 'mount-sshfs': | ||
| 38 | + command => 'test -e /mnt/mailman/archives/flag || sshfs root@listas.interlegis.gov.br:/var/lib/mailman/archives/private /mnt/mailman/archives/ -o ro,nosuid,nodev,max_read=65536,allow_other,IdentityFile=/root/.ssh/id_rsa && touch /mnt/mailman/archives/flag', | ||
| 39 | + minute => '*/5', | ||
| 40 | + user => 'root', | ||
| 41 | + require => [ | ||
| 42 | + File['/mnt/mailman/archives/'], | ||
| 43 | + File['root-ssh-private-key'], | ||
| 44 | + Package['sshfs'], | ||
| 45 | + ], | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | +} |
puppet/modules/colab/manifests/init.pp
| @@ -11,6 +11,7 @@ class colab { | @@ -11,6 +11,7 @@ class colab { | ||
| 11 | 11 | ||
| 12 | include supervisor | 12 | include supervisor |
| 13 | include colab::requirements | 13 | include colab::requirements |
| 14 | + include colab::cronjobs | ||
| 14 | 15 | ||
| 15 | apt::ppa { 'ppa:nginx/stable': } | 16 | apt::ppa { 'ppa:nginx/stable': } |
| 16 | 17 | ||
| @@ -44,6 +45,30 @@ class colab { | @@ -44,6 +45,30 @@ class colab { | ||
| 44 | group => root, | 45 | group => root, |
| 45 | } | 46 | } |
| 46 | 47 | ||
| 48 | + file { 'root-ssh-dir': | ||
| 49 | + ensure => directory, | ||
| 50 | + mode => '0700', | ||
| 51 | + path => '/root/.ssh', | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + file { 'root-ssh-private-key': | ||
| 55 | + ensure => present, | ||
| 56 | + mode => '0600', | ||
| 57 | + path => '/root/.ssh/id_rsa', | ||
| 58 | + source => 'puppet:///modules/colab/root_id_rsa', | ||
| 59 | + owner => root, | ||
| 60 | + group => root, | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + file { 'root-ssh-public-key': | ||
| 64 | + ensure => present, | ||
| 65 | + mode => '0644', | ||
| 66 | + path => '/root/.ssh/id_rsa.pub', | ||
| 67 | + source => 'puppet:///modules/colab/root_id_rsa.pub', | ||
| 68 | + owner => root, | ||
| 69 | + group => root, | ||
| 70 | + } | ||
| 71 | + | ||
| 47 | supervisor::app { 'colab': | 72 | supervisor::app { 'colab': |
| 48 | command => '/home/colab/.virtualenvs/colab/bin/gunicorn colab.wsgi:application -c colab/gunicorn.conf.py', | 73 | command => '/home/colab/.virtualenvs/colab/bin/gunicorn colab.wsgi:application -c colab/gunicorn.conf.py', |
| 49 | directory => '/home/colab/colab/src/', | 74 | directory => '/home/colab/colab/src/', |
puppet/modules/colab/manifests/requirements.pp
| @@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
| 1 | +name 'seocam-supervisor' | ||
| 2 | +version '0.0.1' | ||
| 3 | +source 'https://github.com/TracyWebTech/puppet-supervisor' | ||
| 4 | +author 'Tracy Web Technologies' | ||
| 5 | +summary 'Install and configure Supervisord' | ||
| 6 | +description "This puppet module is used to install and configure Supervisord. It also provides a custom define to manage services (apps) using it." | ||
| 7 | +project_page 'https://github.com/TracyWebTech/puppet-supervisor' | ||
| 8 | + | ||
| 9 | +#dependency 'puppetlabs/stdlib', '>= 2.2.1' |
puppet/modules/supervisor/README.md
| @@ -16,9 +16,12 @@ Install your app using defined type supervisor::app | @@ -16,9 +16,12 @@ Install your app using defined type supervisor::app | ||
| 16 | 16 | ||
| 17 | ```puppet | 17 | ```puppet |
| 18 | supervisor::app { 'your-app-title': | 18 | supervisor::app { 'your-app-title': |
| 19 | - app_name => 'your-app-name' # Default to 'your-app-title' | ||
| 20 | - command => 'The command that will be run this app', # required | ||
| 21 | - directory => 'Path where your command will be run' # required | ||
| 22 | - user => 'User to execute this app' # Default to ubuntu | 19 | + app_name => 'your-app-name' # Default to 'your-app-title' |
| 20 | + command => 'The command that will be run this app', # required | ||
| 21 | + directory => 'Path where your command will be run' # required | ||
| 22 | + user => 'User to execute this app' # Default to ubuntu | ||
| 23 | + startsecs => 'The total number of seconds which the program needs to stay running after a startup to consider the start successful' # Default to undef | ||
| 24 | + stopwaitsecs => 'The number of seconds to wait for the OS to return a SIGCHILD to supervisord after the program has been sent a stopsignal', # Default to undef | ||
| 25 | + priority => 'The relative priority of the program in the start and shutdown ordering' # Default to undef | ||
| 23 | } | 26 | } |
| 24 | -``` | ||
| 25 | \ No newline at end of file | 27 | \ No newline at end of file |
| 28 | +``` |
puppet/modules/supervisor/files/debian-isnok
| @@ -1,217 +0,0 @@ | @@ -1,217 +0,0 @@ | ||
| 1 | -#! /bin/sh | ||
| 2 | -# | ||
| 3 | -# supervisor built from skeleton /etc/init.d/ script. | ||
| 4 | -# | ||
| 5 | -# skeleton by Miquel van Smoorenburg <miquels@cistron.nl>. | ||
| 6 | -# Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>. | ||
| 7 | -# Further changes by Javier Fernandez-Sanguino <jfs@debian.org>. | ||
| 8 | -# More changes by Konstantin Martini <isnok@tuxcode.org>. | ||
| 9 | -# | ||
| 10 | -# Version: @(#)supervisor 0.8 25-Jun-2013 isnok@tuxcode.org | ||
| 11 | -# | ||
| 12 | -### BEGIN INIT INFO | ||
| 13 | -# Provides: supervisor | ||
| 14 | -# Required-Start: $remote_fs $network $named | ||
| 15 | -# Required-Stop: $remote_fs $network $named | ||
| 16 | -# Default-Start: 2 3 4 5 | ||
| 17 | -# Default-Stop: 0 1 6 | ||
| 18 | -# Short-Description: Start/stop supervisord | ||
| 19 | -# Description: Start/stop supervisor daemon and its configured | ||
| 20 | -# subprocesses. | ||
| 21 | -### END INIT INFO | ||
| 22 | - | ||
| 23 | - | ||
| 24 | -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
| 25 | -#DAEMON=/usr/bin/supervisord # Debian package version (presently 3.0a8-1) | ||
| 26 | -DAEMON=/usr/local/bin/supervisord # Python package index (pypi) version (3.0b1) | ||
| 27 | -NAME=supervisord | ||
| 28 | -DESC="supervisord" | ||
| 29 | - | ||
| 30 | -CONFIGFILE=/etc/supervisord.conf # the supervisord config file | ||
| 31 | -SUPERVISORCTL=/usr/local/bin/supervisorctl # used for reload command(s) | ||
| 32 | -#SUPERVISORCTL=/usr/bin/supervisorctl # again: official deb version | ||
| 33 | - | ||
| 34 | -if [ ! -x $DAEMON ]; then | ||
| 35 | - echo "ERROR: Not executable: $DAEMON" | ||
| 36 | - exit 0 | ||
| 37 | -fi | ||
| 38 | - | ||
| 39 | -LOGDIR=/var/log/supervisor | ||
| 40 | -PIDFILE=/var/run/$NAME.pid | ||
| 41 | -DODTIME=5 # Time to wait for the server to die, in seconds | ||
| 42 | - # If this value is set too low you might not | ||
| 43 | - # let some servers to die gracefully and | ||
| 44 | - # 'restart' will not work. | ||
| 45 | - | ||
| 46 | -# fix some args for certain commands | ||
| 47 | -DAEMON_ARGS="-c$CONFIGFILE" | ||
| 48 | -CTL_ARGS="-c$CONFIGFILE" | ||
| 49 | -STARTSTOP_ARGS="--quiet --pidfile $PIDFILE --exec $DAEMON" | ||
| 50 | - | ||
| 51 | -# Include supervisor defaults if available | ||
| 52 | -if [ -r /etc/default/supervisor ]; then | ||
| 53 | - . /etc/default/supervisor | ||
| 54 | -fi | ||
| 55 | - | ||
| 56 | -set -e | ||
| 57 | - | ||
| 58 | -dod_sleep () { | ||
| 59 | - if [ -n "$DODTIME" ]; then | ||
| 60 | - sleep "$DODTIME"s | ||
| 61 | - fi | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | -running_pid () { | ||
| 65 | - # Check if a pid's cmdline contains a string (name). | ||
| 66 | - # This should work for all users. | ||
| 67 | - pid="$1" | ||
| 68 | - name="$2" | ||
| 69 | - if [ -z "$pid" ]; then | ||
| 70 | - return 1 # no pid given | ||
| 71 | - fi | ||
| 72 | - if [ ! -d /proc/"$pid" ]; then | ||
| 73 | - return 1 # no /proc/$pid directory | ||
| 74 | - fi | ||
| 75 | - if cat /proc/"$pid"/cmdline | tr "\000" "\n"| grep -q "$name"; then | ||
| 76 | - return 0 | ||
| 77 | - else | ||
| 78 | - return 1 # $pid does not match $name | ||
| 79 | - fi | ||
| 80 | -} | ||
| 81 | - | ||
| 82 | -running () { | ||
| 83 | - # Check if DAEMON is running by examining $PIDFILE. | ||
| 84 | - # If this succeeds, it sets $pid (a side effect being used). | ||
| 85 | - | ||
| 86 | - if [ ! -f "$PIDFILE" ]; then | ||
| 87 | - return 1 # No pidfile, probably no daemon present. | ||
| 88 | - fi | ||
| 89 | - # Now, obtain the pid and check it's /proc cmdline: | ||
| 90 | - pid="$(cat $PIDFILE)" | ||
| 91 | - if running_pid "$pid" "$DAEMON"; then | ||
| 92 | - return 0 | ||
| 93 | - else | ||
| 94 | - return 1 | ||
| 95 | - fi | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -normal_start () { | ||
| 99 | - start-stop-daemon $STARTSTOP_ARGS --start \ | ||
| 100 | - -- "$DAEMON_ARGS" $DAEMON_OPTS | ||
| 101 | - if [ ! -f "$PIDFILE" ]; then | ||
| 102 | - sleep 1 # grace time to create PIDFILE | ||
| 103 | - fi | ||
| 104 | -} | ||
| 105 | - | ||
| 106 | -normal_stop () { | ||
| 107 | - #start-stop-daemon $STARTSTOP_ARGS --stop --oknodo | ||
| 108 | - "$SUPERVISORCTL" $CTL_ARGS shutdown | ||
| 109 | -} | ||
| 110 | - | ||
| 111 | -force_stop () { | ||
| 112 | - # Forcefully stop a running DAEMON. | ||
| 113 | - if running; then | ||
| 114 | - kill -15 "$pid" | ||
| 115 | - dod_sleep | ||
| 116 | - # Check again, try harder if needed. | ||
| 117 | - if running; then | ||
| 118 | - kill -9 "$pid" | ||
| 119 | - dod_sleep | ||
| 120 | - if running; then | ||
| 121 | - echo "Unable to kill running $NAME process (pid=$pid)!" | ||
| 122 | - exit 1 | ||
| 123 | - fi | ||
| 124 | - fi | ||
| 125 | - fi | ||
| 126 | - rm -f "$PIDFILE" | ||
| 127 | - return 0 | ||
| 128 | -} | ||
| 129 | - | ||
| 130 | -ctl_reload () { | ||
| 131 | - # make supervisord reload it's config | ||
| 132 | - if [ -x "$SUPERVISORCTL" ]; then | ||
| 133 | - "$SUPERVISORCTL" $CTL_ARGS reload | ||
| 134 | - else | ||
| 135 | - return 1 | ||
| 136 | - fi | ||
| 137 | -} | ||
| 138 | - | ||
| 139 | -ctl_status () { | ||
| 140 | - # show stati of supervised processes. | ||
| 141 | - # do not mind if this fails. | ||
| 142 | - "$SUPERVISORCTL" $CTL_ARGS status | ||
| 143 | -} | ||
| 144 | - | ||
| 145 | -case "$1" in | ||
| 146 | - start) | ||
| 147 | - echo -n "Starting $DESC: " | ||
| 148 | - normal_start | ||
| 149 | - if running; then | ||
| 150 | - echo "$NAME." | ||
| 151 | - else | ||
| 152 | - echo "ERROR." | ||
| 153 | - fi | ||
| 154 | - ;; | ||
| 155 | - stop) | ||
| 156 | - echo -n "Stopping $DESC: " | ||
| 157 | - if normal_stop; then | ||
| 158 | - echo "$NAME." | ||
| 159 | - else | ||
| 160 | - echo "ERROR." | ||
| 161 | - fi | ||
| 162 | - ;; | ||
| 163 | - restart) | ||
| 164 | - echo "Restarting $DESC..." | ||
| 165 | - "$0" stop && "$0" start | ||
| 166 | - ;; | ||
| 167 | - force-stop) | ||
| 168 | - echo -n "Forcefully stopping $DESC: " | ||
| 169 | - force_stop | ||
| 170 | - if running; then | ||
| 171 | - echo "$NAME." | ||
| 172 | - else | ||
| 173 | - echo "ERROR." | ||
| 174 | - fi | ||
| 175 | - ;; | ||
| 176 | - reload|force-reload) | ||
| 177 | - # | ||
| 178 | - # If the daemon can reload its config files on the fly | ||
| 179 | - # for example by sending it SIGHUP, do it here. | ||
| 180 | - # | ||
| 181 | - # If the daemon responds to changes in its config file | ||
| 182 | - # directly anyway, make this a do-nothing entry. | ||
| 183 | - # | ||
| 184 | - echo "Reloading $DESC: " | ||
| 185 | - if ctl_reload; then | ||
| 186 | - echo "$NAME." | ||
| 187 | - else | ||
| 188 | - echo "ERROR." | ||
| 189 | - fi | ||
| 190 | - ;; | ||
| 191 | - #force-reload) | ||
| 192 | - # | ||
| 193 | - # If the "reload" option is implemented, move the "force-reload" | ||
| 194 | - # option to the "reload" entry above. If not, "force-reload" is | ||
| 195 | - # just the same as "restart" except that it does nothing if the | ||
| 196 | - # daemon isn't already running. | ||
| 197 | - # Check wether $DAEMON is running. If so, restart. | ||
| 198 | - #echo "Not implemented." | ||
| 199 | - #;; | ||
| 200 | - status) | ||
| 201 | - echo -n "$NAME is " | ||
| 202 | - if running; then | ||
| 203 | - echo "running" | ||
| 204 | -# ctl_status | ||
| 205 | - else | ||
| 206 | - echo "not running." | ||
| 207 | - exit 1 | ||
| 208 | - fi | ||
| 209 | - ;; | ||
| 210 | - *) | ||
| 211 | - N=/etc/init.d/"$NAME" | ||
| 212 | - echo "Usage: $N {start|stop|restart|reload|status|force-stop}" >&2 | ||
| 213 | - exit 1 | ||
| 214 | - ;; | ||
| 215 | -esac | ||
| 216 | - | ||
| 217 | -exit 0 |
| @@ -0,0 +1,217 @@ | @@ -0,0 +1,217 @@ | ||
| 1 | +#! /bin/sh | ||
| 2 | +# | ||
| 3 | +# supervisor built from skeleton /etc/init.d/ script. | ||
| 4 | +# | ||
| 5 | +# skeleton by Miquel van Smoorenburg <miquels@cistron.nl>. | ||
| 6 | +# Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>. | ||
| 7 | +# Further changes by Javier Fernandez-Sanguino <jfs@debian.org>. | ||
| 8 | +# More changes by Konstantin Martini <isnok@tuxcode.org>. | ||
| 9 | +# | ||
| 10 | +# Version: @(#)supervisor 0.8 25-Jun-2013 isnok@tuxcode.org | ||
| 11 | +# | ||
| 12 | +### BEGIN INIT INFO | ||
| 13 | +# Provides: supervisor | ||
| 14 | +# Required-Start: $remote_fs $network $named | ||
| 15 | +# Required-Stop: $remote_fs $network $named | ||
| 16 | +# Default-Start: 2 3 4 5 | ||
| 17 | +# Default-Stop: 0 1 6 | ||
| 18 | +# Short-Description: Start/stop supervisord | ||
| 19 | +# Description: Start/stop supervisor daemon and its configured | ||
| 20 | +# subprocesses. | ||
| 21 | +### END INIT INFO | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
| 25 | +#DAEMON=/usr/bin/supervisord # Debian package version (presently 3.0a8-1) | ||
| 26 | +DAEMON=/usr/local/bin/supervisord # Python package index (pypi) version (3.0b1) | ||
| 27 | +NAME=supervisord | ||
| 28 | +DESC="supervisord" | ||
| 29 | + | ||
| 30 | +CONFIGFILE=/etc/supervisord.conf # the supervisord config file | ||
| 31 | +SUPERVISORCTL=/usr/local/bin/supervisorctl # used for reload command(s) | ||
| 32 | +#SUPERVISORCTL=/usr/bin/supervisorctl # again: official deb version | ||
| 33 | + | ||
| 34 | +if [ ! -x $DAEMON ]; then | ||
| 35 | + echo "ERROR: Not executable: $DAEMON" | ||
| 36 | + exit 0 | ||
| 37 | +fi | ||
| 38 | + | ||
| 39 | +LOGDIR=/var/log/supervisor | ||
| 40 | +PIDFILE=/var/run/$NAME.pid | ||
| 41 | +DODTIME=5 # Time to wait for the server to die, in seconds | ||
| 42 | + # If this value is set too low you might not | ||
| 43 | + # let some servers to die gracefully and | ||
| 44 | + # 'restart' will not work. | ||
| 45 | + | ||
| 46 | +# fix some args for certain commands | ||
| 47 | +DAEMON_ARGS="-c$CONFIGFILE" | ||
| 48 | +CTL_ARGS="-c$CONFIGFILE" | ||
| 49 | +STARTSTOP_ARGS="--quiet --pidfile $PIDFILE --exec $DAEMON" | ||
| 50 | + | ||
| 51 | +# Include supervisor defaults if available | ||
| 52 | +if [ -r /etc/default/supervisor ]; then | ||
| 53 | + . /etc/default/supervisor | ||
| 54 | +fi | ||
| 55 | + | ||
| 56 | +set -e | ||
| 57 | + | ||
| 58 | +dod_sleep () { | ||
| 59 | + if [ -n "$DODTIME" ]; then | ||
| 60 | + sleep "$DODTIME"s | ||
| 61 | + fi | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +running_pid () { | ||
| 65 | + # Check if a pid's cmdline contains a string (name). | ||
| 66 | + # This should work for all users. | ||
| 67 | + pid="$1" | ||
| 68 | + name="$2" | ||
| 69 | + if [ -z "$pid" ]; then | ||
| 70 | + return 1 # no pid given | ||
| 71 | + fi | ||
| 72 | + if [ ! -d /proc/"$pid" ]; then | ||
| 73 | + return 1 # no /proc/$pid directory | ||
| 74 | + fi | ||
| 75 | + if cat /proc/"$pid"/cmdline | tr "\000" "\n"| grep -q "$name"; then | ||
| 76 | + return 0 | ||
| 77 | + else | ||
| 78 | + return 1 # $pid does not match $name | ||
| 79 | + fi | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +running () { | ||
| 83 | + # Check if DAEMON is running by examining $PIDFILE. | ||
| 84 | + # If this succeeds, it sets $pid (a side effect being used). | ||
| 85 | + | ||
| 86 | + if [ ! -f "$PIDFILE" ]; then | ||
| 87 | + return 1 # No pidfile, probably no daemon present. | ||
| 88 | + fi | ||
| 89 | + # Now, obtain the pid and check it's /proc cmdline: | ||
| 90 | + pid="$(cat $PIDFILE)" | ||
| 91 | + if running_pid "$pid" "$DAEMON"; then | ||
| 92 | + return 0 | ||
| 93 | + else | ||
| 94 | + return 1 | ||
| 95 | + fi | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +normal_start () { | ||
| 99 | + start-stop-daemon $STARTSTOP_ARGS --start \ | ||
| 100 | + -- "$DAEMON_ARGS" $DAEMON_OPTS | ||
| 101 | + if [ ! -f "$PIDFILE" ]; then | ||
| 102 | + sleep 1 # grace time to create PIDFILE | ||
| 103 | + fi | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +normal_stop () { | ||
| 107 | + #start-stop-daemon $STARTSTOP_ARGS --stop --oknodo | ||
| 108 | + "$SUPERVISORCTL" $CTL_ARGS shutdown | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +force_stop () { | ||
| 112 | + # Forcefully stop a running DAEMON. | ||
| 113 | + if running; then | ||
| 114 | + kill -15 "$pid" | ||
| 115 | + dod_sleep | ||
| 116 | + # Check again, try harder if needed. | ||
| 117 | + if running; then | ||
| 118 | + kill -9 "$pid" | ||
| 119 | + dod_sleep | ||
| 120 | + if running; then | ||
| 121 | + echo "Unable to kill running $NAME process (pid=$pid)!" | ||
| 122 | + exit 1 | ||
| 123 | + fi | ||
| 124 | + fi | ||
| 125 | + fi | ||
| 126 | + rm -f "$PIDFILE" | ||
| 127 | + return 0 | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +ctl_reload () { | ||
| 131 | + # make supervisord reload it's config | ||
| 132 | + if [ -x "$SUPERVISORCTL" ]; then | ||
| 133 | + "$SUPERVISORCTL" $CTL_ARGS reload | ||
| 134 | + else | ||
| 135 | + return 1 | ||
| 136 | + fi | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +ctl_status () { | ||
| 140 | + # show stati of supervised processes. | ||
| 141 | + # do not mind if this fails. | ||
| 142 | + "$SUPERVISORCTL" $CTL_ARGS status | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +case "$1" in | ||
| 146 | + start) | ||
| 147 | + echo -n "Starting $DESC: " | ||
| 148 | + normal_start | ||
| 149 | + if running; then | ||
| 150 | + echo "$NAME." | ||
| 151 | + else | ||
| 152 | + echo "ERROR." | ||
| 153 | + fi | ||
| 154 | + ;; | ||
| 155 | + stop) | ||
| 156 | + echo -n "Stopping $DESC: " | ||
| 157 | + if normal_stop; then | ||
| 158 | + echo "$NAME." | ||
| 159 | + else | ||
| 160 | + echo "ERROR." | ||
| 161 | + fi | ||
| 162 | + ;; | ||
| 163 | + restart) | ||
| 164 | + echo "Restarting $DESC..." | ||
| 165 | + "$0" stop && "$0" start | ||
| 166 | + ;; | ||
| 167 | + force-stop) | ||
| 168 | + echo -n "Forcefully stopping $DESC: " | ||
| 169 | + force_stop | ||
| 170 | + if running; then | ||
| 171 | + echo "$NAME." | ||
| 172 | + else | ||
| 173 | + echo "ERROR." | ||
| 174 | + fi | ||
| 175 | + ;; | ||
| 176 | + reload|force-reload) | ||
| 177 | + # | ||
| 178 | + # If the daemon can reload its config files on the fly | ||
| 179 | + # for example by sending it SIGHUP, do it here. | ||
| 180 | + # | ||
| 181 | + # If the daemon responds to changes in its config file | ||
| 182 | + # directly anyway, make this a do-nothing entry. | ||
| 183 | + # | ||
| 184 | + echo "Reloading $DESC: " | ||
| 185 | + if ctl_reload; then | ||
| 186 | + echo "$NAME." | ||
| 187 | + else | ||
| 188 | + echo "ERROR." | ||
| 189 | + fi | ||
| 190 | + ;; | ||
| 191 | + #force-reload) | ||
| 192 | + # | ||
| 193 | + # If the "reload" option is implemented, move the "force-reload" | ||
| 194 | + # option to the "reload" entry above. If not, "force-reload" is | ||
| 195 | + # just the same as "restart" except that it does nothing if the | ||
| 196 | + # daemon isn't already running. | ||
| 197 | + # Check wether $DAEMON is running. If so, restart. | ||
| 198 | + #echo "Not implemented." | ||
| 199 | + #;; | ||
| 200 | + status) | ||
| 201 | + echo -n "$NAME is " | ||
| 202 | + if running; then | ||
| 203 | + echo "running" | ||
| 204 | +# ctl_status | ||
| 205 | + else | ||
| 206 | + echo "not running." | ||
| 207 | + exit 1 | ||
| 208 | + fi | ||
| 209 | + ;; | ||
| 210 | + *) | ||
| 211 | + N=/etc/init.d/"$NAME" | ||
| 212 | + echo "Usage: $N {start|stop|restart|reload|status|force-stop}" >&2 | ||
| 213 | + exit 1 | ||
| 214 | + ;; | ||
| 215 | +esac | ||
| 216 | + | ||
| 217 | +exit 0 |
| @@ -0,0 +1,170 @@ | @@ -0,0 +1,170 @@ | ||
| 1 | +#! /bin/sh | ||
| 2 | +# | ||
| 3 | +# Downloaded from: | ||
| 4 | +# http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/supervisor/trusty/view/head:/debian/supervisor.init | ||
| 5 | +# | ||
| 6 | +# skeleton example file to build /etc/init.d/ scripts. | ||
| 7 | +# This file should be used to construct scripts for /etc/init.d. | ||
| 8 | +# | ||
| 9 | +# Written by Miquel van Smoorenburg <miquels@cistron.nl>. | ||
| 10 | +# Modified for Debian | ||
| 11 | +# by Ian Murdock <imurdock@gnu.ai.mit.edu>. | ||
| 12 | +# Further changes by Javier Fernandez-Sanguino <jfs@debian.org> | ||
| 13 | +# | ||
| 14 | +# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl | ||
| 15 | +# | ||
| 16 | +### BEGIN INIT INFO | ||
| 17 | +# Provides: supervisor | ||
| 18 | +# Required-Start: $remote_fs $network $named | ||
| 19 | +# Required-Stop: $remote_fs $network $named | ||
| 20 | +# Default-Start: 2 3 4 5 | ||
| 21 | +# Default-Stop: 0 1 6 | ||
| 22 | +# Short-Description: Start/stop supervisor | ||
| 23 | +# Description: Start/stop supervisor daemon and its configured | ||
| 24 | +# subprocesses. | ||
| 25 | +### END INIT INFO | ||
| 26 | + | ||
| 27 | +. /lib/lsb/init-functions | ||
| 28 | + | ||
| 29 | +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
| 30 | +DAEMON=/usr/local/bin/supervisord | ||
| 31 | +NAME=supervisord | ||
| 32 | +DESC=supervisor | ||
| 33 | + | ||
| 34 | +test -x $DAEMON || exit 0 | ||
| 35 | + | ||
| 36 | +LOGDIR=/var/log/supervisor | ||
| 37 | +PIDFILE=/var/run/$NAME.pid | ||
| 38 | +DODTIME=5 # Time to wait for the server to die, in seconds | ||
| 39 | + # If this value is set too low you might not | ||
| 40 | + # let some servers to die gracefully and | ||
| 41 | + # 'restart' will not work | ||
| 42 | + | ||
| 43 | +# Include supervisor defaults if available | ||
| 44 | +if [ -f /etc/default/supervisor ] ; then | ||
| 45 | + . /etc/default/supervisor | ||
| 46 | +fi | ||
| 47 | +DAEMON_OPTS="-c /etc/supervisord.conf $DAEMON_OPTS" | ||
| 48 | + | ||
| 49 | +set -e | ||
| 50 | + | ||
| 51 | +running_pid() | ||
| 52 | +{ | ||
| 53 | + # Check if a given process pid's cmdline matches a given name | ||
| 54 | + pid=$1 | ||
| 55 | + name=$2 | ||
| 56 | + [ -z "$pid" ] && return 1 | ||
| 57 | + [ ! -d /proc/$pid ] && return 1 | ||
| 58 | + (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1 | ||
| 59 | + return 0 | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +running() | ||
| 63 | +{ | ||
| 64 | +# Check if the process is running looking at /proc | ||
| 65 | +# (works for all users) | ||
| 66 | + | ||
| 67 | + # No pidfile, probably no daemon present | ||
| 68 | + [ ! -f "$PIDFILE" ] && return 1 | ||
| 69 | + # Obtain the pid and check it against the binary name | ||
| 70 | + pid=`cat $PIDFILE` | ||
| 71 | + running_pid $pid $DAEMON || return 1 | ||
| 72 | + return 0 | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +force_stop() { | ||
| 76 | +# Forcefully kill the process | ||
| 77 | + [ ! -f "$PIDFILE" ] && return | ||
| 78 | + if running ; then | ||
| 79 | + kill -15 $pid | ||
| 80 | + # Is it really dead? | ||
| 81 | + [ -n "$DODTIME" ] && sleep "$DODTIME"s | ||
| 82 | + if running ; then | ||
| 83 | + kill -9 $pid | ||
| 84 | + [ -n "$DODTIME" ] && sleep "$DODTIME"s | ||
| 85 | + if running ; then | ||
| 86 | + echo "Cannot kill $LABEL (pid=$pid)!" | ||
| 87 | + exit 1 | ||
| 88 | + fi | ||
| 89 | + fi | ||
| 90 | + fi | ||
| 91 | + rm -f $PIDFILE | ||
| 92 | + return 0 | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +case "$1" in | ||
| 96 | + start) | ||
| 97 | + echo -n "Starting $DESC: " | ||
| 98 | + start-stop-daemon --start --quiet --pidfile $PIDFILE \ | ||
| 99 | + --startas $DAEMON -- $DAEMON_OPTS | ||
| 100 | + test -f $PIDFILE || sleep 1 | ||
| 101 | + if running ; then | ||
| 102 | + echo "$NAME." | ||
| 103 | + else | ||
| 104 | + echo " ERROR." | ||
| 105 | + fi | ||
| 106 | + ;; | ||
| 107 | + stop) | ||
| 108 | + echo -n "Stopping $DESC: " | ||
| 109 | + start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE | ||
| 110 | + echo "$NAME." | ||
| 111 | + ;; | ||
| 112 | + force-stop) | ||
| 113 | + echo -n "Forcefully stopping $DESC: " | ||
| 114 | + force_stop | ||
| 115 | + if ! running ; then | ||
| 116 | + echo "$NAME." | ||
| 117 | + else | ||
| 118 | + echo " ERROR." | ||
| 119 | + fi | ||
| 120 | + ;; | ||
| 121 | + #reload) | ||
| 122 | + # | ||
| 123 | + # If the daemon can reload its config files on the fly | ||
| 124 | + # for example by sending it SIGHUP, do it here. | ||
| 125 | + # | ||
| 126 | + # If the daemon responds to changes in its config file | ||
| 127 | + # directly anyway, make this a do-nothing entry. | ||
| 128 | + # | ||
| 129 | + # echo "Reloading $DESC configuration files." | ||
| 130 | + # start-stop-daemon --stop --signal 1 --quiet --pidfile \ | ||
| 131 | + # /var/run/$NAME.pid --exec $DAEMON | ||
| 132 | + #;; | ||
| 133 | + force-reload) | ||
| 134 | + # | ||
| 135 | + # If the "reload" option is implemented, move the "force-reload" | ||
| 136 | + # option to the "reload" entry above. If not, "force-reload" is | ||
| 137 | + # just the same as "restart" except that it does nothing if the | ||
| 138 | + # daemon isn't already running. | ||
| 139 | + # check wether $DAEMON is running. If so, restart | ||
| 140 | + start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \ | ||
| 141 | + --startas $DAEMON \ | ||
| 142 | + && $0 restart \ | ||
| 143 | + || exit 0 | ||
| 144 | + ;; | ||
| 145 | + restart) | ||
| 146 | + echo -n "Restarting $DESC: " | ||
| 147 | + start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE | ||
| 148 | + [ -n "$DODTIME" ] && sleep $DODTIME | ||
| 149 | + start-stop-daemon --start --quiet --pidfile $PIDFILE \ | ||
| 150 | + --startas $DAEMON -- $DAEMON_OPTS | ||
| 151 | + echo "$NAME." | ||
| 152 | + ;; | ||
| 153 | + status) | ||
| 154 | + echo -n "$LABEL is " | ||
| 155 | + if running ; then | ||
| 156 | + echo "running" | ||
| 157 | + else | ||
| 158 | + echo " not running." | ||
| 159 | + exit 1 | ||
| 160 | + fi | ||
| 161 | + ;; | ||
| 162 | + *) | ||
| 163 | + N=/etc/init.d/$NAME | ||
| 164 | + # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 | ||
| 165 | + echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2 | ||
| 166 | + exit 1 | ||
| 167 | + ;; | ||
| 168 | +esac | ||
| 169 | + | ||
| 170 | +exit 0 |
puppet/modules/supervisor/manifests/app.pp
| @@ -3,6 +3,9 @@ define supervisor::app ( | @@ -3,6 +3,9 @@ define supervisor::app ( | ||
| 3 | $command, | 3 | $command, |
| 4 | $directory, | 4 | $directory, |
| 5 | $user = 'ubuntu', | 5 | $user = 'ubuntu', |
| 6 | + $startsecs = undef, | ||
| 7 | + $stopwaitsecs = undef, | ||
| 8 | + $priority = undef, | ||
| 6 | ) { | 9 | ) { |
| 7 | 10 | ||
| 8 | $conf_file = "supervisor_${app_name}" | 11 | $conf_file = "supervisor_${app_name}" |
puppet/modules/supervisor/manifests/init.pp
| @@ -16,8 +16,13 @@ class supervisor { | @@ -16,8 +16,13 @@ class supervisor { | ||
| 16 | subscribe => File['/etc/supervisord.conf'], | 16 | subscribe => File['/etc/supervisord.conf'], |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | + case $operatingsystem { | ||
| 20 | + debian: { $supervisord_conf = "puppet:///modules/supervisor/debian-isnok-initscript" } | ||
| 21 | + ubuntu: { $supervisord_conf = "puppet:///modules/supervisor/ubuntu-initscript" } | ||
| 22 | + } | ||
| 23 | + | ||
| 19 | file { '/etc/init.d/supervisord': | 24 | file { '/etc/init.d/supervisord': |
| 20 | - source => 'puppet:///modules/supervisor/debian-isnok', | 25 | + source => $supervisord_conf, |
| 21 | mode => '0755', | 26 | mode => '0755', |
| 22 | } | 27 | } |
| 23 | 28 |
puppet/modules/supervisor/templates/supervisor.conf.erb
| @@ -5,3 +5,12 @@ user=<%= @user %> | @@ -5,3 +5,12 @@ user=<%= @user %> | ||
| 5 | autostart=true | 5 | autostart=true |
| 6 | autorestart=true | 6 | autorestart=true |
| 7 | redirect_stderr=True | 7 | redirect_stderr=True |
| 8 | +<%- if @startsecs -%> | ||
| 9 | +startsecs=<%= @startsecs %> | ||
| 10 | +<%- end -%> | ||
| 11 | +<%- if @stopwaitsecs -%> | ||
| 12 | +stopwaitsecs=<%= @stopwaitsecs %> | ||
| 13 | +<%- end -%> | ||
| 14 | +<%- if @priority -%> | ||
| 15 | +priority=<%= @priority %> | ||
| 16 | +<%- end -%> |