Merge branch 'console' into 'master'

Support for serial text consoles

this PR is for following:
issue/528

to have it enabled, you need smth like:
```
parameters:
  linux:
    system:
      console:
        ttyS0:
          autologin: root
          rate: 115200
          term: xterm
```

See merge request !10
diff --git a/README.rst b/README.rst
index cbcaf8d..cd43da2 100644
--- a/README.rst
+++ b/README.rst
@@ -131,6 +131,11 @@
         console:
           tty1:
             autologin: root
+          # Enable serial console
+          ttyS0:
+            autologin: root
+            rate: 115200
+            term: xterm
 
 To disable set autologin to `false`.
 
diff --git a/linux/files/tty.upstart b/linux/files/tty.upstart
new file mode 100644
index 0000000..43b190a
--- /dev/null
+++ b/linux/files/tty.upstart
@@ -0,0 +1,14 @@
+# {{ name }} - getty
+#
+# This service maintains a getty on tty1 from the point the system is
+# started until it is shut down again.
+
+start on stopped rc RUNLEVEL=[2345] and (
+            not-container or
+            container CONTAINER=lxc or
+            container CONTAINER=lxc-libvirt)
+
+stop on runlevel [!2345]
+
+respawn
+exec /sbin/getty{% if tty.get('autologin', False) %} --autologin {{ tty.autologin }}{% endif %} -8 {{ tty.get('rate', 38400) }} {{ name }}{% if tty.term is defined %} {{ tty.term }}{% endif %}
diff --git a/linux/system/console.sls b/linux/system/console.sls
index a0715a1..bba8c1c 100644
--- a/linux/system/console.sls
+++ b/linux/system/console.sls
@@ -5,18 +5,24 @@
 
 {%- for tty_name, console in system.console.iteritems() %}
 
-{%- if console.autologin %}
-autologin_{{ tty_name }}_enable:
-  cmd.run:
-  - name: "sed -i 's|/sbin/getty|/sbin/getty --autologin {{ console.autologin }}|g' /etc/init/{{ tty_name }}.conf"
-  - unless: "grep 'autologin' /etc/init/{{ tty_name }}.conf"
-{%- else %}
-autologin_{{ tty_name }}_disable:
-  cmd.run:
-  - name: "sed -i 's| \-\-autologin [a-zA-Z0-9]*||g' /etc/init/{{ tty_name }}.conf"
-  - onlyif: "grep 'autologin' /etc/init/{{ tty_name }}.conf"
+{%- if grains['init'] == 'upstart' %}
+{{ tty_name }}_service_file:
+  file.managed:
+    - name: /etc/init/{{ tty_name }}.conf
+    - source: salt://linux/files/tty.upstart
+    - template: jinja
+    - defaults:
+        name: {{ tty_name }}
+        tty: {{ console }}
 {%- endif %}
 
+{{ tty_name }}_service:
+  service.running:
+    - enable: true
+    - name: {{ tty_name }}
+    - watch:
+      - file: {{ tty_name }}_service_file
+
 {%- endfor %}
 
 {%- endif %}
diff --git a/tests/pillar/system.sls b/tests/pillar/system.sls
index 2bebcba..f804a7e 100644
--- a/tests/pillar/system.sls
+++ b/tests/pillar/system.sls
@@ -10,7 +10,11 @@
       enabled: false
     console:
       tty0:
-        autologin: true
+        autologin: root
+      ttyS0:
+        autologin: root
+        rate: 115200
+        term: xterm
     prompt:
       default: "test01.local$"
     motd: