Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^5: RFC: an(other) UNIX daemon module implementation

by afoken (Parson)
on Jun 28, 2012 at 19:19 UTC ( #978979=note: print w/ replies, xml ) Need Help??


in reply to Re^4: RFC: an(other) UNIX daemon module implementation
in thread RFC: an(other) UNIX daemon module implementation

Mmmm I didn't dig very deeply into daemontools, but it didn't seem somethig that mixed the daemon with the controlling script, although I may be mistaken (I just took a glance at it).
Rather, it seems to be a framework to provide systemd-like capabilities to the system.

Correct. Let me show how daemontools work on my little server at home:

Output of pstree:

init-+-crond : : |-sshd---sshd---sshd---bash---bash---pstree |-svscanboot-+-readproctitle | `-svscan-+-supervise---ntpd | |-supervise---xfs | |-4*[supervise] | |-8*[supervise---multilog] | |-supervise---fetchmail | |-supervise---exim | |-supervise---server | |-supervise---vnc-fwd | |-supervise---cupsd | |-supervise---mdadm | |-supervise---postmaster---4*[postmaster] | |-supervise---powersocket | `-supervise---vboxwebsrv---8*[{vboxwebsrv}] |-syslogd |-udevd---udevd : : `-ypserv

tree -l in /service

├── cups -> /var/svc.d/cups
│   ├── run
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── exim -> /var/svc.d/exim
│   ├── run
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── fetchmail -> /var/svc.d/fetchmail
│   ├── conffile
│   ├── fetchmail.conf
│   ├── fetchmail.conf-working
│   ├── log
│   │   ├── run
│   │   ├── run~
│   │   └── supervise
│   │       ├── control
│   │       ├── lock
│   │       ├── ok
│   │       └── status
│   ├── pid
│   │   └── fetchmail.pid
│   ├── run
│   ├── status
│   ├── supervise
│   │   ├── control
│   │   ├── lock
│   │   ├── ok
│   │   └── status
│   └── wake
├── mdadm-monitor -> /var/svc.d/mdadm-monitor/
│   ├── run
│   ├── run~
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── ntpd -> /var/svc.d/ntpd
│   ├── run
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── pg9 -> /var/svc.d/pg9
│   ├── log
│   │   ├── run
│   │   └── supervise
│   │       ├── control
│   │       ├── lock
│   │       ├── ok
│   │       └── status
│   ├── run
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── printerpower -> /var/svc.d/printerpower
│   ├── down
│   ├── log
│   │   ├── run
│   │   └── supervise
│   │       ├── control
│   │       ├── lock
│   │       ├── ok
│   │       └── status
│   ├── run
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── save-attachments -> /var/svc.d/save-attachments
│   ├── log
│   │   ├── run
│   │   ├── run~
│   │   └── supervise
│   │       ├── control
│   │       ├── lock
│   │       ├── ok
│   │       └── status
│   ├── run
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── smartd -> /var/svc.d/smartd
│   ├── down
│   ├── run
│   ├── run~
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── vboxweb -> /var/svc.d/vboxweb
│   ├── log
│   │   ├── run
│   │   └── supervise
│   │       ├── control
│   │       ├── lock
│   │       ├── ok
│   │       └── status
│   ├── run
│   ├── run~
│   └── supervise
│       ├── control
│       ├── lock
│       ├── ok
│       └── status
├── vnc-fwd -> /var/svc.d/vnc-fwd
│   ├── bin
│   │   └── vnc-fwd
│   ├── lib
│   │   └── Foken
│   │       ├── VNCForward
│   │       │   ├── HTTPd
│   │       │   │   ├── RH
│   │       │   │   │   ├── debug.pm
│   │       │   │   │   └── vnc.pm
│   │       │   │   ├── RH.pm
│   │       │   │   ├── Request.pm
│   │       │   │   └── RequestHandler.pm
│   │       │   ├── HTTPd.pm
│   │       │   ├── Object.pm
│   │       │   ├── VNCd
│   │       │   │   └── Request.pm
│   │       │   └── VNCd.pm
│   │       └── VNCForward.pm
│   ├── run
│   ├── static
│   │   ├── debug.html
│   │   ├── index.html
│   │   ├── style.css
│   │   ├── vnc_logo.png
│   │   └── vnc_logo_background.png
│   ├── supervise
│   │   ├── control
│   │   ├── lock
│   │   ├── ok
│   │   └── status
│   └── template
│       ├── layout
│       └── vnc
│           ├── default
│           ├── edit
│           └── ip
└── xfs -> /var/svc.d/xfs
    ├── run
    ├── run~
    └── supervise
        ├── control
        ├── lock
        ├── ok
        └── status

You can ignore the supervise directories, they are generated and controled by the supervise program, and you should not mess with them. Essentially, you have one directory for each service. Inside that directory, you have a run program (typically a shell script), and optionally a log directory for a logging service, again with a run program. Typically, log/run starts multilog. Optionally, a service directory may also contain a down entry that prevents an automatic start of the service. You can see that in smartd and printerpower. Other files and directories are allowed, you can see that in fetchmail and even more in vnc-fwd (a daemon written in Perl).

You don't see any run programs in the process list. This is because run typically replaces itself with the actual daemon program. This typically happens indirectly, via a chain of helper programs, each modifies the environment a little bit, then replaces itself with the next program. The most common one is setuidgid, that sets the real and effective user and group IDs to the user given as first argument, then replaces itself with the program in its second argument, passing all remaining parameters to the program.

Output of find -L . -type f -name run -printf '*** %p ***\n' -exec cat {} \;

*** ./ntpd/run *** #!/bin/sh exec 2>&1 echo "*** Starting ntpd ***" exec \ /usr/sbin/ntpd -g -n *** ./xfs/run *** #!/bin/sh exec 2>&1 echo "Starting X font server ..." exec \ /usr/bin/xfs \ -nodaemon \ -droppriv \ -user nobody *** ./fetchmail/log/run *** #!/bin/sh exec \ setuidgid nobody \ multilog t s1000000 /var/multilog/fetchmail *** ./fetchmail/run *** #!/bin/sh exec 2>&1 echo "*** Starting fetchmail service ...***" if [ "$(pidof exim)" = "" ] ; then echo "exim not running, exiting" exit 1 fi exec \ env FETCHMAILHOME="./pid" \ setuidgid fetchmail \ fetchmail -v -f ./fetchmail.conf --nodetach *** ./exim/run *** #!/bin/sh exec 2>&1 echo "*** Starting exim ***" exec \ /opt/exim/bin/exim -bdf -q25m *** ./vboxweb/log/run *** #!/bin/sh exec \ setuidgid nobody \ multilog t s1000000 /var/multilog/vboxweb *** ./vboxweb/run *** #!/bin/sh exec 2>&1 echo "*** Starting vboxweb service ...***" exec \ /opt/VirtualBox/vboxwebsrv # -v *** ./save-attachments/log/run *** #!/bin/sh exec \ setuidgid nobody \ multilog t s1000000 /var/multilog/save-attachments *** ./save-attachments/run *** #!/bin/sh exec 2>&1 echo "*** Starting save-attachments ***" exec \ setuidgid gs \ /home/gs/save-attachments/server *** ./printerpower/log/run *** #!/bin/sh exec \ setuidgid nobody \ multilog t s1000000 /var/multilog/printerpower *** ./printerpower/run *** #!/bin/sh exec /usr/lib64/cups/backend/powersocket --daemon *** ./vnc-fwd/run *** #!/bin/sh exec \ setuidgid nobody \ bin/vnc-fwd *** ./cups/run *** #!/bin/sh exec 2>&1 echo "*** Starting cups ***" # Set the timezone, if possible. This allows the scheduler and all ch +ild # processes to know the local timezone when reporting dates and times +to the # user. If no timezone information is found, then Greenwich Mean Time + (GMT) # will probably be used. [ "$TZ" ] && export TZ # Don't use TMPDIR environment variable from init script, as that can +cause # cupsd to set TempDir to a user's temporary directory instead of the # default. unset TMPDIR exec \ /usr/sbin/cupsd -f *** ./mdadm-monitor/run *** #!/bin/sh exec 2>&1 echo "*** Starting mdadm-monitor ***" exec \ mdadm --monitor \ --syslog \ --mail=root@localhost \ --delay=300 \ --test \ /dev/md0 /dev/md1 /dev/md2 *** ./smartd/run *** #!/bin/sh echo '*** starting smartd ***' exec 2>&1 # exec \ /usr/sbin/smartd -n echo "*** smartd crashed !!! ***" exec /command/svc -d . *** ./pg9/log/run *** #!/bin/sh exec \ setuidgid nobody \ multilog t s1000000 /var/multilog/pg9 *** ./pg9/run *** #!/bin/sh PGDATA=/data/pgdata exec 2>&1 echo "Starting postgresql with PGDATA=$PGDATA" exec \ setuidgid postgres \ /opt/pg9/bin/postmaster -D "$PGDATA"

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re^5: RFC: an(other) UNIX daemon module implementation
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-12-19 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (77 votes), past polls