ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Igor Vlasenko <vlasenko@imath.kiev.ua>
To: devel@lists.altlinux.org
Cc: ldv@altlinux.org
Subject: [devel] systemd policy - different names for systemd and sysV.
Date: Fri, 11 May 2012 14:16:07 +0300
Message-ID: <20120511111606.GA19617@dad.imath.kiev.ua> (raw)

[-- Attachment #1: Type: text/plain, Size: 2789 bytes --]

Господа,
когда имя systemd сервиса отличается от имени sysV init скрипта,
возникает вопрос, что писать в %post/un_service <name>.

Естественно, хочется писать в %post/un_service 
имя sysV init скрипта.

Если сделать симлинк systemd сервиса с sysV init именем,
например, bluetoothd.service -> bluetooth.service
service <sysV init имя> start/stop работать будет.

Проблема в том, что chkconfig <sysV init имя> on / off
не работает, даже если есть симлинк, поскольку эта функциональность
считается неправильной в systemctl.

Это плохо, так как не позволяет писать скрипты, одинаково
работающие хоть под sysV init, хоть под systemd.

Однако нам ничто не мешает пропатчить chkconfig,
чтобы он разрешал симлинк в настоящее имя systemd сервиса.

Пример такого достаточно тривиального патча к chkconfig
приложен в аттачменте (chkconfig-2.patch).

Предлагаю патчить chkconfig (не обязательно предложенным патчем)
так как иначе придется переименовывать sysV init скрипты,
а это 
1) будут замусорены сотни спеков
2) сотни спеков будут замусорены как правило некорректным
кодом, который еще надо тщательно тестировать, чтобы он не
сломал обновление.

Ведь при переименовании, если не проследить,
может поменяться имя pid файла, и вообще у нас при переименовании 
нет condrestart, а есть только <старое имя> stop
и <новое имя> start, и универсальный триггер для condrestart при
переименовании, использование которого можно было бы рекомендовать
в полиси, вряд ли получится написать. Нужно будет смотреть 
в каждый sysV init скрипт индивидуально.
И все ли смогут сделать это корректно?

-- 

Dr. Igor Vlasenko
--------------------
Topology Department
Institute of Math
Kiev, Ukraine


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


[-- Attachment #2: chkconfig-2.patch --]
[-- Type: text/plain, Size: 1893 bytes --]

diff --git a/chkconfig.c b/chkconfig.c
index 63ddd73..727a820 100644
--- a/chkconfig.c
+++ b/chkconfig.c
@@ -622,15 +622,43 @@ int setService(char * name, int type, int where, int state) {
     return 0;
 }
 
+#ifndef SYSTEMD_UNITDIR
+# define SYSTEMD_UNITDIR "/lib/systemd/system"
+#endif
+
+static char* systemdServiceName (const char* name) {
+    char *p;
+    char *serviceFile;
+    struct stat statbuf;
+    xasprintf(&serviceFile, SYSTEMD_UNITDIR "%s.service", name);
+    lstat(serviceFile,&statbuf);
+    if (!S_ISLNK(statbuf.st_mode)) {
+	xasprintf(&p, "%s.service", name);
+    } else {
+	char *realFile = realpath(serviceFile,NULL);
+	char *realName = basename(realFile);
+	/* wheather the end of realName ends with .service */
+	if (strncmp (realName+strlen(realName)-sizeof(".service"),
+		     ".service", sizeof(".service")) != 0) {
+	    fprintf(stderr, _("Symlink %s does not point to a *.service file. Falling back to %s as systemd service name.\n"), realFile, name);
+	    xasprintf(&p, "%s.service", name);
+	} else {
+	    p = strdup (realName);
+	}
+	free(realFile);
+    }
+    free(serviceFile);
+    return p;
+}
+
+
 void forwardSystemd(const char *name, int type, const char *verb) {
 
     if (type == TYPE_XINETD)
         return;
 
     if (systemdActive() && isOverriddenBySystemd(name)) {
-        char *p;
-
-        xasprintf(&p, "%s.service", name);
+	char *p = systemdServiceName(name);
 
         fprintf(stderr, _("Note: Forwarding request to 'systemctl %s %s'.\n"),
                 verb, p);
@@ -648,8 +676,10 @@ static int systemd_loaded_type(const char *name) {
 	char *cmd;
 	FILE *p;
 	int rc = 0;
+	char *systemdName = systemdServiceName(name);
 
-        xasprintf(&cmd, "systemctl status %s.service", name);
+        xasprintf(&cmd, "systemctl status %s", systemdName);
+	free(systemdName);
 	p = popen(cmd, "r");
 	if (p) {
 		char buf[1024];

             reply	other threads:[~2012-05-11 11:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 11:16 Igor Vlasenko [this message]
2012-05-11 18:31 ` Dmitry V. Levin
2012-05-11 19:19   ` Igor Vlasenko
2012-05-11 19:36     ` Igor Vlasenko
2012-05-18  9:55       ` Alexey Shabalin
2012-05-18 10:19         ` Dmitry V. Levin
2012-05-18 10:51           ` Alexey Shabalin
2012-05-18 15:07             ` Dmitry V. Levin
2012-05-18 16:05               ` Alexey Shabalin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120511111606.GA19617@dad.imath.kiev.ua \
    --to=vlasenko@imath.kiev.ua \
    --cc=devel@lists.altlinux.org \
    --cc=ldv@altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git