From 8475d117d722bcbf919eb0f332f34c0dc7ace36b Mon Sep 17 00:00:00 2001 From: James Slagle Date: Fri, 31 Jan 2014 13:34:53 -0500 Subject: [PATCH] Ability to add *-create-dir service separately For systemd services, we create 2 services: one for the daemon and one that creates the run directory under /var/run for the daemon. For the packaged installs, the daemon service is already provided by the package, so we need the ability to add just the *-create-dir service. Some might say that the package should create it's run directory...and it in fact does. However, we are reconfiguring the services to use /var/run and the package uses /var/lib. Since /var/run is tmpfs mounted, we need the *-create-dir services for the packages as well. Change-Id: If26d9d7da04d3d1d97809db0e21e54dd9f8042ca --- elements/os-svc-install/bin/os-svc-daemon | 22 +++++++++++++++++++--- elements/os-svc-install/bin/os-svc-enable | 7 ++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/elements/os-svc-install/bin/os-svc-daemon b/elements/os-svc-install/bin/os-svc-daemon index 2df77f372..7181fc96a 100755 --- a/elements/os-svc-install/bin/os-svc-daemon +++ b/elements/os-svc-install/bin/os-svc-daemon @@ -12,6 +12,8 @@ usage() { echo "" echo " -h Show help and exit" echo " -p Print the job file instead of writing to disk" + echo " -d Only create the systemd service that creates the run time directory," + echo " not the actual systemd daemon service. Ignored for upstart." echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd." echo " default: $DEFAULT_POSTSTART" echo " -e ENV Environment name=value entries to set in the service/job" @@ -27,6 +29,7 @@ SERVICENAME=${SERVICENAME:-""} RUNAS=${RUNAS:-""} RUNCMD=${RUNCMD:-""} ENV=${ENV:-""} +CREATE_DIR_ONLY=${CREATE_DIR_ONLY:-""} # The default helps avoid race with daemon listening. http://pad.lv/1179766 POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART} @@ -41,7 +44,7 @@ print_to_file() { OUTPUT=print_to_file nshift=0 -while getopts "phs:n:u:c:e:" opt; do +while getopts "phds:n:u:c:e:" opt; do case "$opt" in n) SERVICENAME=$OPTARG;; u) RUNAS=$OPTARG;; @@ -49,6 +52,7 @@ while getopts "phs:n:u:c:e:" opt; do s) POSTSTART=$OPTARG;; e) ENV=$OPTARG;; p) OUTPUT=print_only;; + d) CREATE_DIR_ONLY=1;; h) usage; exit 0;; \?) usage; exit 1;; :) usage; exit 1;; @@ -137,13 +141,22 @@ WantedBy=multi-user.target Alias=$name.service EOF +} + +function install_create_dir_systemd { + local name=$(map-services $1) + local user=$2 + $OUTPUT /usr/lib/systemd/system/$name-create-dir.service <&2 fi - install_systemd $SERVICENAME $RUNAS $RUNCMD $* + if [ -z "$CREATE_DIR_ONLY" ]; then + install_systemd $SERVICENAME $RUNAS $RUNCMD $* + fi + install_create_dir_systemd $SERVICENAME $RUNAS fi diff --git a/elements/os-svc-install/bin/os-svc-enable b/elements/os-svc-install/bin/os-svc-enable index 7cb08c7f8..eb9e5d391 100755 --- a/elements/os-svc-install/bin/os-svc-enable +++ b/elements/os-svc-install/bin/os-svc-enable @@ -50,7 +50,12 @@ function enable_upstart_service { function enable_systemd_service { local name=$1 - systemctl enable $(map-services $name).service + local service_name=$(map-services $name) + systemctl enable $service_name.service + # Also enable the create-dir service if it exists + if [ -f /usr/lib/systemd/system/$service_name-create-dir.service ]; then + systemctl enable $service_name-create-dir.service + fi } # TODO: SysV init fallback support