mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
deployment, wohoo. also, cleanup of old stuff.
This commit is contained in:
23
deploy/README
Normal file
23
deploy/README
Normal file
@@ -0,0 +1,23 @@
|
||||
To use the playbook, create a yaml file credentials.yml
|
||||
with the following content (you can use vault to encrypt):
|
||||
|
||||
jid: yourjabber@id.to.use
|
||||
password: yourpasswordforthisjabber
|
||||
rooms:
|
||||
- debianforum.de@chat.debianforum.de # your channel
|
||||
- spielwiese@chat.debianforum.de # bot playground
|
||||
bot_nickname: T800 # your bots nickname
|
||||
bot_owner: MASTER # your nickname (for info and admin stuff)
|
||||
|
||||
|
||||
Further, you need a hosts-file with the following content:
|
||||
|
||||
[bots]
|
||||
yourserverip
|
||||
# or alternatively,
|
||||
derpy_name ansible_host=yourserverip
|
||||
|
||||
|
||||
There is deploy.sh which I created so I have a single file to
|
||||
deploy my stuff - it uses a virtualenv (py2!) with ansible and
|
||||
some vault file declaration.
|
||||
4
deploy/deploy.sh
Normal file
4
deploy/deploy.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
source ~/urlbot-native/venv/bin/activate
|
||||
|
||||
ansible-playbook -i hosts deploy.yml --vault-password-file ~/.vaultpass -D
|
||||
86
deploy/deploy.yml
Normal file
86
deploy/deploy.yml
Normal file
@@ -0,0 +1,86 @@
|
||||
- hosts: bots
|
||||
remote_user: root
|
||||
tasks:
|
||||
- name: create user for bot
|
||||
user: name=jabberbot comment="Account for the urlbot" shell=/bin/bash
|
||||
- name: local user can log in with ssh key
|
||||
authorized_key: user=jabberbot key="{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
|
||||
|
||||
- name: git, python3, virtualenv have to be installed
|
||||
apt: name="{{item}}" state=installed
|
||||
with_items:
|
||||
- git
|
||||
- python3
|
||||
- virtualenv
|
||||
- python3-virtualenv
|
||||
|
||||
- hosts: bots
|
||||
remote_user: jabberbot
|
||||
vars:
|
||||
- botrepo: http://aero2k.de/t/repos/urlbot-native.git
|
||||
- pypi_mirror: http://pypi.fcio.net/simple/
|
||||
tasks:
|
||||
- include_vars: credentials.yml
|
||||
tags: [render_config]
|
||||
- name: virtualenv for the bot
|
||||
shell: virtualenv -p python3 ~/botenv creates=~/botenv/bin/activate
|
||||
- name: virtualenv for supervisord
|
||||
shell: virtualenv -p python2 ~/svenv creates=~/svenv/bin/activate
|
||||
- name: clone repository
|
||||
git: repo="{{botrepo}}" dest=~/urlbot force=yes update=yes
|
||||
register: source_code
|
||||
- name: install bot dependencies into virtualenv
|
||||
pip: name="{{item}}" virtualenv=~/botenv extra_args="-i {{pypi_mirror}}"
|
||||
with_items:
|
||||
- sleekxmpp
|
||||
- configobj
|
||||
- name: install supervisor
|
||||
pip: name=supervisor virtualenv=~/svenv extra_args="-i {{pypi_mirror}}"
|
||||
|
||||
- name: set configuration
|
||||
lineinfile: dest=~/urlbot/local_config.ini create=yes line="{{item.key}} = {{item.value}}" regexp="^{{item.key}}.="
|
||||
with_items:
|
||||
- key: "jid"
|
||||
value: "{{jid}}"
|
||||
- key: "password"
|
||||
value: "{{password}}"
|
||||
- key: "rooms"
|
||||
value: "{{rooms | join(', ')}}"
|
||||
- key: "src-url"
|
||||
value: "{{botrepo}}"
|
||||
- key: "bot_nickname"
|
||||
value: "{{bot_nickname}}"
|
||||
- key: "bot_owner"
|
||||
value: "{{bot_owner}}"
|
||||
tags: [render_config]
|
||||
register: urlbot_config
|
||||
|
||||
- name: create supervisor config
|
||||
copy: src=supervisord.conf dest=~/supervisord.conf
|
||||
register: supervisord
|
||||
|
||||
- name: verify supervisor running
|
||||
shell: nc -z 127.0.0.1 9004; echo $? executable=/bin/bash
|
||||
register: supervisor_running
|
||||
changed_when: false
|
||||
|
||||
- name: start supervisord
|
||||
shell: source ~/svenv/bin/activate && supervisord executable=/bin/bash
|
||||
register: start_supervisor
|
||||
when: supervisord.changed or supervisor_running.stdout == "1"
|
||||
#changed_when: "'already listening' not in start_supervisor.stdout"
|
||||
|
||||
- name: activate supervisord changes
|
||||
when: supervisord.changed
|
||||
shell: source ~/svenv/bin/activate && supervisorctl reload executable=/bin/bash
|
||||
|
||||
- name: idlebot started
|
||||
supervisorctl: name=idlebot state=restarted supervisorctl_path=~/svenv/bin/supervisorctl
|
||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
|
||||
- pause: seconds=30
|
||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
|
||||
- name: urlbot started
|
||||
supervisorctl: name=bot state=restarted supervisorctl_path=~/svenv/bin/supervisorctl
|
||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
2
deploy/hosts
Normal file
2
deploy/hosts
Normal file
@@ -0,0 +1,2 @@
|
||||
[bots]
|
||||
aero2k.de ansible_host=2a01:4f8:d16:130c::2
|
||||
46
deploy/supervisord.conf
Normal file
46
deploy/supervisord.conf
Normal file
@@ -0,0 +1,46 @@
|
||||
; Sample supervisor config file.
|
||||
;
|
||||
; For more information on the config file, please see:
|
||||
; http://supervisord.org/configuration.html
|
||||
;
|
||||
; Notes:
|
||||
; - Shell expansion ("~" or "$HOME") is not supported. Environment
|
||||
; variables can be expanded using this syntax: "%(ENV_HOME)s".
|
||||
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
|
||||
|
||||
[unix_http_server]
|
||||
file=/home/jabberbot/supervisor.sock ; (the path to the socket file)
|
||||
|
||||
[inet_http_server]
|
||||
port=127.0.0.1:9004
|
||||
|
||||
[supervisord]
|
||||
logfile=/home/jabberbot/supervisord.log ; (main log file;default $CWD/supervisord.log)
|
||||
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
|
||||
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
|
||||
loglevel=info ; (log level;default info; others: debug,warn,trace)
|
||||
pidfile=/home/jabberbot/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
|
||||
nodaemon=false ; (start in foreground if true;default false)
|
||||
minfds=1024 ; (min. avail startup file descriptors;default 1024)
|
||||
minprocs=200 ; (min. avail process descriptors;default 200)
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///home/jabberbot/supervisor.sock ; use a unix:// URL for a unix socket
|
||||
|
||||
;[include]
|
||||
;files = relative/directory/*.ini
|
||||
|
||||
[program:bot]
|
||||
command=/home/jabberbot/botenv/bin/python3 /home/jabberbot/urlbot/urlbot.py
|
||||
directory=/home/jabberbot/urlbot/
|
||||
stderr_logfile=/home/jabberbot/urlbot.err
|
||||
stdout_logfile=/home/jabberbot/urlbot.log
|
||||
|
||||
[program:idlebot]
|
||||
directory=/home/jabberbot/urlbot/
|
||||
command=/home/jabberbot/botenv/bin/python3 /home/jabberbot/urlbot/idlebot.py
|
||||
stderr_logfile=/home/jabberbot/idlebot.err
|
||||
stdout_logfile=/home/jabberbot/idlebot.log
|
||||
Reference in New Issue
Block a user