From 5b801a3e7b0465f88b785a155dd430ba09c56568 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Wed, 15 May 2019 20:49:14 +0200 Subject: afm-unit.conf: Refactor its generation The process of generating the file /etc/afm-unit.conf had be reworked to be more straight forward. Before that commit, a manual operation (a "make") had to be done before committing the repository. This was not efficient, error prone and kept temporary files in conf. That commit changes it by calling m4 through cmake. Bug-AGL: SPEC-2436 Change-Id: Ia32a810286471dde8a01387d157e33277d67411d Signed-off-by: Jose Bollo --- conf/unit/CMakeLists.txt | 25 +- conf/unit/afm-unit | 109 ++++++++ conf/unit/afm-unit-debug.conf.in | 293 --------------------- conf/unit/afm-unit.conf.in | 294 ---------------------- conf/unit/binder.inc | 51 ++++ conf/unit/generate-unit-conf/Makefile | 20 -- conf/unit/generate-unit-conf/afm-unit | 109 -------- conf/unit/generate-unit-conf/binder.inc | 51 ---- conf/unit/generate-unit-conf/macros.inc | 67 ----- conf/unit/generate-unit-conf/provided-api.inc | 56 ----- conf/unit/generate-unit-conf/provided-binding.inc | 25 -- conf/unit/generate-unit-conf/service.inc | 133 ---------- conf/unit/macros.inc | 67 +++++ conf/unit/provided-api.inc | 56 +++++ conf/unit/provided-binding.inc | 25 ++ conf/unit/service.inc | 133 ++++++++++ 16 files changed, 462 insertions(+), 1052 deletions(-) create mode 100644 conf/unit/afm-unit delete mode 100644 conf/unit/afm-unit-debug.conf.in delete mode 100644 conf/unit/afm-unit.conf.in create mode 100644 conf/unit/binder.inc delete mode 100644 conf/unit/generate-unit-conf/Makefile delete mode 100644 conf/unit/generate-unit-conf/afm-unit delete mode 100644 conf/unit/generate-unit-conf/binder.inc delete mode 100644 conf/unit/generate-unit-conf/macros.inc delete mode 100644 conf/unit/generate-unit-conf/provided-api.inc delete mode 100644 conf/unit/generate-unit-conf/provided-binding.inc delete mode 100644 conf/unit/generate-unit-conf/service.inc create mode 100644 conf/unit/macros.inc create mode 100644 conf/unit/provided-api.inc create mode 100644 conf/unit/provided-binding.inc create mode 100644 conf/unit/service.inc diff --git a/conf/unit/CMakeLists.txt b/conf/unit/CMakeLists.txt index 1d11e11..7fbe6e1 100644 --- a/conf/unit/CMakeLists.txt +++ b/conf/unit/CMakeLists.txt @@ -18,15 +18,32 @@ cmake_minimum_required(VERSION 2.8) +find_program(M4EXEC m4) +mark_as_advanced(M4EXEC) + +file(GLOB in_afm_unit_list + LIST_DIRECTORIES false + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + CONFIGURE_DEPENDS + afm-unit *.inc +) +foreach(f IN LISTS in_afm_unit_list) + configure_file(${f} ${f}) + set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/afm-unit.conf APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${f}) +endforeach(f) if(AGL_DEVEL) - configure_file(afm-unit-debug.conf.in afm-unit.conf) -else() - configure_file(afm-unit.conf.in afm-unit.conf) + set(optm4 -DAGL_DEVEL) endif() +add_custom_command( + OUTPUT afm-unit.conf + COMMAND ${M4EXEC} ${optm4} -I. afm-unit > afm-unit.conf + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) +add_custom_target(unitconf ALL DEPENDS afm-unit.conf) if(NOT USE_SDK) install(DIRECTORY DESTINATION ${afm_confdir}/unit.env.d) install(DIRECTORY DESTINATION ${afm_confdir}/widget.env.d) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-unit.conf DESTINATION ${afm_confdir}) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-unit.conf DESTINATION ${afm_confdir}) endif() diff --git a/conf/unit/afm-unit b/conf/unit/afm-unit new file mode 100644 index 0000000..2a91067 --- /dev/null +++ b/conf/unit/afm-unit @@ -0,0 +1,109 @@ +divert(-1) +-------------------------------------------------------------------------------- +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: +include(macros.inc) +-- Set the comment character of m4 to ; instead of # +-- This is needed for substitution within lines starting with # +changecom( ';') +divert(0)dnl +;------------------------------------------------------------------------------- +; File: +; +; afm-unit.conf +; +; Mode: +; +; ON_AGL_DEVEL(DEVEL, RELEASE) +; +; Role: +; +; Configure how installation of widget produces unit files for systemd +; +; Processing and format: +; +; 1. File load +; +; Lines beginning with ; are firstly removed +; +; 2. File instantiation +; +; Mustache (extended) substitutions are applied using JSON +; data deduced from config.xml file of the widget. +; +; 3. Extraction of units +; +; Extract produced units, pack it (remove empty lines and directives) +; +; Directives: +; +; Any directive occupy one whole line starting with % +; +; - %nl +; +; produce an empty line at the end +; +; - %begin systemd-unit +; - %end systemd-unit +; +; delimit the produced unit +; +; - %systemd-unit user +; - %systemd-unit system +; +; tells the kind of unit (user/system) +; +; - %systemd-unit service NAME +; - %systemd-unit socket NAME +; +; gives the name and type of the unit +; +; - %systemd-unit wanted-by NAME +; +; tells to install a link to unit in the wants of NAME +; +; Setting variables: +; +; AFM uses the feature of systemd that completely ignores options prefixed +; with X- +; +; Consequently, options starting with X-AFM- are recorded as public data +; about the application and options starting starting with X-AFM-- are +; recorded as private data. +; +; Examples: +; +; X-AFM-description={{description}} +; +; Records the description of the unit in the field "description" +; of both the public and private object describing the unit. +; +; X-AFM--wgtdir={{:#metadata.install-dir}} +; +; Records the installation directory path in the field "wgtdir" +; of the private object only. +; +;------------------------------------------------------------------------------- +;---- F O R E A C H T A R G E T ---- +;------------------------------------------------------------------------------- +{{#targets}} +;------------------------------------------------------------------------------- +include(service.inc) +;------------------------------------------------------------------------------- +;---- F O R E A C H P R O V I D E D A P I S ---- +;------------------------------------------------------------------------------- +{{#provided-api}} +{{#value=ws|auto}} +include(provided-api.inc) +{{/value=ws|auto}} +{{/provided-api}} +;------------------------------------------------------------------------------- +;---- F O R E A C H P R O V I D E D B I N D I N G ---- +;------------------------------------------------------------------------------- +{{#provided-binding}} +include(provided-binding.inc) +{{/provided-binding}} +;------------------------------------------------------------------------------- +{{/targets}} +;------------------------------------------------------------------------------- +; End of file afm-unit.conf mode ON_AGL_DEVEL(DEVEL, RELEASE) +;------------------------------------------------------------------------------- diff --git a/conf/unit/afm-unit-debug.conf.in b/conf/unit/afm-unit-debug.conf.in deleted file mode 100644 index 15c794c..0000000 --- a/conf/unit/afm-unit-debug.conf.in +++ /dev/null @@ -1,293 +0,0 @@ -;------------------------------------------------------------------------------- -; File: -; -; afm-unit.conf -; -; Mode: -; -; DEVEL -; -; Role: -; -; Configure how installation of widget produces unit files for systemd -; -; Processing and format: -; -; 1. File load -; -; Lines beginning with ; are firstly removed -; -; 2. File instantiation -; -; Mustache (extended) substitutions are applied using JSON -; data deduced from config.xml file of the widget. -; -; 3. Extraction of units -; -; Extract produced units, pack it (remove empty lines and directives) -; -; Directives: -; -; Any directive occupy one whole line starting with % -; -; - %nl -; -; produce an empty line at the end -; -; - %begin systemd-unit -; - %end systemd-unit -; -; delimit the produced unit -; -; - %systemd-unit user -; - %systemd-unit system -; -; tells the kind of unit (user/system) -; -; - %systemd-unit service NAME -; - %systemd-unit socket NAME -; -; gives the name and type of the unit -; -; - %systemd-unit wanted-by NAME -; -; tells to install a link to unit in the wants of NAME -; -; Setting variables: -; -; AFM uses the feature of systemd that completely ignores options prefixed -; with X- -; -; Consequently, options starting with X-AFM- are recorded as public data -; about the application and options starting starting with X-AFM-- are -; recorded as private data. -; -; Examples: -; -; X-AFM-description={{description}} -; -; Records the description of the unit in the field "description" -; of both the public and private object describing the unit. -; -; X-AFM--wgtdir={{:#metadata.install-dir}} -; -; Records the installation directory path in the field "wgtdir" -; of the private object only. -; -;------------------------------------------------------------------------------- -;---- F O R E A C H T A R G E T ---- -;------------------------------------------------------------------------------- -{{#targets}} -;------------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -;---- M A I N P A R T O F T H E S E R V I C E ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%nl -%systemd-unit system -%systemd-unit service afm-{{#required-permission.@afm_prefix@permission::public:hidden}}service{{/required-permission.@afm_prefix@permission::public:hidden}}{{^required-permission.@afm_prefix@permission::public:hidden}}appli{{/required-permission.@afm_prefix@permission::public:hidden}}-{{:id}}--{{:ver}}--{{:#target}}@ -[Unit] -Description={{description}} -X-AFM-description={{description}} -X-AFM-name={{name.content}} -X-AFM-shortname={{name.short}} -X-AFM-id={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} -X-AFM-version={{:version}} -X-AFM-author={{author.content}} -X-AFM-author-email={{author.email}} -X-AFM-width={{width}} -X-AFM-height={{height}} -{{#icon}} -X-AFM-icon={{:#metadata.install-dir}}/{{:src}} -{{/icon}} -X-AFM--ID={{:id}} -X-AFM--target-name={{:#target}} -X-AFM--content={{content.src}} -X-AFM--type={{content.type}} -X-AFM--wgtdir={{:#metadata.install-dir}} -X-AFM--workdir=/home/%i/app-data/{{:id}} -X-AFM--visibility={{#required-permission.@afm_prefix@permission::public:hidden}}hidden{{/required-permission.@afm_prefix@permission::public:hidden}}{{^required-permission.@afm_prefix@permission::public:hidden}}visible{{/required-permission.@afm_prefix@permission::public:hidden}} -%nl -Requires=afm-user-session@%i.target -After=user@%i.service -After=Network.target -# Adds check to smack -ConditionSecurity=smack -%nl -# Automatic bound to required api -{{#required-binding}} -{{#value=extern}} -BindsTo=afm-link-{{name}}@%i.service -After=afm-link-{{name}}@%i.service -{{/value=extern}} -{{/required-binding}} -{{#required-api}} -{{#value=auto|ws}} -BindsTo=afm-api-{{name}}@%i.service -After=afm-api-{{name}}@%i.service -{{/value=auto|ws}} -{{/required-api}} -{{#provided-api}} -{{#value=ws|auto}} -Requires=afm-api-{{name}}@%i.socket -After=afm-api-{{name}}@%i.socket -{{/value=ws|auto}} -{{/provided-api}} -%nl -[Service] -EnvironmentFile=-@afm_confdir@/unit.env.d/* -EnvironmentFile=-@afm_confdir@/widget.env.d/{{:id}}/* -SmackProcessLabel=User::App::{{:id}} -SuccessExitStatus=0 SIGKILL -User=%i -Slice=user-%i.slice -CapabilityBoundingSet= -#AmbientCapabilities= -{{#required-permission.@afm_prefix@permission::platform:no-oom}}OOMScoreAdjust=-500{{/required-permission.@afm_prefix@permission::platform:no-oom}} -{{#required-permission.@afm_prefix@permission::partner:real-time}}IOSchedulingClass=realtime{{/required-permission.@afm_prefix@permission::partner:real-time}} -{{#required-permission.@afm_prefix@permission::public:display}}SupplementaryGroups=display{{/required-permission.@afm_prefix@permission::public:display}} -{{^required-permission.@afm_prefix@permission::public:syscall:clock}}SystemCallFilter=~@clock{{/required-permission.@afm_prefix@permission::public:syscall:clock}} -%nl -WorkingDirectory=-/home/%i/app-data/{{:id}} -ExecStartPre=/bin/mkdir -p /home/%i/app-data/{{:id}} -Environment=AFM_ID={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} -Environment=AFM_APP_INSTALL_DIR={{:#metadata.install-dir}} -Environment=AFM_WORKDIR=/home/%i/app-data/{{:id}} -Environment=AFM_WSAPI_DIR=@afm_users_rundir@/%i/apis/ws -Environment=PATH=/usr/sbin:/usr/bin:/sbin:/bin:{{:#metadata.install-dir}}/bin -Environment=LD_LIBRARY_PATH={{:#metadata.install-dir}}/lib -Environment=XDG_DATA_HOME=/home/%i/app-data/{{:id}} -Environment=XDG_CONFIG_HOME=/home/%i/app-data/{{:id}} -Environment=XDG_CACHE_HOME=/home/%i/app-data/{{:id}} -Environment=XDG_RUNTIME_DIR=@afm_users_rundir@/%i -Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=@afm_users_rundir@/%i/bus -; Needed to enable debug -EnvironmentFile=-@afm_platform_rundir@/debug/{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}.env -SyslogIdentifier=afbd-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} -StandardInput=null -StandardOutput=journal -StandardError=journal -;------------------------------------------------------------------------------- -;---- text/html application/vnd.agl.native application/vnd.agl.service ---- -;------------------------------------------------------------------------------- -{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} -X-AFM-http-port={{:#metatarget.http-port}} -Type=notify -ExecStart=/usr/bin/afb-daemon \ - --name afbd-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} \ - --rootdir={{:#metadata.install-dir}} \ - --workdir=/home/%i/app-data/{{id}} \ - --verbose \ - --verbose \ - --monitoring \ - --port={{:#metatarget.http-port}} \ - --token=HELLO \ - --roothttp={{#content.type=application/vnd.agl.service}}.{{/content.type=application/vnd.agl.service}}{{^content.type=application/vnd.agl.service}}{{#required-permission.@afm_prefix@permission::public:no-htdocs}}.{{/required-permission.@afm_prefix@permission::public:no-htdocs}}{{^required-permission.@afm_prefix@permission::public:no-htdocs}}htdocs{{/required-permission.@afm_prefix@permission::public:no-htdocs}}{{/content.type=application/vnd.agl.service}} \ - {{#required-permission.@afm_prefix@permission::public:applications:read}}--alias=/icons:{{:#metadata.icons-dir}}{{/required-permission.@afm_prefix@permission::public:applications:read}} \ - {{#required-api}} \ - {{#value=auto|ws}}--ws-client=unix:@afm_users_rundir@/%i/apis/ws/{{name}}{{/value=auto|ws}} \ - {{#value=dbus}}--dbus-client={{name}}{{/value=dbus}} \ - {{#value=cloud}}--cloud-client={{name}}{{/value=cloud}} \ - {{#value=local}}--binding={{:#metadata.install-dir}}/{{name}}{{/value=local}} \ - {{#value=tcp}}--ws-client=tcp:{{name}}{{/value=tcp}} \ - {{/required-api}} \ - {{#required-binding}} \ - {{#value=local}}--binding={{:#metadata.install-dir}}/{{name}}{{/value=local}} \ - {{#value=extern}}--binding=@afm_users_rundir@/%i/apis/link/{{name}}{{/value=extern}} \ - {{/required-binding}} \ - {{#provided-api}} \ - {{#value=auto|ws}}--ws-server=sd:{{name}}{{/value=auto|ws}} \ - {{#value=dbus}}--dbus-server={{name}}{{/value=dbus}} \ - {{#value=tcp}}--ws-server=tcp:{{name}}{{/value=tcp}} \ - {{/provided-api}} \ - {{#content.type=text/html}}--exec /usr/bin/web-runtime http://localhost:@p/{{content.src}}?token=@t{{/content.type=text/html}} \ - {{#content.type=application/vnd.agl.native}}--exec {{:#metadata.install-dir}}/{{content.src}} @p @t{{/content.type=application/vnd.agl.native}} -{{/content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} -;------------------------------------------------------------------------------- -;---- application/x-executable ---- -;------------------------------------------------------------------------------- -{{#content.type=application/x-executable}} -ExecStart={{:#metadata.install-dir}}/{{content.src}} -{{/content.type=application/x-executable}} -{{#required-permission.@afm_prefix@permission::system:run-by-default}} -;------------------------------------------------------------------------------- -; auto start -;------------------------------------------------------------------------------- -[Install] -WantedBy=afm-user-session@.target -%systemd-unit wanted-by afm-user-session@.target -{{/required-permission.@afm_prefix@permission::system:run-by-default}} -%end systemd-unit -;------------------------------------------------------------------------------- -;---- F O R E A C H P R O V I D E D A P I S ---- -;------------------------------------------------------------------------------- -{{#provided-api}} -{{#value=ws|auto}} -;------------------------------------------------------------------------------- -;---- T H E S E R V I C E O F T H E A P I ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%systemd-unit system -%systemd-unit service afm-api-{{name}}@ -[Unit] -Description=Provides api {{name}} for user %i -X-AFM-API-TYPE={{value}} -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -Requires=afm-api-{{name}}@%i.socket -After=afm-api-{{name}}@%i.socket -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/true -%end systemd-unit -;------------------------------------------------------------------------------- -;---- T H E S O C K E T O F T H E A P I ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%systemd-unit system -%systemd-unit socket afm-api-{{name}}@ -[Unit] -Description=Provides websocket api {{name}} for user %i -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -DefaultDependencies=no -[Socket] -SmackLabel=* -SmackLabelIPIn=System -SmackLabelIPOut=System -ListenStream=@afm_users_rundir@/%i/apis/ws/{{name}} -FileDescriptorName={{name}} -Service=afm-{{#required-permission.@afm_prefix@permission::public:hidden}}service{{/required-permission.@afm_prefix@permission::public:hidden}}{{^required-permission.@afm_prefix@permission::public:hidden}}appli{{/required-permission.@afm_prefix@permission::public:hidden}}-{{:id}}--{{:ver}}--{{:#target}}@%i.service -%end systemd-unit -{{/value=ws|auto}} -{{/provided-api}} -;------------------------------------------------------------------------------- -;---- F O R E A C H P R O V I D E D B I N D I N G ---- -;------------------------------------------------------------------------------- -{{#provided-binding}} -;------------------------------------------------------------------------------- -;---- T H E S E R V I C E O F T H E B I N D I N G ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%systemd-unit system -%systemd-unit service afm-link-{{name}}@ -[Unit] -Description=Provides binding {{name}} for user %i -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/ln -sf {{:#metadata.install-dir}}/{{value}} @afm_users_rundir@/%i/apis/link/{{name}} -%end systemd-unit -{{/provided-binding}} -;------------------------------------------------------------------------------- -{{/targets}} -;------------------------------------------------------------------------------- -; End of file afm-unit.conf mode DEVEL -;------------------------------------------------------------------------------- diff --git a/conf/unit/afm-unit.conf.in b/conf/unit/afm-unit.conf.in deleted file mode 100644 index e9585f0..0000000 --- a/conf/unit/afm-unit.conf.in +++ /dev/null @@ -1,294 +0,0 @@ -;------------------------------------------------------------------------------- -; File: -; -; afm-unit.conf -; -; Mode: -; -; RELEASE -; -; Role: -; -; Configure how installation of widget produces unit files for systemd -; -; Processing and format: -; -; 1. File load -; -; Lines beginning with ; are firstly removed -; -; 2. File instantiation -; -; Mustache (extended) substitutions are applied using JSON -; data deduced from config.xml file of the widget. -; -; 3. Extraction of units -; -; Extract produced units, pack it (remove empty lines and directives) -; -; Directives: -; -; Any directive occupy one whole line starting with % -; -; - %nl -; -; produce an empty line at the end -; -; - %begin systemd-unit -; - %end systemd-unit -; -; delimit the produced unit -; -; - %systemd-unit user -; - %systemd-unit system -; -; tells the kind of unit (user/system) -; -; - %systemd-unit service NAME -; - %systemd-unit socket NAME -; -; gives the name and type of the unit -; -; - %systemd-unit wanted-by NAME -; -; tells to install a link to unit in the wants of NAME -; -; Setting variables: -; -; AFM uses the feature of systemd that completely ignores options prefixed -; with X- -; -; Consequently, options starting with X-AFM- are recorded as public data -; about the application and options starting starting with X-AFM-- are -; recorded as private data. -; -; Examples: -; -; X-AFM-description={{description}} -; -; Records the description of the unit in the field "description" -; of both the public and private object describing the unit. -; -; X-AFM--wgtdir={{:#metadata.install-dir}} -; -; Records the installation directory path in the field "wgtdir" -; of the private object only. -; -;------------------------------------------------------------------------------- -;---- F O R E A C H T A R G E T ---- -;------------------------------------------------------------------------------- -{{#targets}} -;------------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -;---- M A I N P A R T O F T H E S E R V I C E ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%nl -%systemd-unit system -%systemd-unit service afm-{{#required-permission.@afm_prefix@permission::public:hidden}}service{{/required-permission.@afm_prefix@permission::public:hidden}}{{^required-permission.@afm_prefix@permission::public:hidden}}appli{{/required-permission.@afm_prefix@permission::public:hidden}}-{{:id}}--{{:ver}}--{{:#target}}@ -[Unit] -Description={{description}} -X-AFM-description={{description}} -X-AFM-name={{name.content}} -X-AFM-shortname={{name.short}} -X-AFM-id={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} -X-AFM-version={{:version}} -X-AFM-author={{author.content}} -X-AFM-author-email={{author.email}} -X-AFM-width={{width}} -X-AFM-height={{height}} -{{#icon}} -X-AFM-icon={{:#metadata.install-dir}}/{{:src}} -{{/icon}} -X-AFM--ID={{:id}} -X-AFM--target-name={{:#target}} -X-AFM--content={{content.src}} -X-AFM--type={{content.type}} -X-AFM--wgtdir={{:#metadata.install-dir}} -X-AFM--workdir=/home/%i/app-data/{{:id}} -X-AFM--visibility={{#required-permission.@afm_prefix@permission::public:hidden}}hidden{{/required-permission.@afm_prefix@permission::public:hidden}}{{^required-permission.@afm_prefix@permission::public:hidden}}visible{{/required-permission.@afm_prefix@permission::public:hidden}} -%nl -Requires=afm-user-session@%i.target -After=user@%i.service -After=Network.target -# Adds check to smack -ConditionSecurity=smack -%nl -# Automatic bound to required api -{{#required-binding}} -{{#value=extern}} -BindsTo=afm-link-{{name}}@%i.service -After=afm-link-{{name}}@%i.service -{{/value=extern}} -{{/required-binding}} -{{#required-api}} -{{#value=auto|ws}} -BindsTo=afm-api-{{name}}@%i.service -After=afm-api-{{name}}@%i.service -{{/value=auto|ws}} -{{/required-api}} -{{#provided-api}} -{{#value=ws|auto}} -Requires=afm-api-{{name}}@%i.socket -After=afm-api-{{name}}@%i.socket -{{/value=ws|auto}} -{{/provided-api}} -%nl -[Service] -EnvironmentFile=-@afm_confdir@/unit.env.d/* -EnvironmentFile=-@afm_confdir@/widget.env.d/{{:id}}/* -SmackProcessLabel=User::App::{{:id}} -SuccessExitStatus=0 SIGKILL -User=%i -Slice=user-%i.slice -CapabilityBoundingSet= -#AmbientCapabilities= -{{#required-permission.@afm_prefix@permission::platform:no-oom}}OOMScoreAdjust=-500{{/required-permission.@afm_prefix@permission::platform:no-oom}} -{{#required-permission.@afm_prefix@permission::partner:real-time}}IOSchedulingClass=realtime{{/required-permission.@afm_prefix@permission::partner:real-time}} -{{#required-permission.@afm_prefix@permission::public:display}}SupplementaryGroups=display{{/required-permission.@afm_prefix@permission::public:display}} -{{^required-permission.@afm_prefix@permission::public:syscall:clock}}SystemCallFilter=~@clock{{/required-permission.@afm_prefix@permission::public:syscall:clock}} -%nl -WorkingDirectory=-/home/%i/app-data/{{:id}} -ExecStartPre=/bin/mkdir -p /home/%i/app-data/{{:id}} -Environment=AFM_ID={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} -Environment=AFM_APP_INSTALL_DIR={{:#metadata.install-dir}} -Environment=AFM_WORKDIR=/home/%i/app-data/{{:id}} -Environment=AFM_WSAPI_DIR=@afm_users_rundir@/%i/apis/ws -Environment=PATH=/usr/sbin:/usr/bin:/sbin:/bin:{{:#metadata.install-dir}}/bin -Environment=LD_LIBRARY_PATH={{:#metadata.install-dir}}/lib -Environment=XDG_DATA_HOME=/home/%i/app-data/{{:id}} -Environment=XDG_CONFIG_HOME=/home/%i/app-data/{{:id}} -Environment=XDG_CACHE_HOME=/home/%i/app-data/{{:id}} -Environment=XDG_RUNTIME_DIR=@afm_users_rundir@/%i -Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=@afm_users_rundir@/%i/bus -SyslogIdentifier=afbd-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} -StandardInput=null -StandardOutput=journal -StandardError=journal -;------------------------------------------------------------------------------- -;---- text/html application/vnd.agl.native application/vnd.agl.service ---- -;------------------------------------------------------------------------------- -{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} -{{^content.type=application/vnd.agl.service}} -X-AFM--http-port={{:#metatarget.http-port}} -{{/content.type=application/vnd.agl.service}} -Type=notify -ExecStart=/usr/bin/afb-daemon \ - --name afbd-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} \ - --rootdir={{:#metadata.install-dir}} \ - --workdir=/home/%i/app-data/{{id}} \ - {{#content.type=application/vnd.agl.service}} \ - --no-httpd \ - {{/content.type=application/vnd.agl.service}}{{^content.type=application/vnd.agl.service}} \ - --port={{:#metatarget.http-port}} \ - --random-token \ - --roothttp={{#required-permission.@afm_prefix@permission::public:no-htdocs}}.{{/required-permission.@afm_prefix@permission::public:no-htdocs}}{{^required-permission.@afm_prefix@permission::public:no-htdocs}}htdocs{{/required-permission.@afm_prefix@permission::public:no-htdocs}} \ - {{/content.type=application/vnd.agl.service}} \ - {{#required-permission.@afm_prefix@permission::public:applications:read}}--alias=/icons:{{:#metadata.icons-dir}}{{/required-permission.@afm_prefix@permission::public:applications:read}} \ - {{#required-api}} \ - {{#value=auto|ws}}--ws-client=unix:@afm_users_rundir@/%i/apis/ws/{{name}}{{/value=auto|ws}} \ - {{#value=dbus}}--dbus-client={{name}}{{/value=dbus}} \ - {{#value=cloud}}--cloud-client={{name}}{{/value=cloud}} \ - {{#value=local}}--binding={{:#metadata.install-dir}}/{{name}}{{/value=local}} \ - {{#value=tcp}}--ws-client=tcp:{{name}}{{/value=tcp}} \ - {{/required-api}} \ - {{#required-binding}} \ - {{#value=local}}--binding={{:#metadata.install-dir}}/{{name}}{{/value=local}} \ - {{#value=extern}}--binding=@afm_users_rundir@/%i/apis/link/{{name}}{{/value=extern}} \ - {{/required-binding}} \ - {{#provided-api}} \ - {{#value=auto|ws}}--ws-server=sd:{{name}}{{/value=auto|ws}} \ - {{#value=dbus}}--dbus-server={{name}}{{/value=dbus}} \ - {{#value=tcp}}--ws-server=tcp:{{name}}{{/value=tcp}} \ - {{/provided-api}} \ - {{#content.type=text/html}}--exec /usr/bin/web-runtime http://localhost:@p/{{content.src}}?token=@t{{/content.type=text/html}} \ - {{#content.type=application/vnd.agl.native}}--exec {{:#metadata.install-dir}}/{{content.src}} @p @t{{/content.type=application/vnd.agl.native}} -{{/content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} -;------------------------------------------------------------------------------- -;---- application/x-executable ---- -;------------------------------------------------------------------------------- -{{#content.type=application/x-executable}} -ExecStart={{:#metadata.install-dir}}/{{content.src}} -{{/content.type=application/x-executable}} -{{#required-permission.@afm_prefix@permission::system:run-by-default}} -;------------------------------------------------------------------------------- -; auto start -;------------------------------------------------------------------------------- -[Install] -WantedBy=afm-user-session@.target -%systemd-unit wanted-by afm-user-session@.target -{{/required-permission.@afm_prefix@permission::system:run-by-default}} -%end systemd-unit -;------------------------------------------------------------------------------- -;---- F O R E A C H P R O V I D E D A P I S ---- -;------------------------------------------------------------------------------- -{{#provided-api}} -{{#value=ws|auto}} -;------------------------------------------------------------------------------- -;---- T H E S E R V I C E O F T H E A P I ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%systemd-unit system -%systemd-unit service afm-api-{{name}}@ -[Unit] -Description=Provides api {{name}} for user %i -X-AFM-API-TYPE={{value}} -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -Requires=afm-api-{{name}}@%i.socket -After=afm-api-{{name}}@%i.socket -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/true -%end systemd-unit -;------------------------------------------------------------------------------- -;---- T H E S O C K E T O F T H E A P I ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%systemd-unit system -%systemd-unit socket afm-api-{{name}}@ -[Unit] -Description=Provides websocket api {{name}} for user %i -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -DefaultDependencies=no -[Socket] -SmackLabel=* -SmackLabelIPIn=System -SmackLabelIPOut=System -ListenStream=@afm_users_rundir@/%i/apis/ws/{{name}} -FileDescriptorName={{name}} -Service=afm-{{#required-permission.@afm_prefix@permission::public:hidden}}service{{/required-permission.@afm_prefix@permission::public:hidden}}{{^required-permission.@afm_prefix@permission::public:hidden}}appli{{/required-permission.@afm_prefix@permission::public:hidden}}-{{:id}}--{{:ver}}--{{:#target}}@%i.service -%end systemd-unit -{{/value=ws|auto}} -{{/provided-api}} -;------------------------------------------------------------------------------- -;---- F O R E A C H P R O V I D E D B I N D I N G ---- -;------------------------------------------------------------------------------- -{{#provided-binding}} -;------------------------------------------------------------------------------- -;---- T H E S E R V I C E O F T H E B I N D I N G ---- -;------------------------------------------------------------------------------- -%begin systemd-unit -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%systemd-unit system -%systemd-unit service afm-link-{{name}}@ -[Unit] -Description=Provides binding {{name}} for user %i -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/ln -sf {{:#metadata.install-dir}}/{{value}} @afm_users_rundir@/%i/apis/link/{{name}} -%end systemd-unit -{{/provided-binding}} -;------------------------------------------------------------------------------- -{{/targets}} -;------------------------------------------------------------------------------- -; End of file afm-unit.conf mode RELEASE -;------------------------------------------------------------------------------- diff --git a/conf/unit/binder.inc b/conf/unit/binder.inc new file mode 100644 index 0000000..30c25d5 --- /dev/null +++ b/conf/unit/binder.inc @@ -0,0 +1,51 @@ +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: + +IF_AGL_DEVEL +X-AFM-http-port={{:#metatarget.http-port}} +ELSE +IF_NOT_CONTENT(application/vnd.agl.service) +X-AFM--http-port={{:#metatarget.http-port}} +ENDIF +ENDIF + +Type=notify +ExecStart=/usr/bin/afb-daemon \ + --name afbd-TARGET \ + --rootdir={{:#metadata.install-dir}} \ + --workdir=APP_DATA_DIR/{{id}} \ +IF_AGL_DEVEL \ + --verbose \ + --verbose \ + --monitoring \ + --port={{:#metatarget.http-port}} \ + --token=HELLO \ + --roothttp=ON_CONTENT(application/vnd.agl.service, ., ON_PERM(:public:no-htdocs, ., htdocs)) \ +ELSE \ + IF_CONTENT(application/vnd.agl.service) \ + --no-httpd \ + ELSE \ + --port={{:#metatarget.http-port}} \ + --random-token \ + --roothttp=ON_PERM(:public:no-htdocs, ., htdocs) \ + ENDIF \ +ENDIF \ + ON_PERM(:public:applications:read, --alias=/icons:{{:#metadata.icons-dir}}) \ + {{#required-api}} \ + ON_VALUE(auto|ws, --ws-client=unix:API_PATH_WS/{{name}}) \ + ON_VALUE(dbus, --dbus-client={{name}}) \ + ON_VALUE(cloud, --cloud-client={{name}}) \ + ON_VALUE(local, --binding={{:#metadata.install-dir}}/{{name}}) \ + ON_VALUE(tcp, --ws-client=tcp:{{name}}) \ + {{/required-api}} \ + {{#required-binding}} \ + ON_VALUE(local, --binding={{:#metadata.install-dir}}/{{name}}) \ + ON_VALUE(extern, --binding=API_PATH_LINK/{{name}}) \ + {{/required-binding}} \ + {{#provided-api}} \ + ON_VALUE(auto|ws, --ws-server=sd:{{name}}) \ + ON_VALUE(dbus, --dbus-server={{name}}) \ + ON_VALUE(tcp, --ws-server=tcp:{{name}}) \ + {{/provided-api}} \ + ON_CONTENT(text/html, --exec /usr/bin/web-runtime http://localhost:@p/{{content.src}}?token=@t) \ + ON_CONTENT(application/vnd.agl.native, --exec {{:#metadata.install-dir}}/{{content.src}} @p @t) + diff --git a/conf/unit/generate-unit-conf/Makefile b/conf/unit/generate-unit-conf/Makefile deleted file mode 100644 index 51cb9c8..0000000 --- a/conf/unit/generate-unit-conf/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -.PHONY: all - -MAIN = afm-unit - -FILES = $(MAIN) $(shell ls *.inc) Makefile - -DIR = .. - -D = -DAGL_DEVEL - -all: $(DIR)/afm-unit.conf.in $(DIR)/afm-unit-debug.conf.in - -$(DIR)/afm-unit.conf.in: $(FILES) - @echo generating $@ - @m4 $< | sed '/^[ \t]*\\*[ \t]*$$/d' > $@ - -$(DIR)/afm-unit-debug.conf.in: $(FILES) - @echo generating $@ - @m4 $D $< | sed '/^[ \t]*\\*[ \t]*$$/d' > $@ - diff --git a/conf/unit/generate-unit-conf/afm-unit b/conf/unit/generate-unit-conf/afm-unit deleted file mode 100644 index 2a91067..0000000 --- a/conf/unit/generate-unit-conf/afm-unit +++ /dev/null @@ -1,109 +0,0 @@ -divert(-1) --------------------------------------------------------------------------------- -dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -include(macros.inc) --- Set the comment character of m4 to ; instead of # --- This is needed for substitution within lines starting with # -changecom( ';') -divert(0)dnl -;------------------------------------------------------------------------------- -; File: -; -; afm-unit.conf -; -; Mode: -; -; ON_AGL_DEVEL(DEVEL, RELEASE) -; -; Role: -; -; Configure how installation of widget produces unit files for systemd -; -; Processing and format: -; -; 1. File load -; -; Lines beginning with ; are firstly removed -; -; 2. File instantiation -; -; Mustache (extended) substitutions are applied using JSON -; data deduced from config.xml file of the widget. -; -; 3. Extraction of units -; -; Extract produced units, pack it (remove empty lines and directives) -; -; Directives: -; -; Any directive occupy one whole line starting with % -; -; - %nl -; -; produce an empty line at the end -; -; - %begin systemd-unit -; - %end systemd-unit -; -; delimit the produced unit -; -; - %systemd-unit user -; - %systemd-unit system -; -; tells the kind of unit (user/system) -; -; - %systemd-unit service NAME -; - %systemd-unit socket NAME -; -; gives the name and type of the unit -; -; - %systemd-unit wanted-by NAME -; -; tells to install a link to unit in the wants of NAME -; -; Setting variables: -; -; AFM uses the feature of systemd that completely ignores options prefixed -; with X- -; -; Consequently, options starting with X-AFM- are recorded as public data -; about the application and options starting starting with X-AFM-- are -; recorded as private data. -; -; Examples: -; -; X-AFM-description={{description}} -; -; Records the description of the unit in the field "description" -; of both the public and private object describing the unit. -; -; X-AFM--wgtdir={{:#metadata.install-dir}} -; -; Records the installation directory path in the field "wgtdir" -; of the private object only. -; -;------------------------------------------------------------------------------- -;---- F O R E A C H T A R G E T ---- -;------------------------------------------------------------------------------- -{{#targets}} -;------------------------------------------------------------------------------- -include(service.inc) -;------------------------------------------------------------------------------- -;---- F O R E A C H P R O V I D E D A P I S ---- -;------------------------------------------------------------------------------- -{{#provided-api}} -{{#value=ws|auto}} -include(provided-api.inc) -{{/value=ws|auto}} -{{/provided-api}} -;------------------------------------------------------------------------------- -;---- F O R E A C H P R O V I D E D B I N D I N G ---- -;------------------------------------------------------------------------------- -{{#provided-binding}} -include(provided-binding.inc) -{{/provided-binding}} -;------------------------------------------------------------------------------- -{{/targets}} -;------------------------------------------------------------------------------- -; End of file afm-unit.conf mode ON_AGL_DEVEL(DEVEL, RELEASE) -;------------------------------------------------------------------------------- diff --git a/conf/unit/generate-unit-conf/binder.inc b/conf/unit/generate-unit-conf/binder.inc deleted file mode 100644 index 30c25d5..0000000 --- a/conf/unit/generate-unit-conf/binder.inc +++ /dev/null @@ -1,51 +0,0 @@ -dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: - -IF_AGL_DEVEL -X-AFM-http-port={{:#metatarget.http-port}} -ELSE -IF_NOT_CONTENT(application/vnd.agl.service) -X-AFM--http-port={{:#metatarget.http-port}} -ENDIF -ENDIF - -Type=notify -ExecStart=/usr/bin/afb-daemon \ - --name afbd-TARGET \ - --rootdir={{:#metadata.install-dir}} \ - --workdir=APP_DATA_DIR/{{id}} \ -IF_AGL_DEVEL \ - --verbose \ - --verbose \ - --monitoring \ - --port={{:#metatarget.http-port}} \ - --token=HELLO \ - --roothttp=ON_CONTENT(application/vnd.agl.service, ., ON_PERM(:public:no-htdocs, ., htdocs)) \ -ELSE \ - IF_CONTENT(application/vnd.agl.service) \ - --no-httpd \ - ELSE \ - --port={{:#metatarget.http-port}} \ - --random-token \ - --roothttp=ON_PERM(:public:no-htdocs, ., htdocs) \ - ENDIF \ -ENDIF \ - ON_PERM(:public:applications:read, --alias=/icons:{{:#metadata.icons-dir}}) \ - {{#required-api}} \ - ON_VALUE(auto|ws, --ws-client=unix:API_PATH_WS/{{name}}) \ - ON_VALUE(dbus, --dbus-client={{name}}) \ - ON_VALUE(cloud, --cloud-client={{name}}) \ - ON_VALUE(local, --binding={{:#metadata.install-dir}}/{{name}}) \ - ON_VALUE(tcp, --ws-client=tcp:{{name}}) \ - {{/required-api}} \ - {{#required-binding}} \ - ON_VALUE(local, --binding={{:#metadata.install-dir}}/{{name}}) \ - ON_VALUE(extern, --binding=API_PATH_LINK/{{name}}) \ - {{/required-binding}} \ - {{#provided-api}} \ - ON_VALUE(auto|ws, --ws-server=sd:{{name}}) \ - ON_VALUE(dbus, --dbus-server={{name}}) \ - ON_VALUE(tcp, --ws-server=tcp:{{name}}) \ - {{/provided-api}} \ - ON_CONTENT(text/html, --exec /usr/bin/web-runtime http://localhost:@p/{{content.src}}?token=@t) \ - ON_CONTENT(application/vnd.agl.native, --exec {{:#metadata.install-dir}}/{{content.src}} @p @t) - diff --git a/conf/unit/generate-unit-conf/macros.inc b/conf/unit/generate-unit-conf/macros.inc deleted file mode 100644 index a764765..0000000 --- a/conf/unit/generate-unit-conf/macros.inc +++ /dev/null @@ -1,67 +0,0 @@ -dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: --------------------------------------------------------------------------------- --- GLOBAL IMPORTANT DEFINITIONS --------------------------------------------------------------------------------- -define( `X_EMITS', 1) -define( `X_DIVERTS', `divert(eval(-!X_EMITS()))') -define( `X_PUSH_DIVERTS', `pushdef(`X_EMITS', eval(X_EMITS() && $1))X_DIVERTS()') - -define( `X_IF', `pushdef(`X_COND', $1)X_PUSH_DIVERTS($1)') -define( `X_ELSE', `popdef(`X_EMITS')X_PUSH_DIVERTS(eval(!X_COND))') -define( `X_ELIF', `X_ELSE()X_IF($1)') -define( `X_ENDIF', `popdef(`X_EMITS')popdef(`X_COND')X_DIVERTS()') - -define( `IF', `pushdef(`ELSE',`X_ELSE()')pushdef(`ELIF',`X_ELIF($1)')pushdef(`ENDIF',`X_ENDIF()popdef(`ELSE',`ELIF',`ENDIF')')X_IF($1)') --------------------------------------------------------------------------------- --- MUSTACH SPECIFIC DEFINITIONS --------------------------------------------------------------------------------- -define( `MUSTACH_ON', `ifelse(`$2',,,`{{#$1}}`$2'{{/$1}}')ifelse(`$3',,,`{{^$1}}`$3'{{/$1}}')') -define( `MUSTACH_IF', `{{#$1}}pushdef(`ELSE',`{{/$1}}{{^$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') -define( `MUSTACH_IF_NOT', `{{^$1}}pushdef(`ELSE',`{{/$1}}{{#$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') --------------------------------------------------------------------------------- --- CONDITIONAL HELPERS --------------------------------------------------------------------------------- -define( `PERM', `@afm_prefix@permission:$1') -define( `REQPERM', `required-permission.PERM($1)') - -define( `ON_PERM', `MUSTACH_ON(REQPERM($1),$2,$3)') -define( `IF_PERM', `MUSTACH_IF(REQPERM($1))') -define( `IF_NOT_PERM', `MUSTACH_IF_NOT(REQPERM($1))') - -define( `ON_CONTENT', `MUSTACH_ON(content.type=$1,$2,$3)') -define( `IF_CONTENT', `MUSTACH_IF(content.type=$1)') -define( `IF_NOT_CONTENT', `MUSTACH_IF_NOT(content.type=$1)') - -define( `ON_VALUE', `MUSTACH_ON(value=$1,$2,$3)') -define( `IF_VALUE', `MUSTACH_IF(value=$1)') -define( `IF_NOT_VALUE', `MUSTACH_IF_NOT(value=$1)') --------------------------------------------------------------------------------- --- AFM DEFINITION --------------------------------------------------------------------------------- --- NOTE: --- when home screen will use real ids --- use TARGET={{:id}}--{{:ver}}--{{:#target}} --- instead of TARGET={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} --------------------------------------------------------------------------------- -define( `TARGET', `{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}') -define( `NEWTARGET', `{{:id}}--{{:ver}}--{{:#target}}') -define( `UNIT_NAME_BASE', `afm-ON_PERM(`:public:hidden', `service', `appli')-NEWTARGET') -define( `UNIT_NAME_SERVICE', `UNIT_NAME_BASE@%i.service') -define( `UNIT_NAME_API_BASE', `afm-api-$1') -define( `UNIT_NAME_API_SERVICE', `UNIT_NAME_API_BASE($1)@$2.service') -define( `UNIT_NAME_API_SOCKET', `UNIT_NAME_API_BASE($1)@$2.socket') -define( `UNIT_NAME_BINDING_BASE', `afm-link-$1') -define( `UNIT_NAME_BINDING_SERVICE', `UNIT_NAME_BINDING_BASE($1)@$2.service') -define( `APP_DATA_DIR', `/home/%i/app-data') -define( `USER_RUN_DIR', `@afm_users_rundir@/%i') -define( `DEBUGGING_DIR', `@afm_platform_rundir@/debug') -define( `API_PATH', `USER_RUN_DIR/apis') -define( `API_PATH_WS', `API_PATH/ws') -define( `API_PATH_LINK', `API_PATH/link') --------------------------------------------------------------------------------- --- AGL_DEVEL SPECIFIC PARTS --------------------------------------------------------------------------------- -define( `ON_AGL_DEVEL', `ifdef(`AGL_DEVEL', $1, $2)') -define( `ON_NOT_AGL_DEVEL', `ifdef(`AGL_DEVEL', $2, $1)') -define( `IF_AGL_DEVEL', `IF(ON_AGL_DEVEL(1,0))') -define( `IF_NOT_AGL_DEVEL', `IF(ON_AGL_DEVEL(0,1))') diff --git a/conf/unit/generate-unit-conf/provided-api.inc b/conf/unit/generate-unit-conf/provided-api.inc deleted file mode 100644 index bdee6c9..0000000 --- a/conf/unit/generate-unit-conf/provided-api.inc +++ /dev/null @@ -1,56 +0,0 @@ -dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -;------------------------------------------------------------------------------- -;---- T H E S E R V I C E O F T H E A P I ---- -;------------------------------------------------------------------------------- -%begin systemd-unit - -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} - -%systemd-unit system -%systemd-unit service UNIT_NAME_API_BASE({{name}})@ - -[Unit] -Description=Provides api {{name}} for user %i -X-AFM-API-TYPE={{value}} - -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service - -Requires=UNIT_NAME_API_BASE({{name}})@%i.socket -After=UNIT_NAME_API_BASE({{name}})@%i.socket - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/true - -%end systemd-unit - -;------------------------------------------------------------------------------- -;---- T H E S O C K E T O F T H E A P I ---- -;------------------------------------------------------------------------------- - -%begin systemd-unit - -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} - -%systemd-unit system -%systemd-unit socket UNIT_NAME_API_BASE({{name}})@ -[Unit] -Description=Provides websocket api {{name}} for user %i -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service -DefaultDependencies=no - -[Socket] -SmackLabel=* -SmackLabelIPIn=System -SmackLabelIPOut=System -ListenStream=API_PATH_WS/{{name}} -FileDescriptorName={{name}} -Service=UNIT_NAME_SERVICE - -%end systemd-unit - - - diff --git a/conf/unit/generate-unit-conf/provided-binding.inc b/conf/unit/generate-unit-conf/provided-binding.inc deleted file mode 100644 index 3737126..0000000 --- a/conf/unit/generate-unit-conf/provided-binding.inc +++ /dev/null @@ -1,25 +0,0 @@ -dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -;------------------------------------------------------------------------------- -;---- T H E S E R V I C E O F T H E B I N D I N G ---- -;------------------------------------------------------------------------------- -%begin systemd-unit - -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} - -%systemd-unit system -%systemd-unit service UNIT_NAME_BINDING_BASE({{name}})@ - -[Unit] -Description=Provides binding {{name}} for user %i - -Requires=afm-user-setup@%i.service -After=afm-user-setup@%i.service - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/ln -sf {{:#metadata.install-dir}}/{{value}} API_PATH_LINK/{{name}} - -%end systemd-unit - - diff --git a/conf/unit/generate-unit-conf/service.inc b/conf/unit/generate-unit-conf/service.inc deleted file mode 100644 index 88c1454..0000000 --- a/conf/unit/generate-unit-conf/service.inc +++ /dev/null @@ -1,133 +0,0 @@ -dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -;------------------------------------------------------------------------------- -;---- M A I N P A R T O F T H E S E R V I C E ---- -;------------------------------------------------------------------------------- -%begin systemd-unit - -# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} -%nl - -%systemd-unit system -%systemd-unit service UNIT_NAME_BASE@ - -[Unit] -Description={{description}} -X-AFM-description={{description}} -X-AFM-name={{name.content}} -X-AFM-shortname={{name.short}} -X-AFM-id=TARGET -X-AFM-version={{:version}} -X-AFM-author={{author.content}} -X-AFM-author-email={{author.email}} -X-AFM-width={{width}} -X-AFM-height={{height}} -{{#icon}} -X-AFM-icon={{:#metadata.install-dir}}/{{:src}} -{{/icon}} -X-AFM--ID={{:id}} -X-AFM--target-name={{:#target}} -X-AFM--content={{content.src}} -X-AFM--type={{content.type}} -X-AFM--wgtdir={{:#metadata.install-dir}} -X-AFM--workdir=APP_DATA_DIR/{{:id}} -X-AFM--visibility=ON_PERM(`:public:hidden', `hidden', `visible') -%nl - -Requires=afm-user-session@%i.target -After=user@%i.service -After=Network.target - -# Adds check to smack -ConditionSecurity=smack -%nl - -# Automatic bound to required api -{{#required-binding}} -{{#value=extern}} -BindsTo=UNIT_NAME_BINDING_SERVICE({{name}},%i) -After=UNIT_NAME_BINDING_SERVICE({{name}},%i) -{{/value=extern}} -{{/required-binding}} -{{#required-api}} -{{#value=auto|ws}} -BindsTo=UNIT_NAME_API_SERVICE({{name}},%i) -After=UNIT_NAME_API_SERVICE({{name}},%i) -{{/value=auto|ws}} -{{/required-api}} -{{#provided-api}} -{{#value=ws|auto}} -Requires=UNIT_NAME_API_SOCKET({{name}},%i) -After=UNIT_NAME_API_SOCKET({{name}},%i) -{{/value=ws|auto}} -{{/provided-api}} - -%nl - -[Service] -EnvironmentFile=-@afm_confdir@/unit.env.d/* -EnvironmentFile=-@afm_confdir@/widget.env.d/{{:id}}/* -SmackProcessLabel=User::App::{{:id}} -SuccessExitStatus=0 SIGKILL - -User=%i -Slice=user-%i.slice - -CapabilityBoundingSet= -#AmbientCapabilities= - -ON_PERM(:platform:no-oom, OOMScoreAdjust=-500) -ON_PERM(:partner:real-time, IOSchedulingClass=realtime) -ON_PERM(:public:display, SupplementaryGroups=display) -ON_PERM(:public:syscall:clock, , SystemCallFilter=~@clock) -%nl - -WorkingDirectory=-APP_DATA_DIR/{{:id}} -ExecStartPre=/bin/mkdir -p APP_DATA_DIR/{{:id}} -Environment=AFM_ID=TARGET -Environment=AFM_APP_INSTALL_DIR={{:#metadata.install-dir}} -Environment=AFM_WORKDIR=APP_DATA_DIR/{{:id}} -Environment=AFM_WSAPI_DIR=API_PATH_WS -Environment=PATH=/usr/sbin:/usr/bin:/sbin:/bin:{{:#metadata.install-dir}}/bin -Environment=LD_LIBRARY_PATH={{:#metadata.install-dir}}/lib -Environment=XDG_DATA_HOME=APP_DATA_DIR/{{:id}} -Environment=XDG_CONFIG_HOME=APP_DATA_DIR/{{:id}} -Environment=XDG_CACHE_HOME=APP_DATA_DIR/{{:id}} -Environment=XDG_RUNTIME_DIR=USER_RUN_DIR -Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=USER_RUN_DIR/bus - -IF_AGL_DEVEL -; Needed to enable debug -EnvironmentFile=-DEBUGGING_DIR/TARGET.env -ENDIF - -SyslogIdentifier=afbd-TARGET -StandardInput=null -StandardOutput=journal -StandardError=journal - -;------------------------------------------------------------------------------- -;---- text/html application/vnd.agl.native application/vnd.agl.service ---- -;------------------------------------------------------------------------------- -{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} -include(binder.inc) -{{/content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} - -;------------------------------------------------------------------------------- -;---- application/x-executable ---- -;------------------------------------------------------------------------------- -{{#content.type=application/x-executable}} -ExecStart={{:#metadata.install-dir}}/{{content.src}} -{{/content.type=application/x-executable}} - -IF_PERM(:system:run-by-default) -;------------------------------------------------------------------------------- -; auto start -;------------------------------------------------------------------------------- -[Install] -WantedBy=afm-user-session@.target -%systemd-unit wanted-by afm-user-session@.target -ENDIF - -%end systemd-unit - - diff --git a/conf/unit/macros.inc b/conf/unit/macros.inc new file mode 100644 index 0000000..a764765 --- /dev/null +++ b/conf/unit/macros.inc @@ -0,0 +1,67 @@ +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: +-------------------------------------------------------------------------------- +-- GLOBAL IMPORTANT DEFINITIONS +-------------------------------------------------------------------------------- +define( `X_EMITS', 1) +define( `X_DIVERTS', `divert(eval(-!X_EMITS()))') +define( `X_PUSH_DIVERTS', `pushdef(`X_EMITS', eval(X_EMITS() && $1))X_DIVERTS()') + +define( `X_IF', `pushdef(`X_COND', $1)X_PUSH_DIVERTS($1)') +define( `X_ELSE', `popdef(`X_EMITS')X_PUSH_DIVERTS(eval(!X_COND))') +define( `X_ELIF', `X_ELSE()X_IF($1)') +define( `X_ENDIF', `popdef(`X_EMITS')popdef(`X_COND')X_DIVERTS()') + +define( `IF', `pushdef(`ELSE',`X_ELSE()')pushdef(`ELIF',`X_ELIF($1)')pushdef(`ENDIF',`X_ENDIF()popdef(`ELSE',`ELIF',`ENDIF')')X_IF($1)') +-------------------------------------------------------------------------------- +-- MUSTACH SPECIFIC DEFINITIONS +-------------------------------------------------------------------------------- +define( `MUSTACH_ON', `ifelse(`$2',,,`{{#$1}}`$2'{{/$1}}')ifelse(`$3',,,`{{^$1}}`$3'{{/$1}}')') +define( `MUSTACH_IF', `{{#$1}}pushdef(`ELSE',`{{/$1}}{{^$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') +define( `MUSTACH_IF_NOT', `{{^$1}}pushdef(`ELSE',`{{/$1}}{{#$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') +-------------------------------------------------------------------------------- +-- CONDITIONAL HELPERS +-------------------------------------------------------------------------------- +define( `PERM', `@afm_prefix@permission:$1') +define( `REQPERM', `required-permission.PERM($1)') + +define( `ON_PERM', `MUSTACH_ON(REQPERM($1),$2,$3)') +define( `IF_PERM', `MUSTACH_IF(REQPERM($1))') +define( `IF_NOT_PERM', `MUSTACH_IF_NOT(REQPERM($1))') + +define( `ON_CONTENT', `MUSTACH_ON(content.type=$1,$2,$3)') +define( `IF_CONTENT', `MUSTACH_IF(content.type=$1)') +define( `IF_NOT_CONTENT', `MUSTACH_IF_NOT(content.type=$1)') + +define( `ON_VALUE', `MUSTACH_ON(value=$1,$2,$3)') +define( `IF_VALUE', `MUSTACH_IF(value=$1)') +define( `IF_NOT_VALUE', `MUSTACH_IF_NOT(value=$1)') +-------------------------------------------------------------------------------- +-- AFM DEFINITION +-------------------------------------------------------------------------------- +-- NOTE: +-- when home screen will use real ids +-- use TARGET={{:id}}--{{:ver}}--{{:#target}} +-- instead of TARGET={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} +-------------------------------------------------------------------------------- +define( `TARGET', `{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}') +define( `NEWTARGET', `{{:id}}--{{:ver}}--{{:#target}}') +define( `UNIT_NAME_BASE', `afm-ON_PERM(`:public:hidden', `service', `appli')-NEWTARGET') +define( `UNIT_NAME_SERVICE', `UNIT_NAME_BASE@%i.service') +define( `UNIT_NAME_API_BASE', `afm-api-$1') +define( `UNIT_NAME_API_SERVICE', `UNIT_NAME_API_BASE($1)@$2.service') +define( `UNIT_NAME_API_SOCKET', `UNIT_NAME_API_BASE($1)@$2.socket') +define( `UNIT_NAME_BINDING_BASE', `afm-link-$1') +define( `UNIT_NAME_BINDING_SERVICE', `UNIT_NAME_BINDING_BASE($1)@$2.service') +define( `APP_DATA_DIR', `/home/%i/app-data') +define( `USER_RUN_DIR', `@afm_users_rundir@/%i') +define( `DEBUGGING_DIR', `@afm_platform_rundir@/debug') +define( `API_PATH', `USER_RUN_DIR/apis') +define( `API_PATH_WS', `API_PATH/ws') +define( `API_PATH_LINK', `API_PATH/link') +-------------------------------------------------------------------------------- +-- AGL_DEVEL SPECIFIC PARTS +-------------------------------------------------------------------------------- +define( `ON_AGL_DEVEL', `ifdef(`AGL_DEVEL', $1, $2)') +define( `ON_NOT_AGL_DEVEL', `ifdef(`AGL_DEVEL', $2, $1)') +define( `IF_AGL_DEVEL', `IF(ON_AGL_DEVEL(1,0))') +define( `IF_NOT_AGL_DEVEL', `IF(ON_AGL_DEVEL(0,1))') diff --git a/conf/unit/provided-api.inc b/conf/unit/provided-api.inc new file mode 100644 index 0000000..bdee6c9 --- /dev/null +++ b/conf/unit/provided-api.inc @@ -0,0 +1,56 @@ +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: +;------------------------------------------------------------------------------- +;---- T H E S E R V I C E O F T H E A P I ---- +;------------------------------------------------------------------------------- +%begin systemd-unit + +# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} + +%systemd-unit system +%systemd-unit service UNIT_NAME_API_BASE({{name}})@ + +[Unit] +Description=Provides api {{name}} for user %i +X-AFM-API-TYPE={{value}} + +Requires=afm-user-setup@%i.service +After=afm-user-setup@%i.service + +Requires=UNIT_NAME_API_BASE({{name}})@%i.socket +After=UNIT_NAME_API_BASE({{name}})@%i.socket + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/true + +%end systemd-unit + +;------------------------------------------------------------------------------- +;---- T H E S O C K E T O F T H E A P I ---- +;------------------------------------------------------------------------------- + +%begin systemd-unit + +# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} + +%systemd-unit system +%systemd-unit socket UNIT_NAME_API_BASE({{name}})@ +[Unit] +Description=Provides websocket api {{name}} for user %i +Requires=afm-user-setup@%i.service +After=afm-user-setup@%i.service +DefaultDependencies=no + +[Socket] +SmackLabel=* +SmackLabelIPIn=System +SmackLabelIPOut=System +ListenStream=API_PATH_WS/{{name}} +FileDescriptorName={{name}} +Service=UNIT_NAME_SERVICE + +%end systemd-unit + + + diff --git a/conf/unit/provided-binding.inc b/conf/unit/provided-binding.inc new file mode 100644 index 0000000..3737126 --- /dev/null +++ b/conf/unit/provided-binding.inc @@ -0,0 +1,25 @@ +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: +;------------------------------------------------------------------------------- +;---- T H E S E R V I C E O F T H E B I N D I N G ---- +;------------------------------------------------------------------------------- +%begin systemd-unit + +# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} + +%systemd-unit system +%systemd-unit service UNIT_NAME_BINDING_BASE({{name}})@ + +[Unit] +Description=Provides binding {{name}} for user %i + +Requires=afm-user-setup@%i.service +After=afm-user-setup@%i.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/ln -sf {{:#metadata.install-dir}}/{{value}} API_PATH_LINK/{{name}} + +%end systemd-unit + + diff --git a/conf/unit/service.inc b/conf/unit/service.inc new file mode 100644 index 0000000..88c1454 --- /dev/null +++ b/conf/unit/service.inc @@ -0,0 +1,133 @@ +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: +;------------------------------------------------------------------------------- +;---- M A I N P A R T O F T H E S E R V I C E ---- +;------------------------------------------------------------------------------- +%begin systemd-unit + +# auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} +%nl + +%systemd-unit system +%systemd-unit service UNIT_NAME_BASE@ + +[Unit] +Description={{description}} +X-AFM-description={{description}} +X-AFM-name={{name.content}} +X-AFM-shortname={{name.short}} +X-AFM-id=TARGET +X-AFM-version={{:version}} +X-AFM-author={{author.content}} +X-AFM-author-email={{author.email}} +X-AFM-width={{width}} +X-AFM-height={{height}} +{{#icon}} +X-AFM-icon={{:#metadata.install-dir}}/{{:src}} +{{/icon}} +X-AFM--ID={{:id}} +X-AFM--target-name={{:#target}} +X-AFM--content={{content.src}} +X-AFM--type={{content.type}} +X-AFM--wgtdir={{:#metadata.install-dir}} +X-AFM--workdir=APP_DATA_DIR/{{:id}} +X-AFM--visibility=ON_PERM(`:public:hidden', `hidden', `visible') +%nl + +Requires=afm-user-session@%i.target +After=user@%i.service +After=Network.target + +# Adds check to smack +ConditionSecurity=smack +%nl + +# Automatic bound to required api +{{#required-binding}} +{{#value=extern}} +BindsTo=UNIT_NAME_BINDING_SERVICE({{name}},%i) +After=UNIT_NAME_BINDING_SERVICE({{name}},%i) +{{/value=extern}} +{{/required-binding}} +{{#required-api}} +{{#value=auto|ws}} +BindsTo=UNIT_NAME_API_SERVICE({{name}},%i) +After=UNIT_NAME_API_SERVICE({{name}},%i) +{{/value=auto|ws}} +{{/required-api}} +{{#provided-api}} +{{#value=ws|auto}} +Requires=UNIT_NAME_API_SOCKET({{name}},%i) +After=UNIT_NAME_API_SOCKET({{name}},%i) +{{/value=ws|auto}} +{{/provided-api}} + +%nl + +[Service] +EnvironmentFile=-@afm_confdir@/unit.env.d/* +EnvironmentFile=-@afm_confdir@/widget.env.d/{{:id}}/* +SmackProcessLabel=User::App::{{:id}} +SuccessExitStatus=0 SIGKILL + +User=%i +Slice=user-%i.slice + +CapabilityBoundingSet= +#AmbientCapabilities= + +ON_PERM(:platform:no-oom, OOMScoreAdjust=-500) +ON_PERM(:partner:real-time, IOSchedulingClass=realtime) +ON_PERM(:public:display, SupplementaryGroups=display) +ON_PERM(:public:syscall:clock, , SystemCallFilter=~@clock) +%nl + +WorkingDirectory=-APP_DATA_DIR/{{:id}} +ExecStartPre=/bin/mkdir -p APP_DATA_DIR/{{:id}} +Environment=AFM_ID=TARGET +Environment=AFM_APP_INSTALL_DIR={{:#metadata.install-dir}} +Environment=AFM_WORKDIR=APP_DATA_DIR/{{:id}} +Environment=AFM_WSAPI_DIR=API_PATH_WS +Environment=PATH=/usr/sbin:/usr/bin:/sbin:/bin:{{:#metadata.install-dir}}/bin +Environment=LD_LIBRARY_PATH={{:#metadata.install-dir}}/lib +Environment=XDG_DATA_HOME=APP_DATA_DIR/{{:id}} +Environment=XDG_CONFIG_HOME=APP_DATA_DIR/{{:id}} +Environment=XDG_CACHE_HOME=APP_DATA_DIR/{{:id}} +Environment=XDG_RUNTIME_DIR=USER_RUN_DIR +Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=USER_RUN_DIR/bus + +IF_AGL_DEVEL +; Needed to enable debug +EnvironmentFile=-DEBUGGING_DIR/TARGET.env +ENDIF + +SyslogIdentifier=afbd-TARGET +StandardInput=null +StandardOutput=journal +StandardError=journal + +;------------------------------------------------------------------------------- +;---- text/html application/vnd.agl.native application/vnd.agl.service ---- +;------------------------------------------------------------------------------- +{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} +include(binder.inc) +{{/content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} + +;------------------------------------------------------------------------------- +;---- application/x-executable ---- +;------------------------------------------------------------------------------- +{{#content.type=application/x-executable}} +ExecStart={{:#metadata.install-dir}}/{{content.src}} +{{/content.type=application/x-executable}} + +IF_PERM(:system:run-by-default) +;------------------------------------------------------------------------------- +; auto start +;------------------------------------------------------------------------------- +[Install] +WantedBy=afm-user-session@.target +%systemd-unit wanted-by afm-user-session@.target +ENDIF + +%end systemd-unit + + -- cgit 1.2.3-korg