Commit ac46dcb3 authored by Johan Ström's avatar Johan Ström

Templatize systemd init files

Use new cmake AgoService macro to create & install systemd files for each service.
Renamed devices/scheduler to schedulerold, since it conflicts with
core/scheduler
parent 5b973901
Pipeline #355 passed with stage
in 7 minutes
......@@ -191,7 +191,6 @@ endif()
OPTION(BUILD_CORE "Build the CORE" ON)
if (BUILD_CORE)
add_subdirectory (core)
install (PROGRAMS gateways/agomeloware.py DESTINATION ${BINDIR})
install (FILES data/inventory.sql data/datalogger.sql DESTINATION ${DATADIR})
endif()
......
......@@ -41,19 +41,25 @@ endfunction()
# and to avoid conflicts.
#
# Usage:
# AgoPythonProgram(myapp [WITH_CONFIGDIR ] [EXTRA_FILES "..."])
# AgoPythonProgram(myapp DESCRIPTION "ago control blaha handler" [WITH_CONFIGDIR ] [EXTRA_FILES "..."])
#
# Will setup targets to copy agomyapp.py and any extra files to the CMAKE_CURRENT_BINARY_DIR,
# and setup install to then copy these files to the appropriate installation dir.
# Also prepares a conf/systemd/agomyapp.service file and installs it, unless a .in with same name
# exists in the source dir.
#
# If WITH_CONFIGDIR is set, it will enable installation of directory /etc/opt/agocontrol/myapp.
# If EXTRA_FILES is specified, these will be copied to the "private" dir next to the .py file.
# If RUN_AS is specified, systemd will have that User instead of default user.
#
# Note that PROGRAM_BASE_NAME should not have ago prefix, nor .py suffix.
# The directory containing this directive must have a file named ago<name>.py.
#
function(AgoPythonProgram PROGRAM_BASE_NAME)
cmake_parse_arguments(PYPROG "WITH_CONFIGDIR" "" "EXTRA_FILES" ${ARGN})
set(options WITH_CONFIGDIR)
set(oneValueArgs DESCRIPTION RUN_AS)
set(multiValueArgs EXTRA_FILES)
cmake_parse_arguments(PYPROG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(PROGRAM_NAME "ago${PROGRAM_BASE_NAME}")
set(APP_DIR "${BASEDIR}/python/${PROGRAM_NAME}")
......@@ -65,6 +71,8 @@ function(AgoPythonProgram PROGRAM_BASE_NAME)
install(DIRECTORY DESTINATION ${CONFDIR}/${PROGRAM_BASE_NAME})
endif()
AgoService(${PROGRAM_BASE_NAME} DESCRIPTION "${PYPROG_DESCRIPTION}" RUN_AS "${PYPROG_RUN_AS}")
install(CODE "
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../python/${PROGRAM_NAME}/${PROGRAM_NAME}.py \$ENV{DESTDIR}${BINDIR}/${PROGRAM_NAME})
message(\"-- Installing symlink: \$ENV{DESTDIR}${BINDIR}/${PROGRAM_NAME} -> ../python/${PROGRAM_NAME}/${PROGRAM_NAME}.py\")
......@@ -75,4 +83,22 @@ function(AgoPythonProgram PROGRAM_BASE_NAME)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${infile}" DESTINATION "${OUTDIR}")
endforeach()
endfunction()
function(AgoService PROGRAM_BASE_NAME)
set(options )
set(oneValueArgs DESCRIPTION RUN_AS)
set(multiValueArgs )
cmake_parse_arguments(PROG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(PROGRAM_NAME "ago${PROGRAM_BASE_NAME}")
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/conf/systemd/${PROGRAM_NAME}.service.in")
if(NOT PROG_RUN_AS)
set(PROG_RUN_AS "agocontrol")
endif()
#message("Creating service file for ${PROGRAM_NAME} ${PROG_DESCRIPTION} AND ${PROG_RUN_AS}")
configure_file("${PROJECT_SOURCE_DIR}/conf/systemd/template.service.in" ${PROJECT_BINARY_DIR}/conf/systemd/${PROGRAM_NAME}.service)
install (FILES "${PROJECT_BINARY_DIR}/conf/systemd/${PROGRAM_NAME}.service" DESTINATION "/lib/systemd/system/")
endif()
endfunction()
\ No newline at end of file
agoowfs.init
agoresolver.init
conf.d/rpc.conf
conf.d/eta.conf
sysvinit/agocontrol
agomeloware.init
agozwave.init
systemd/agoeta.service
systemd/agozmcam.service
systemd/agomeloware.service
systemd/agoevent.service
systemd/agodmx.service
systemd/agoscenario.service
systemd/agoasterisk.service
systemd/agodatalogger.service
systemd/agoapc.service
systemd/agoiscp.service
systemd/agojointspace.service
systemd/agomysensors.service
systemd/agogc100.service
systemd/agoi2c.service
systemd/agozwave.service
systemd/agoblinkm.service
systemd/raspi1wGPIO.service
systemd/agoping.service
systemd/agoradiothermostat.service
systemd/agowebcam.service
systemd/agosecurity.service
systemd/agokwikwai.service
systemd/agoknx.service
systemd/agoowfs.service
systemd/agoenigma2.service
systemd/raspiMCP3xxxGPIO.service
systemd/agolua.service
systemd/raspiGPIO.service
systemd/agosimulator.service
systemd/agotimer.service
systemd/agorain8net.service
systemd/agoirtransethernet.service
systemd/agofirmata.service
systemd/agoresolver.service
systemd/agorpc.service
systemd/agosqueezeboxserver.service
systemd/agomopidy.service
systemd/agox10.service
......@@ -16,7 +16,6 @@ foreach (infile ${INIT_FILES})
endforeach (infile)
add_subdirectory (systemd)
add_subdirectory (conf.d)
add_subdirectory (schema.d)
add_subdirectory (sysvinit)
......
cmake_minimum_required (VERSION 3.0)
file (GLOB SYSTEMD_FILES *.in)
foreach (infile ${SYSTEMD_FILES})
string(REGEX REPLACE ".in$" "" outfile ${infile})
string(REGEX REPLACE ".*/" "" outfile ${outfile})
configure_file(
"${infile}"
"${CMAKE_CURRENT_BINARY_DIR}/${outfile}"
@ONLY
)
LIST(APPEND SYSTEMD_FILES_DONE ${CMAKE_CURRENT_BINARY_DIR}/${outfile})
endforeach (infile)
file (GLOB SYSTEMD_FILES *.service)
install (FILES ${SYSTEMD_FILES_DONE} ${SYSTEMD_FILES} DESTINATION /lib/systemd/system)
[Unit]
Description=ago control Web GUI NG
[Service]
ExecStart=/opt/agocontrol/admin/agoadmin.py
WorkingDirectory=/opt/agocontrol/admin
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control alerts system
[Service]
ExecStart=@BINDIR@/agoalert
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control APC Device
[Service]
ExecStart=@BINDIR@/agoapc
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Asterisk PBX interface
[Service]
ExecStart=@BINDIR@/agoasterisk
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control axis audio transmit device
[Service]
ExecStart=@BINDIR@/agoaxisaudiotransmit
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control blinkm i2c device
[Service]
ExecStart=@BINDIR@/agoblinkm
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Data Logger
[Service]
ExecStart=@BINDIR@/agodatalogger
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control dmx device
[Service]
ExecStart=@BINDIR@/agodmx
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Enigma2/Dreambox interface
[Service]
ExecStart=@BINDIR@/agoenigma2
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Enocean ESP3 Device
[Service]
ExecStart=@BINDIR@/agoenocean3
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control ETAtouch service
[Service]
ExecStart=@BINDIR@/agoeta
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Arduino Firmata Device
[Service]
ExecStart=@BINDIR@/agofirmata
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control gammu sms gateway
[Service]
ExecStart=@BINDIR@/agogammu
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control gc100 interface
[Service]
ExecStart=@BINDIR@/agogc100
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control i2c device
[Service]
ExecStart=@BINDIR@/agoi2c
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control ImperiHome App gateway
[Service]
ExecStart=@BINDIR@/agoImperiHome
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control IPX800
[Service]
ExecStart=@BINDIR@/agoipx800
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control IRTrans Ethernet infrared blaster Device
[Service]
ExecStart=@BINDIR@/agoirtrans_ethernet
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Onkyo ISCP device
[Service]
ExecStart=@BINDIR@/agoiscp
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control JointSpace Device
[Service]
ExecStart=@BINDIR@/agojointspace
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control KNX Device
[Service]
ExecStart=@BINDIR@/agoknx
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Kwikwai HDMI CEC Bridge Device
[Service]
ExecStart=@BINDIR@/agokwikwai
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control LIFX handler
[Service]
ExecStart=@BINDIR@/agolifx
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control LUA script event handler
[Service]
ExecStart=@BINDIR@/agolua
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Meloware Lightswitchserver Gateway
[Service]
ExecStart=@BINDIR@/agomeloware
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Mopidy device
[Service]
ExecStart=@BINDIR@/agomopidy
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control MQTT client
[Service]
ExecStart=@BINDIR@/agomqtt
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control MySensors interface
[Service]
ExecStart=@BINDIR@/agoMySensors
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control NVR (Network Video Recorder)
[Service]
ExecStart=@BINDIR@/agonvr
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control for onvif devices
[Service]
ExecStart=@BINDIR@/agoonvif
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control 1-Wire Device
[Service]
ExecStart=@BINDIR@/agoowfs
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Host pinger
[Service]
ExecStart=@BINDIR@/agoping
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control radio thermostat device
[Service]
ExecStart=@BINDIR@/agoradiothermostat
WorkingDirectory=@BINDIR@
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control rain8net Device
[Service]
ExecStart=@BINDIR@/agorain8net
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=agocontrol
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control raspberry pi 1-wire GPIO Device
[Service]
ExecStart=@BINDIR@/agoraspi1wGPIO
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago raspberry pi Camera device
[Service]
ExecStart=@BINDIR@/agoraspiCamera
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control raspberry pi GPIO Device
[Service]
ExecStart=@BINDIR@/agoraspiGPIO
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago raspberry pi MCPxxx GPIO device
[Service]
ExecStart=@BINDIR@/agoraspiMCP3xxxGPIO
WorkingDirectory=@BINDIR@
Restart=always
RestartSec=2
User=root
[Install]
WantedBy=multi-user.target
[Unit]
Description=ago control Resolver