The plugin builds on the nubula.rpm plugin from Netflix. Unlike the more general service script code created by nebula.ospackage-daemon, the scripts generated by this plugin do not use daemontools. This plugin also provides a options for creating a service account user.
plugins {
id "nebula.rpm" version "4.3.0"
id "amdonov.ospackage-init" version "0.4.0"
}
daemon {
daemonName = "myservice"
command = "/usr/bin/myservice server"
user = 'myuser'
group = 'myuser'
createUser = true
}
In addition to creating the init script, the preceeding options would create the following RPM scripts.
/usr/sbin/groupadd -r myuser 2>/dev/null || :
/usr/sbin/useradd -g myuser \
-s /sbin/nologin -r myuser 2>/dev/null || :
/sbin/chkconfig myservice on
if [ "$1" = "0" ]; then
/etc/rc.d/init.d/myservice stop >/dev/null 2>&1
/sbin/chkconfig --del myservice
fi
The plugin supports the options shown below.
String daemonName // defaults to packageName
String command // Required
String user // defaults to "root"
String group // defaults to "root"
List<Integer> runLevels = new LinkedList<>() // rpm default == [3,4,5]
Integer startSequence // default 85
Integer stopSequence // default 15
Boolean createUser // default false
String userShell // defaults /sbin/nologin
String userHome // default unset
The generated service script initializes and uses variables shown below. It will also source the the file /etc/sysconfig/${daemonName}. Use that file to override defaults, set extra environment varibles, etc.
name=${daemonName}
pidfile="/var/run/${daemonName}.pid"
command="${command}"
user="${user}"
group="${group}"
chroot="/"
chdir="/"
nice=""