Documentationcurrent version
Help us improve the docs by fixing typos and proposing enhancements.


Action "service.init"

Render startup script. Reload the service daemon provider depending on the os.


  • $status
    Indicates if the init script was reloaded.

Schema definitions

definitions =
    type: 'object'
        $ref: 'module://@nikitajs/file/lib/index#/definitions/config/properties/backup'
        $ref: 'module://@nikitajs/file/lib/index#/definitions/config/properties/context'
        default: {}
        description: '''
        The context object used to render the scripts file; templating is
        disabled if no context is provided.
        $ref: 'module://@nikitajs/file/lib/index#/definitions/config/properties/engine'
        typeof: 'function'
        description: '''
        Filter function to extend the nunjucks engine.
        $ref: 'module://@nikitajs/core/lib/actions/fs/chown#/definitions/config/properties/gid'
        $ref: 'module://@nikitajs/file/lib/index#/definitions/config/properties/local'
        $ref: 'module://@nikitajs/core/lib/actions/fs/chmod#/definitions/config/properties/mode'
        default: '755'
        type: 'string'
        description: '''
        The name of the destination file. Uses the name of the template if
        $ref: 'module://@nikitajs/file/lib/index#/definitions/config/properties/source'
        $ref: 'module://@nikitajs/file/lib/index#/definitions/config/properties/target'
        description: '''
        The destination file. `/etc/init.d/crond` or
        `/etc/systemd/system/crond.service` for example. If no provided,
        nikita put it on the default folder based on the service daemon
        provider,the OS and use the source filename as the name.
        $ref: 'module://@nikitajs/core/lib/actions/fs/chown#/definitions/config/properties/uid'
    required: ['source']


handler = ({config, tools: {path}}) ->
  # check if file is target is directory
  # detect daemon loader provider to construct target ?= path.basename(config.source).split('.')[0] = path.basename('.service')[0] if ?= "/etc/init.d/#{}"
  {loader} = await {}
  config.loader ?= loader
  # discover loader to put in cache
  await @file.render
    source: config.source
    mode: config.mode
    uid: config.uid
    gid: config.gid
    backup: config.backup
    context: config.context
    local: config.local
    engine: config.engine
  return unless config.loader is 'systemctl'
  {$status} = await @execute
    $shy: true
    command: """
      systemctl status #{} 2>\&1 | egrep \
      '(Reason: No such file or directory)|(Unit #{}.service could not be found)|(#{}.service changed on disk)'
    code: [0, 1]
  return unless $status
  await @execute
    command: 'systemctl daemon-reload;systemctl reset-failed'


module.exports =
  handler: handler
    definitions: definitions
Edit on GitHub

Nikita is an open source project hosted on GitHub and developed by Adaltas.