Creates systemd service for APIs
[src/app-framework-main.git] / conf / unit / generate-unit-conf / afm-unit
1 divert(-1)
2 dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4:
3 -----------------------------------------------------------------------
4 -- Set the comment character of m4 to ; instead of #
5 -- This is needed for substitution within lines starting with #
6 changecom( ';')
7
8 -----------------------------------------------------------------------
9 -- 
10 define( `X_EMITS', 1)
11 define( `X_DIVERTS', `divert(eval(-!X_EMITS()))')
12 define( `X_PUSH_DIVERTS', `pushdef(`X_EMITS', eval(X_EMITS() && $1))X_DIVERTS()')
13
14 define( `X_IF', `pushdef(`X_COND', $1)X_PUSH_DIVERTS($1)')
15 define( `X_ELSE', `popdef(`X_EMITS')X_PUSH_DIVERTS(eval(!X_COND))')
16 define( `X_ELIF', `X_ELSE()X_IF($1)')
17 define( `X_ENDIF', `popdef(`X_EMITS')popdef(`X_COND')X_DIVERTS()')
18
19 define( `IF', `pushdef(`ELSE',`X_ELSE()')pushdef(`ELIF',`X_ELIF($1)')pushdef(`ENDIF',`X_ENDIF()popdef(`ELSE',`ELIF',`ENDIF')')X_IF($1)')
20
21 -----------------------------------------------------------------------
22 -- 
23 define( `MUSTACH_ON', `ifelse(`$2',,,`{{#$1}}`$2'{{/$1}}')ifelse(`$3',,,`{{^$1}}`$3'{{/$1}}')')
24 define( `MUSTACH_IF', `{{#$1}}pushdef(`ELSE',`{{/$1}}{{^$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')')
25 define( `MUSTACH_IF_NOT', `{{^$1}}pushdef(`ELSE',`{{/$1}}{{#$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')')
26
27 -----------------------------------------------------------------------
28 -- 
29 define( `PERM', `urn:AGL:permission:$1')
30 define( `REQPERM', `required-permission.PERM($1)')
31
32 define( `ON_PERM', `MUSTACH_ON(REQPERM($1),$2,$3)')
33 define( `IF_PERM', `MUSTACH_IF(REQPERM($1))')
34 define( `IF_NOT_PERM', `MUSTACH_IF_NOT(REQPERM($1))')
35
36 define( `ON_CONTENT', `MUSTACH_ON(content.type=$1,$2,$3)')
37 define( `IF_CONTENT', `MUSTACH_IF(content.type=$1)')
38 define( `IF_NOT_CONTENT', `MUSTACH_IF_NOT(content.type=$1)')
39
40 define( `ON_VALUE', `MUSTACH_ON(value=$1,$2,$3)')
41 define( `IF_VALUE', `MUSTACH_IF(value=$1)')
42 define( `IF_NOT_VALUE', `MUSTACH_IF_NOT(value=$1)')
43
44 -----------------------------------------------------------------------
45 -- 
46  when home screen will use real ids
47  use TARGET={{:id}}--{{:ver}}--{{:#target}}
48  instead of TARGET={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}
49
50 define( `TARGET', `{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}')
51 define( `UNIT_NAME_BASE', `afm-ON_PERM(`:public:hidden', `service', `appli')-{{:id}}--{{:ver}}--{{:#target}}@')
52 define( `UNIT_NAME_SERVICE', `UNIT_NAME_BASE%i.service')
53 define( `UNIT_NAME_API_BASE', `afm-api-$1')
54 define( `UNIT_NAME_API_SERVICE', `UNIT_NAME_API_BASE($1)@$2.service')
55 define( `UNIT_NAME_API_SOCKET', `UNIT_NAME_API_BASE($1)@$2.socket')
56 define( `APP_DATA_DIR', `/home/%i/app-data')
57 define( `USER_RUN_DIR', `@afm_users_rundir@/%i')
58 define( `DEBUGGING_DIR', `@afm_platform_rundir@/debug')
59
60 -----------------------------------------------------------------------
61 -- 
62 define( `ON_AGL_DEVEL', `ifdef(`AGL_DEVEL', $1, $2)')
63 define( `IF_AGL_DEVEL', `IF(ON_AGL_DEVEL(1,0))')
64
65 divert(0)dnl
66 ;---------------------------------------------------------------------------------
67 ; File:
68 ;
69 ;    afm-unit.conf
70 ;
71 ; Mode:
72 ;
73 ;    ON_AGL_DEVEL(DEVEL, RELEASE)
74 ;
75 ; Role:
76 ;
77 ;    Configure how installation of widget produces unit files for systemd
78 ;
79 ; Processing and format:
80 ;
81 ;    1. File load
82 ;
83 ;           Lines beginning with ; are firstly removed
84 ;
85 ;    2. File instantiation
86 ;
87 ;           Mustache (extended) substitutions are applied using JSON
88 ;           data deduced from config.xml file of the widget.
89 ;
90 ;    3. Extraction of units
91 ;
92 ;           Extract produced units, pack it (remove empty lines and directives)
93 ;
94 ; Directives:
95 ;
96 ;    Any directive occupy one whole line starting with %
97 ;
98 ;     - %nl
99 ;
100 ;             produce an empty line at the end
101 ;
102 ;     - %begin systemd-unit
103 ;     - %end systemd-unit
104 ;
105 ;             delimit the produced unit
106 ;
107 ;     - %systemd-unit user
108 ;     - %systemd-unit system
109 ;
110 ;             tells the kind of unit (user/system)
111 ;
112 ;     - %systemd-unit service NAME
113 ;     - %systemd-unit socket NAME
114 ;
115 ;             gives the name and type of the unit
116 ;
117 ;     - %systemd-unit wanted-by NAME
118 ;
119 ;             tells to install a link to unit in the wants of NAME
120 ;
121 ; Setting variables:
122 ;
123 ;    AFM uses the feature of systemd that completely ignores options prefixed
124 ;    with X-
125 ;
126 ;    Consequently, options starting with X-AFM- are recorded as public data
127 ;    about the application and options starting starting with X-AFM-- are
128 ;    recorded as private data.
129 ;
130 ;    Examples:
131 ;
132 ;        X-AFM-description={{description}}
133 ;
134 ;              Records the description of the unit in the field "description"
135 ;              of both the public and private object describing the unit.
136 ;
137 ;        X-AFM--wgtdir={{:#metadata.install-dir}}
138 ;
139 ;              Records the installation directory path in the field "wgtdir"
140 ;              of the private object only.
141 ;
142 ;---------------------------------------------------------------------------------
143 {{#targets}}
144
145 include(service.inc)
146
147 include(provided.inc)
148
149 {{/targets}}
150 ;---------------------------------------------------------------------------------
151 ; End of file afm-unit.conf mode ON_AGL_DEVEL(DEVEL, RELEASE)
152 ;---------------------------------------------------------------------------------