]> WPIA git - infra.git/blob - modules/motion/manifests/container.pp
add: motion system from source
[infra.git] / modules / motion / manifests / container.pp
1 class motion::container($container){
2   include container::contained;
3   include container::no_ssh;
4
5   package{ ['python3', 'python3-pip',  'virtualenv', 'libpq-dev']:
6     ensure => 'installed'
7   }
8   user{'motion':
9     ensure => present,
10     home => '/home/motion',
11     system => 'yes'
12   } ->
13   file{'/home/motion':
14     ensure => 'directory',
15     owner => 'motion',
16     group => 'motion'
17   }
18   file{'/motion-socket':
19     owner => 'motion',
20     group => 'motion'
21   }
22   package{'git':
23   } ->
24   exec{'clone motion':
25     command => '/usr/bin/git clone https://code.wpia.club/motion.git',
26     cwd => '/home/motion',
27     creates => '/home/motion/motion/.git',
28     user => 'motion'
29   } ->
30   file{'/home/motion/motion/__pycache__':
31     ensure => directory,
32     owner => motion,
33     group => motion
34   } ->
35   file{'/home/motion/motion/config.py':
36     content => epp("motion/config.py", {user => $container, password => 'motion'}),
37     owner => motion,
38     group => motion
39   } ->
40   exec {'motion-virtualenv':
41     command => '/usr/bin/virtualenv -p python3 motion',
42     cwd => '/home/motion',
43     creates => '/home/motion/motion/bin/activate',
44     user => 'motion',
45     require => [Package['virtualenv'], Package['python3-pip'], Exec['clone motion']],
46     before =>  Service['motion.service'],
47   } ->
48   exec{'pip dependencies':
49     command => '/bin/bash -c "source motion/bin/activate; /home/motion/motion/bin/pip install -r motion/requirements.txt"',
50     require => [Exec['motion-virtualenv'],Package['python3-pip']],
51     cwd => '/home/motion',
52     timeout => 0,
53     user => 'motion',
54     creates => '/home/motion/motion/bin/flask'
55   }
56
57   exec{'install uwsgi':
58     command => '/bin/bash -c "source motion/bin/activate; /home/motion/motion/bin/pip install uwsgi"',
59     require => Exec['motion-virtualenv'],
60     cwd => '/home/motion',
61     timeout => 0,
62     user => 'motion',
63     creates => '/home/motion/motion/bin/uwsgi'
64   }
65
66   file{'/home/motion/motion.ini':
67     source => 'puppet:///modules/motion/motion.ini'
68   } ->
69   systemd::unit_file {'motion.service':
70     ensure => 'file',
71     source => 'puppet:///modules/motion/motion.service',
72     notify => Service['motion.service'],
73     require => Exec['install uwsgi']
74   }
75   service{'motion.service':
76     ensure => 'running',
77     provider => 'systemd',
78     enable => true,
79     require => [Exec['pip dependencies'],Exec['systemctl-daemon-reload']],
80   }
81
82 }