@@ -0,0 +1,4 @@ | |||
*.retry | |||
*.pyc | |||
__PYCACHE__ | |||
@@ -1 +0,0 @@ | |||
10.0.2.46 |
@@ -0,0 +1,17 @@ | |||
[upstart:children] | |||
upstart-desktops | |||
upstart-servers | |||
[upstart-desktops] | |||
desk1204 ansible_host=10.9.0.50 ansible_user=vlad ansible_password=123 ansible_sudo_password=123 | |||
desk1404 ansible_host=10.9.0.51 ansible_user=vlad ansible_password=123 ansible_sudo_password=123 | |||
[upstart-servers] | |||
serv1204 ansible_host=10.9.0.48 ansible_user=vlad ansible_password=123 ansible_sudo_password=123 | |||
serv1404 ansible_host=10.9.0.49 ansible_user=vlad ansible_password=123 ansible_sudo_password=123 | |||
[systemd:children] | |||
systemd-desktops | |||
[systemd-desktops] | |||
desk1804 ansible_host=10.9.0.155 ansible_user=vlad ansible_password=123 ansible_sudo_password=123 |
@@ -0,0 +1,10 @@ | |||
--- | |||
- name: Minimum packages for Debian-like | |||
apt: name="{{ item }}" state=present update_cache=yes | |||
become: yes | |||
become_method: sudo | |||
with_items: | |||
- python | |||
- mc | |||
- htop | |||
when: preinstall is defined |
@@ -0,0 +1,13 @@ | |||
import time | |||
import multiprocessing | |||
import child_process | |||
print("Hello world") | |||
processes = [None] * 4 | |||
for i in range(4): | |||
processes[i] = multiprocessing.Process(target=child_process.run, args=(i,)) | |||
processes[i].start() | |||
for i in range(4): | |||
processes[i].join() |
@@ -0,0 +1,12 @@ | |||
import time | |||
import multiprocessing | |||
def test(info): | |||
while 1: | |||
print 'TEST', info[0], info[1] | |||
def run(proc_id): | |||
pool = multiprocessing.Pool(processes=4) | |||
pool.map(test, [(proc_id, i) for i in range(4)]) | |||
pool.close() | |||
pool.join() |
@@ -0,0 +1,30 @@ | |||
--- | |||
- name: Install app.py | |||
copy: | |||
src: files/app.py | |||
dest: /opt/app.py | |||
owner: root | |||
group: root | |||
mode: 0644 | |||
- name: Install child_process.py | |||
copy: | |||
src: files/child_process.py | |||
dest: /opt/child_process.py | |||
owner: root | |||
group: root | |||
mode: 0644 | |||
- name: Create service file for upstart Ubuntu versions | |||
template: src=upstart-service.template.j2 dest=/etc/init/{{service_name}}.conf backup=no mode=0644 | |||
when: ansible_distribution == 'Ubuntu' and (ansible_distribution_version == "14.04" or ansible_distribution_version == "12.04") | |||
- name: Create service file for systemd Ubuntu versions | |||
template: src=systemd-service.template.j2 dest=/etc/systemd/system/{{service_name}}.service backup=no mode=0644 | |||
when: ansible_distribution == 'Ubuntu' and (ansible_distribution_version == "16.04" or ansible_distribution_version == "18.04") | |||
- name: Enable service {{ service_name }} | |||
service: name={{ service_name }} enabled=yes | |||
- name: Start service {{ service_name }} | |||
service: name={{ service_name }} state=restarted |
@@ -0,0 +1,15 @@ | |||
[Unit] | |||
Description={{service_description}} | |||
Requires=network.target | |||
After=syslog.target network.target | |||
TimeoutStopSpec=60 | |||
[Service] | |||
Type=simple | |||
ExecStart={{interpretator}} {{installation_path}}/app.py | |||
ExecReload=/bin/kill -HUP $MAINPID | |||
WorkingDirectory={{installation_path}} | |||
User=vlad | |||
Restart=always | |||
RestartSec=30 | |||
[Install] | |||
WantedBy=multi-user.target |
@@ -0,0 +1,25 @@ | |||
description "{{ service_description }}" | |||
start on runlevel [2345] | |||
stop on runlevel [!2345] | |||
expect fork | |||
kill timeout 60 # when upstart issued a stop, send SIGTERM, wait 60 sec before sending SIGKILL | |||
respawn | |||
respawn limit 5 30 #try 5 times within 60 seconds, or giveup | |||
script | |||
echo $$ > {{installation_path}}/app.pid | |||
exec {{ interpretator }} {{ installation_path}}/app.py | |||
end script | |||
pre-start script | |||
touch {{installation_path}}/app.log | |||
echo "\n[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> {{installation_path}}/app.log | |||
end script | |||
pre-stop script | |||
rm -f {{installation_path}}/app.pid | |||
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> {{installation_path}}/app.log | |||
end script |
@@ -0,0 +1,4 @@ | |||
service_name: app | |||
service_description: my app.py | |||
installation_path: /opt | |||
interpretator: /usr/bin/python |
@@ -0,0 +1,4 @@ | |||
--- | |||
- name: test | |||
debug: | |||
msg: "OS Version: {{ansible_distribution }} {{ansible_distribution_release}} {{ansible_distribution_version}}" |
@@ -0,0 +1,6 @@ | |||
- hosts: all | |||
roles: | |||
- test | |||
- preinstall | |||
- { role: set_service, become: yes } | |||