UJP - 技術情報1

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

daemontoolsのインストール

daemontoolsのインストール


0.改訂履歴

  • 2006.02.07 新規作成
  • 2006.02.17 微調整

1.はじめに

 このドキュメントでは,qmailの作者であるD. J. Bernstein氏が提供する,daemontoolsのインストール手順を説明する. このツールでは,サーバプロセス(デーモン)の監視を行い,異常終了していたら自動的に再起動するという監視を行うことができる. 今回の目的では,qmailを監視させる為にこのツールを利用するが,daemontoolsで監視できるのはバックグラウンドサービスにならないプロセスのみとなっている.

 なお,RedHat Linux ES3.0上でおこなう.

2.インストール

  • モジュールを入手する.
[root@neptune Download]# wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
--16:05:38--  http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
           => `daemontools-0.76.tar.gz'
cr.yp.to をDNSに問いあわせています... 131.193.178.175
cr.yp.to[131.193.178.175]:80 に接続しています... 接続しました。

HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 36,975 [application/x-gzip]

100%[===================================================>] 36,975        50.28K/s             

16:05:40 (50.21 KB/s) - `daemontools-0.76.tar.gz' saved [36,975/36,975]

[root@neptune Download]#
  • 取得したアーカイブファイルを展開する.
[root@neptune Download]# tar zfx daemontools-0.76.tar.gz 
[root@neptune Download]# ls -la
合計 1248
drwxr-xr-x    3 root     root         4096  2月  7 16:06 .
drwxr-x---    5 root     root         4096  2月  7 15:22 ..
drwxr-xr-t    3 root     root         4096  7月 13  2001 admin
-rw-r--r--    1 root     root        36975  7月 13  2001 daemontools-0.76.tar.gz
-rw-r--r--    1 root     root      1158144  2月  7 14:20 qmail-1.03.tar
-rw-r--r--    1 root     root         2450 12月 20  1998 qmail-date-localtime.patch
-rw-r--r--    1 root     root        53019  3月 19  2000 ucspi-tcp-0.88.tar.gz
[root@neptune Download]#
  • 展開されたのはadminディレクトリなので,移動する.
[root@neptune Download]# cd admin
[root@neptune admin]# ls -la
合計 12
drwxr-xr-t    3 root     root         4096  7月 13  2001 .
drwxr-xr-x    3 root     root         4096  2月  7 16:06 ..
drwxr-xr-x    4 root     root         4096  7月 13  2001 daemontools-0.76
[root@neptune admin]# 
  • さらに中身を確認する.
[root@nepture admin]# cd daemontools-0.76
[root@neptune daemontools-0.76]# ls -la
合計 16
drwxr-xr-x    4 root     root         4096  7月 13  2001 .
drwxr-xr-t    3 root     root         4096  7月 13  2001 ..
drwxr-xr-x    2 root     root         4096  7月 13  2001 package
drwxr-xr-x    2 root     root         4096  7月 13  2001 src
[root@neptune daemontools-0.76]#  
  • まずは,コンパイルを行う.
[root@neptune daemontools-0.76]# ./package/compile
Linking ./src/* into ./compile...
Compiling everything in ./compile...
sh find-systype.sh > systype
rm -f compile
sh print-cc.sh > compile
chmod 555 compile
./compile byte_chr.c
./compile byte_copy.c
./compile byte_cr.c
./compile byte_diff.c
./compile byte_rchr.c
./compile fmt_uint.c
./compile fmt_uint0.c
./compile fmt_ulong.c
rm -f makelib
sh print-ar.sh > makelib
chmod 555 makelib
./compile scan_ulong.c
./compile str_chr.c
./compile str_diff.c
./compile str_len.c
./compile str_start.c
./makelib byte.a byte_chr.o byte_copy.o byte_cr.o byte_diff.o ¥
byte_rchr.o fmt_uint.o fmt_uint0.o fmt_ulong.o scan_ulong.o str_chr.o ¥
str_diff.o str_len.o str_start.o
rm -f choose
cat warn-auto.sh choose.sh ¥
| sed s}HOME}"`head -1 home`"}g ¥
> choose
chmod 555 choose
./choose c trydrent direntry.h1 direntry.h2 > direntry.h
./compile envdir.c
rm -f load
sh print-ld.sh > load
chmod 555 load
./compile alloc.c
./compile alloc_re.c
./compile buffer.c
./compile buffer_0.c
./compile buffer_1.c
./compile buffer_2.c
./compile buffer_get.c
./compile buffer_put.c
./compile buffer_read.c
./compile buffer_write.c
./compile coe.c
./compile env.c
./compile error.c
./compile error_str.c
./compile fd_copy.c
./compile fd_move.c
./choose cl trymkffo hasmkffo.h1 hasmkffo.h2 > hasmkffo.h
./compile fifo.c
./choose cl tryflock hasflock.h1 hasflock.h2 > hasflock.h
./compile lock_ex.c
./compile lock_exnb.c
./compile ndelay_off.c
./compile ndelay_on.c
./compile open_append.c
./compile open_read.c
./compile open_trunc.c
./compile open_write.c
./compile openreadclose.c
./compile pathexec_env.c
./compile pathexec_run.c
pathexec_run.c: 関数 `pathexec_run' 内:
pathexec_run.c:18: 警告: 関数 `execve' の暗黙の宣言
./compile chkshsgr.c
chkshsgr.c: 関数 `main' 内:
chkshsgr.c:10: 警告: 互換性のないポインタ型からの引数 2 個の `getgroups' を渡しますです

chkshsgr.c:10: 警告: 関数 `setgroups' の暗黙の宣言
./load chkshsgr 
./chkshsgr || ( cat warn-shsgr; exit 1 )
./choose clr tryshsgr hasshsgr.h1 hasshsgr.h2 > hasshsgr.h
./compile prot.c
prot.c: 関数 `prot_gid' 内:
prot.c:13: 警告: 関数 `setgroups' の暗黙の宣言
prot.c:15: 警告: 関数 `setgid' の暗黙の宣言
prot.c: 関数 `prot_uid' 内:
prot.c:20: 警告: 関数 `setuid' の暗黙の宣言
./compile readclose.c
./compile seek_set.c
seek_set.c: 関数 `seek_set' 内:
seek_set.c:9: 警告: 関数 `lseek' の暗黙の宣言
./compile sgetopt.c
./compile sig.c
./choose cl trysgprm hassgprm.h1 hassgprm.h2 > hassgprm.h
./compile sig_block.c
./choose cl trysgact hassgact.h1 hassgact.h2 > hassgact.h
./compile sig_catch.c
./compile sig_pause.c
./compile stralloc_cat.c
./compile stralloc_catb.c
./compile stralloc_cats.c
./compile stralloc_eady.c
./compile stralloc_opyb.c
./compile stralloc_opys.c
./compile stralloc_pend.c
./compile strerr_die.c
./compile strerr_sys.c
./compile subgetopt.c
./choose cl trywaitp haswaitp.h1 haswaitp.h2 > haswaitp.h
./compile wait_nohang.c
./compile wait_pid.c
./makelib unix.a alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o ¥
buffer_2.o buffer_get.o buffer_put.o buffer_read.o buffer_write.o ¥
coe.o env.o error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o ¥
lock_exnb.o ndelay_off.o ndelay_on.o open_append.o open_read.o ¥
open_trunc.o open_write.o openreadclose.o pathexec_env.o ¥
pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o ¥
sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o ¥
stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o ¥
stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o ¥
wait_pid.o
./load envdir unix.a byte.a 
envdir.o(.text+0xca): In function `main':
: undefined reference to `errno'
envdir.o(.text+0x1ea): In function `main':
: undefined reference to `errno'
unix.a(openreadclose.o)(.text+0x3b): In function `openreadclose':
: undefined reference to `errno'
unix.a(pathexec_run.o)(.text+0xf6): In function `pathexec_run':
: undefined reference to `errno'
unix.a(pathexec_run.o)(.text+0x13a): In function `pathexec_run':
: undefined reference to `errno'
unix.a(readclose.o)(.text+0x42): more undefined references to `errno' follow
collect2: ld はステータス 1 で終了しました
make: *** [envdir] エラー 1
Copying commands into ./command...
cp: cannot stat `compile/svscan': そのようなファイルやディレクトリはありません
[root@neptune daemontools-0.76]#  
  • DJBツールでよくあるエラーがでるので,error.hファイルを探す.
[root@neptune daemontools-0.76]# cd src
[root@neptune src]# ls -la err*
-rw-r--r-- 1 root root 1233 7月 13 2001 error.c
-rw-r--r-- 1 root root 595 7月 13 2001 error.h
-rw-r--r-- 1 root root 5502 7月 13 2001 error_str.c
[root@neptune src]#
  • 次のようにヘッダファイルを修正する.
修正前
/* Public domain. */

#ifndef ERROR_H
#define ERROR_H

extern int errno;

extern int error_intr;
extern int error_nomem;
extern int error_noent;
extern int error_txtbsy;
extern int error_io;
修正後
/* Public domain. */

#ifndef ERROR_H
#define ERROR_H

#include <errno.h>

extern int error_intr;
extern int error_nomem;
extern int error_noent;
extern int error_txtbsy;
extern int error_io;
  • 修正後,コンパイルを行う.
[root@neptune daemontools-0.76]# ./package/compile 
Linking ./src/* into ./compile...
Compiling everything in ./compile...
./compile envdir.c
./compile alloc.c
./compile buffer_get.c
./compile buffer_put.c
./compile error.c
./compile error_str.c
./compile openreadclose.c
./compile pathexec_run.c
pathexec_run.c: 関数 `pathexec_run' 内:
pathexec_run.c:18: 警告: 関数 `execve' の暗黙の宣言
./compile readclose.c
./compile strerr_sys.c
./compile wait_pid.c
./makelib unix.a alloc.o alloc_re.o buffer.o buffer_0.o buffer_1.o ¥
buffer_2.o buffer_get.o buffer_put.o buffer_read.o buffer_write.o ¥
coe.o env.o error.o error_str.o fd_copy.o fd_move.o fifo.o lock_ex.o ¥
lock_exnb.o ndelay_off.o ndelay_on.o open_append.o open_read.o ¥
open_trunc.o open_write.o openreadclose.o pathexec_env.o ¥
pathexec_run.o prot.o readclose.o seek_set.o sgetopt.o sig.o ¥
sig_block.o sig_catch.o sig_pause.o stralloc_cat.o stralloc_catb.o ¥
stralloc_cats.o stralloc_eady.o stralloc_opyb.o stralloc_opys.o ¥
stralloc_pend.o strerr_die.o strerr_sys.o subgetopt.o wait_nohang.o ¥
wait_pid.o
./load envdir unix.a byte.a 
./compile envuidgid.c
./load envuidgid unix.a byte.a 
./compile fghack.c
./load fghack unix.a byte.a 
./compile match.c
./compile matchtest.c
matchtest.c: 関数 `main' 内:
matchtest.c:22: 警告: 関数 `_exit' の暗黙の宣言
./load matchtest match.o unix.a byte.a 
./choose clr trypoll iopause.h1 iopause.h2 > iopause.h
./choose clr tryulong64 uint64.h1 uint64.h2 > uint64.h
./compile deepsleep.c
./compile multilog.c
multilog.c: 関数 `startprocessor' 内:
multilog.c:200: 警告: 互換性のないポインタ型からの引数 2 個の `execve' を渡しますです

multilog.c: 関数 `fullcurrent' 内:
multilog.c:216: 警告: 関数 `rename' の暗黙の宣言
./choose c trysysel select.h1 select.h2 > select.h
./compile iopause.c
./compile tai_now.c
./compile tai_pack.c
./compile tai_sub.c
./compile tai_unpack.c
./compile taia_add.c
./compile taia_approx.c
./compile taia_frac.c
./compile taia_less.c
./compile taia_now.c
./compile taia_pack.c
./compile taia_sub.c
./compile taia_uint.c
./makelib time.a iopause.o tai_now.o tai_pack.o tai_sub.o ¥
tai_unpack.o taia_add.o taia_approx.o taia_frac.o taia_less.o ¥
taia_now.o taia_pack.o taia_sub.o taia_uint.o
./compile timestamp.c
./load multilog deepsleep.o timestamp.o match.o time.a unix.a byte.a 
./compile pgrphack.c
./load pgrphack unix.a byte.a 
./compile readproctitle.c
./load readproctitle unix.a byte.a 
./compile setlock.c
./load setlock unix.a byte.a 
./compile setuidgid.c
./load setuidgid unix.a byte.a 
./compile softlimit.c
./load softlimit unix.a byte.a 
./compile supervise.c
supervise.c: 関数 `announce' 内:
supervise.c:78: 警告: 関数 `rename' の暗黙の宣言
supervise.c: 関数 `trystart' 内:
supervise.c:102: 警告: 互換性のないポインタ型からの引数 2 個の `execve' を渡しますです

./load supervise deepsleep.o time.a unix.a byte.a 
./compile svc.c
./load svc unix.a byte.a 
./compile svok.c
./load svok unix.a byte.a 
./compile svscan.c
svscan.c: 関数 `start' 内:
svscan.c:104: 警告: 互換性のないポインタ型からの引数 3 個の `pathexec_run' を渡しますです

svscan.c:123: 警告: 互換性のないポインタ型からの引数 3 個の `pathexec_run' を渡しますです

./load svscan unix.a byte.a 
rm -f svscanboot
cat warn-auto.sh svscanboot.sh ¥
| sed s}HOME}"`head -1 home`"}g ¥
> svscanboot
chmod 555 svscanboot
./compile svstat.c
./load svstat time.a unix.a byte.a 
./compile tai64n.c
./load tai64n timestamp.o time.a unix.a byte.a 
./compile tai64nlocal.c
./load tai64nlocal unix.a byte.a 
env - /bin/sh rts.tests 2>&1 | cat -v > rts
rm -f sysdeps
cat systype compile load >> sysdeps
grep sysdep direntry.h >> sysdeps
grep sysdep haswaitp.h >> sysdeps
grep sysdep hassgact.h >> sysdeps
grep sysdep hassgprm.h >> sysdeps
grep sysdep select.h >> sysdeps
grep sysdep uint64.h >> sysdeps
grep sysdep iopause.h >> sysdeps
grep sysdep hasmkffo.h >> sysdeps
grep sysdep hasflock.h >> sysdeps
grep sysdep hasshsgr.h >> sysdeps
Copying commands into ./command...
[root@neptune daemontools-0.76]#  
  • コンパイルが終了したようである.
  • インストールのために,次のようなスクリプトを作成する.
[root@neptune daemontools-0.76]# ls -la
合計 32
drwxr-xr-x    6 root     root         4096  2月  7 16:44 .
drwxr-xr-t    3 root     root         4096  7月 13  2001 ..
drwxr-xr-x    2 root     root         4096  2月  7 16:20 command
drwxr-xr-x    3 root     root         8192  2月  7 16:20 compile
-rwxr-xr-x    1 root     root          249  2月  7 16:12 install.sh
drwxr-xr-x    3 root     root         4096  2月  7 16:44 package
drwxr-xr-x    2 root     root         4096  2月  7 16:20 src
[root@neptune daemontools-0.76]# cat install.sh 
#!/bin/sh

install_dir=/usr/local/bin

for file in command/*
do
        if ( file ${file} | grep -i 'shell script' ) ; then
                install -o root -g root -m 0755 ${file} ${install_dir}
        else
                install -o root -g root -m 0755 -s ${file} ${install_dir}
        fi
done
[root@neptune daemontools-0.76]#  
[root@neptune daemontools-0.76]# chmod ogu+x install.sh 
[root@neptune daemontools-0.76]#  
  • 作成したプログラムを実行する.
[root@neptune daemontools-0.76]# ./install.sh 
command/svscanboot: Bourne shell script text executable
[root@neptune daemontools-0.76]#  
  • サービスの起動・終了を管理するためにサービスディレクトリを作成する.
[root@neptune daemontools-0.76]# mkdir /var/service
[root@neptune daemontools-0.76]#
  • svscanbootコマンドスクリプトを,インストールしたディレクトリにあわせて変更する.
    • デフォルトでは,/commandや/serviceというディレクトリを前提として作成されているので,これを/usr/local/binや/var/serviceに変更する.
[root@neptune daemontools-0.76]# pwd
/root/Download/admin/daemontools-0.76
[root@neptune daemontools-0.76]# sed -e 's#/command;##' ¥
> -e 's#command/#usr/local/bin/#g' ¥
> -e 's#/service#/var/service#g' ¥
> command/svscanboot > /usr/local/bin/svscanboot
[root@neptune daemontools-0.76]#  
  • 変更された箇所を確認する.
[root@neptune daemontools-0.76]# ls -la /usr/local/bin/svscanboot
-rwxr-xr-x    1 root     root          758  2月  7 17:03 /usr/local/bin/svscanboot
[root@neptune daemontools-0.76]# diff command/svscanboot /usr/local/bin/svscanboot
10c10
< /command/svc -dx /service/* /service/*/log
---
> /usr/local/bin/svc -dx /var/service/* /var/service/*/log
12c12
< env - PATH=$PATH svscan /service 2>&1 | ¥
---
> env - PATH=$PATH svscan /var/service 2>&1 | ¥
[root@neptune daemontools-0.76]#  
  • 作成されたsvscanbootを確認する.
[root@neptune daemontools-0.76]# cat /usr/local/bin/svscanboot
#!/bin/sh
# WARNING: This file was auto-generated. Do not edit!

PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

exec </dev/null
exec >/dev/null
exec 2>/dev/null

/usr/local/bin/svc -dx /var/service/* /var/service/*/log

env - PATH=$PATH svscan /var/service 2>&1 | ¥
env - PATH=$PATH readproctitle service errors: ..........................................
.........................................................................................
.........................................................................................
.........................................................................................
.........................................................................................
..
[root@neptune daemontools-0.76]#  
  • /etc/inittabに,追加する.
[root@neptune daemontools-0.76]# echo SV:123456:respawn:/usr/local/bin/svscanboot ¥
> >> /etc/inittab
[root@neptune daemontools-0.76]#
  • HUPシグナルをプロセス1に送信する.initは常にプロセス番号が1である.
[root@neptune daemontools-0.76]# kill -HUP 1
[root@neptune daemontools-0.76]#
  • svscanプロセスが稼働しているか確認する.
[root@neptune daemontools-0.76]# ps -ef | grep svs
root      6464     1  0 17:19 ?        00:00:00 /bin/sh /usr/local/bin/svscanboot
root      6466  6464  0 17:19 ?        00:00:00 svscan /var/service
root      6476  1274  0 17:21 pts/0    00:00:00 grep svs
[root@neptune daemontools-0.76]#  
  • svscanbootが,プロセスNo.1を親として起動していることが確認できた.


広告スペース
Google