Scriptlets

Snippets

Users and groups

Users and groups are dynamically mapped on the target systems at package install time.

prerequires += shadow-utils

script prein
    getent group GROUPNAME >/dev/null || groupadd -r GROUPNAME
    getent passwd USERNAME >/dev/null || \
      useradd -r -g GROUPNAME -d HOMEDIR -s /sbin/nologin \
      -c "Useful comment about the purpose of this account" USERNAME
end

HOMEDIR must be created by the package that is to be installed and be owned by the user with appropriately restrictive permissions. A good location for that would be the application's data directory. Don't ever use /home/USERNAME for system users.

Systemd

# Just search for new unit files that were just installed.
script postin
    systemctl daemon-reload >/dev/null 2>&1 || :
end

# Disable the service that is to be removed and stop it if it is still running.
script preun
    systemctl --no-reload disable NAME.service >/dev/null 2>&1 || :
    systemctl stop NAME.service >/dev/null 2>&1 || :
end

# Just tell systemd that unitfiles have been removed.
script postun
    systemctl daemon-reload >/dev/null 2>&1 || :
end

# Try to restart the service if it is running.
script postup
    systemctl daemon-reload >/dev/null 2>&1 || :
    systemctl try-restart NAME.service >/dev/null 2>&1 || :
end

Don't ever start a service at install time. This will break the build process and generation of images. In case you want to enable a service by default use the following line in postin after reloading the daemon:

systemctl --no-reload enable NAME.service >/dev/null 2>&1 || :
Edit Page ‐ Yes, you can edit!

Older Revisions • February 15 at 4:41 pm • Jon