/usr/bin/pkgos-gen-systemd-unit is in openstack-pkg-tools 75.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #!/bin/sh
if [ $# -ne 1 ] ; then
echo "Usage: $0 <init_template>"
exit 1
fi
INIT_TEMPLATE=${1}
SERVICE_FILE=`echo ${INIT_TEMPLATE} | sed 's/.init.in/.service/'`
# Get the variables defined in the init template
. ${INIT_TEMPLATE}
if [ -z "${NAME}" ] ; then
echo "Variable NAME is not set!"
exit 1
fi
if [ -z "${PROJECT_NAME}" ] ; then
echo "Variable PROJECT_NAME is not set!"
exit 1
fi
if [ -z "${DESC}" ] ; then
echo "Variable DESC is not set!"
exit 1
fi
if [ -z "${SCRIPTNAME}" ] ; then
SCRIPTNAME=/etc/init.d/${NAME}
fi
if [ -z "${SYSTEM_USER}" ] ; then
SYSTEM_USER=${PROJECT_NAME}
fi
if [ -z "${SYSTEM_GROUP}" ] ; then
SYSTEM_GROUP=${PROJECT_NAME}
fi
if [ -z "${SYSTEMD_TYPE}" ] ; then
SYSTEMD_TYPE=simple
fi
# Find out what should go in After=
SHOULD_START=`cat ${INIT_TEMPLATE} | grep "# Should-Start:" | sed 's/# Should-Start://'`
X_START_BEFORE=`cat ${INIT_TEMPLATE} | grep "# X-Start-Before:" | sed 's/# X-Start-Before://'`
if [ -n "${SHOULD_START}" ] ; then
AFTER="After="
for i in ${SHOULD_START} ; do
AFTER="${AFTER}${i}.service "
done
fi
if [ -n "${X_START_BEFORE}" ] ; then
BEFORE="Before="
for i in ${X_START_BEFORE} ; do
BEFORE="${BEFORE}${i}.service "
done
fi
if [ "${SYSTEMD_TYPE}" = "oneshot" ] ; then
SYSTEMD_RESTART="Restart=no"
else
SYSTEMD_RESTART="Restart=on-failure"
fi
if [ -n "${SYSTEMD_DOC}" ] ; then
SYSTEMD_DOC="Documentation=$SYSTEMD_DOC"
fi
echo "[Unit]
Description=${DESC}
$AFTER
$BEFORE
$SYSTEMD_DOC
[Service]
User=${SYSTEM_USER}
Group=${SYSTEM_GROUP}
Type=${SYSTEMD_TYPE}
WorkingDirectory=~
RuntimeDirectory=${PROJECT_NAME} lock/${PROJECT_NAME}
CacheDirectory=${PROJECT_NAME}
ExecStart=${SCRIPTNAME} systemd-start
$SYSTEMD_RESTART
LimitNOFILE=65535
TimeoutStopSec=15
[Install]
WantedBy=multi-user.target
" >${SERVICE_FILE}
|