Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getting Samba under AIX SRC control

193 views
Skip to first unread message

Pim Zandbergen

unread,
Jan 15, 1998, 3:00:00 AM1/15/98
to

I think it would be cool to get Samba under AIX SRC (System Resource Controller)control. You would be able to stop and start Samba through SMIT or by
startsrc/stopsrc -s samba.

Anyone knows how to do this ?
--
E-mail : Pim Zandbergen <p...@cti.nl>
S-mail : Laan Copes van Cattenburch 70, 2585 GD The Hague, The Netherlands
Phone : +31 70 3067373
Fax : +31 70 3067374

Joseph H. Buehler

unread,
Jan 15, 1998, 3:00:00 AM1/15/98
to

Look in info explorer, it is all in there. Or ask on the aix newsgroup.

Joe Buehler

Michael Wojcik

unread,
Jan 16, 1998, 3:00:00 AM1/16/98
to

In article <69kk4d$u32$1...@chagall.cti.nl> p...@cti.nl (Pim Zandbergen) writes:
>I think it would be cool to get Samba under AIX SRC (System Resource Controller)control. You would be able to stop and start Samba through SMIT or by
>startsrc/stopsrc -s samba.
>
>Anyone knows how to do this ?

See _AIX General Programming Concepts_, chapter 24, "System Resource
Controller". (That's for AIX 3.2.5; under various incarnations of
AIX 4, the chapter number might be different.)

If you just want to be able to stop and start Samba (ie. the two
Samba daemons, smbd and nmbd) using startsrc and stopsrc, it's
pretty trivial. lssrc will also list whether they're active, though
you can't get a "long" (detailed) report using the -l option unless
you're willing to do some programming.

You should be able to put Samba under basic SRC control without
changing any Samba code at all. Use mkssys to register two new
subsystems. I'll call them "samba_share" and "samba_name" for
smbd and nmbd respectively. To create the subsystems you'd use
something like:

# mkssys -s samba_share -p /usr/local/samba/bin/smbd -a -D -u root \
-S -n 15 -f 9 -G samba -t smbd

and something similar for nmbd.

This will create a subsystem called "samba_share", alias "smbd", in
the "samba" group, communicating with SRC via signals (which require
no additional code in Samba). The program to run for the subsystem
is smbd, with the "-D" parameter. To kill the subsystem normally,
use signal 15 (SIGTERM); to force-kill it, use signal 9 (SIGKILL).

Once you've defined smbd and nmbd this way to SRC, you can start
Samba using "startsrc -g samba" and terminate it using "stopsrc -g
samba".

Disclaimer: I haven't actually tried this with Samba. I've put
other daemons under SRC using this method (or something like it --
it's been a while) though.

Michael Wojcik m...@microfocus.com
AAI Development, Micro Focus Inc.
Department of English, Miami University

Even 300 years later, you should plan it in detail, when it comes to your
summer vacation.
-- Pizzicato Five


Eric M. Agar

unread,
Jan 22, 1998, 3:00:00 AM1/22/98
to

m...@microfocus.com (Michael Wojcik) writes:

>
> You should be able to put Samba under basic SRC control without
> changing any Samba code at all. Use mkssys to register two new
> subsystems. I'll call them "samba_share" and "samba_name" for
> smbd and nmbd respectively. To create the subsystems you'd use
> something like:
>
> # mkssys -s samba_share -p /usr/local/samba/bin/smbd -a -D -u root \
> -S -n 15 -f 9 -G samba -t smbd
>
> and something similar for nmbd.
>
> This will create a subsystem called "samba_share", alias "smbd", in
> the "samba" group, communicating with SRC via signals (which require
> no additional code in Samba). The program to run for the subsystem
> is smbd, with the "-D" parameter. To kill the subsystem normally,
> use signal 15 (SIGTERM); to force-kill it, use signal 9 (SIGKILL).
>
> Once you've defined smbd and nmbd this way to SRC, you can start
> Samba using "startsrc -g samba" and terminate it using "stopsrc -g
> samba".
>
> Disclaimer: I haven't actually tried this with Samba. I've put
> other daemons under SRC using this method (or something like it --
> it's been a while) though.
>

I don't know any details about these specific daemons, but I'd like to
add some general comments about placing daemons under SRC control.

Whether or not you can put a daemon under SRC control without any code
changes depends on how that daemon's initialization is coded. It is
common for a daemon to take a sequence of initialization steps
designed to lose the controlling terminal it may have inherited by
fork()ing a child, leaving the child running as the daemon and having
the parent exit. That poses problems for SRC control, since the SRC
interprets the termination of the parent process as the termination of
the daemon it just started. I've seen daemons coded to avoid this
problem by only creating the child process if file descriptor 0 is
associated with a terminal.

For example, a daemon could successfully use the start_daemon()
routine below with or without the SRC.

----- code example -----

#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mode.h>

void create_child(void)
{
pid_t pid;

if ((pid = fork()) == (pid_t)-1) {
exit(1);
} else if (pid != 0) {
exit(0);
}

return;
}

void start_daemon(void)
{
struct sigaction sa;
struct stat st;

sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGHUP, &sa, NULL) == -1) {
exit(1);
}

if (fstat(0, &st) < 0) {
create_child();
} else {
if ((st.st_mode & S_IFMT) == S_IFCHR) {
if (isatty(0)) {
create_child();
}
} else {
create_child();
}
}

(void) setsid();

return;
}

---- end code example -----


This code comes from a redbook I wrote about writing daemons for AIX,
"Writing Reliable AIX Daemons", SG24-4946. It discusses the SRC in
detail. The book also includes the source code for library routines
our development lab uses to simplify the coding required for our use
of the SRC.

Hope this helps.

--
Eric M. Agar
IBM, Scalable Power Parallel Systems, RS/6000 Division
ag...@us.ibm.com

Pim Zandbergen

unread,
Jan 22, 1998, 3:00:00 AM1/22/98
to

ag...@ppsclnt8.pok.ibm.com (Eric M. Agar) writes:


>I don't know any details about these specific daemons, but I'd like to
>add some general comments about placing daemons under SRC control.

>Whether or not you can put a daemon under SRC control without any code
>changes depends on how that daemon's initialization is coded. It is
>common for a daemon to take a sequence of initialization steps
>designed to lose the controlling terminal it may have inherited by
>fork()ing a child, leaving the child running as the daemon and having
>the parent exit. That poses problems for SRC control, since the SRC
>interprets the termination of the parent process as the termination of
>the daemon it just started.


This should pose no problem for the samba daemons. Only when given the -D
options will they fork and go to the background.

Without the -D option, they will stay in the foreground, as is required
when started from inetd.

I suppose if a daemon could be run from inetd, it could run from SRC
or inittab as well.

Villy Kruse

unread,
Jan 23, 1998, 3:00:00 AM1/23/98
to

p...@cti.nl (Pim Zandbergen) writes:


>This should pose no problem for the samba daemons. Only when given the -D
>options will they fork and go to the background.

>Without the -D option, they will stay in the foreground, as is required
>when started from inetd.

>I suppose if a daemon could be run from inetd, it could run from SRC
>or inittab as well.

Well, there is a difference:

If a daemon is started from inetd, then the tcpip connection is already
set-up and the demain just have to talk to the client using stdin and
stdout. When the tcp call is closed the deamon process will terminate.

If the daemon is started from a rc-script (with -D option) it has to
create its own listen socket and fork off a server process for each
incomming call. This should still happen if started from inittab or SRC.

Villy

0 new messages