[완료] 새로만든 프로그램 데몬화 작업에 관한 질문입니다.

kimyh의 이미지

얼마전에도 비슷한 질문을 올렸는데 아직도 해결을 못해서요.

새로만든 프로그램을 ntsysv에 등록하여 부팅시마다 동작 하게 할려고 합니다.
실행파일을 /usr/sbin에 카피하고 데몬스크립트를 /etc/rc.d/init.d 에도 카피해서 부팅시 데몬스크립트도 제대로 동작 하는것 같습니다.

그런데 /usr/sbin 아래에 있는 실행파일에 문제가 있는지 제대로 실행을 하지 않습니다.
물론 수동으로 실행시키거나 /etc/rc.d/rc.local 에 ./ipdns & 백그라운드로 스크립트를 넣고 돌려보면
문제 없이 잘 돌아 갑니다.

그런데 확인해보면 ntsysv에 등록도 잘 되어 있고 부팅 프로세스 화면에 활성화되어 잘 되는것 같은데
부팅후에 확인 해보면 /usr/sbin/ 아래에 있는 실행파일이 제대로 동작을 하지 않습니다.

그리고 이해 할수 없는건 /etc/rc.d/init.d/ipdns restart 하면 아래와같이 나온다는 겁니다.
starting 이 확인 되었는데 다음에 Stopping 이 왜 실패가 나오는가 하는겁니다.

[root@localhost root]# /etc/rc.d/init.d/ipdns restart
Stopping ipdns: [실패]
Starting ipdns: [ 확인 ]
[root@localhost root]# /etc/rc.d/init.d/ipdns restart
Stopping ipdns: [실패]
Starting ipdns: [ 확인 ]
[root@localhost root]#

실행파일을 아래와같이 만들었는데 데몬화하는데 문제가 있는지 아니면 데몬 스크립트와 매칭이 되지 않은건지 도무지 방법을 찾을수가 없군요.

소스중 실행파일 해당부분;

//   메인 프로세스       
      int main()
    {
// 리눅스 ntsysv에 등록하여 부팅시 자동실행하기위한 조치     
        switch( fork() )
              {
                case -1:
                        exit(1);
                case 0:
                setsid(); /* become session leader */
                chdir("."); /* change working directory */
                umask(0); /* clear our file mode creation mask */
                break;
                  default:
                        exit(0);
              }
// 리눅스 ntsysv에 등록하여 부팅시 자동실행하기위한 조치 끝
 
//   WHILE문 시작 
        while(1)
         {
           ............
           ...........
           30초마다 새로운 작업을 하여 그 결과가
             이전 작업결과와 다를경우에만 소켓으로 서버에 그 처리결과를 전송헤
             주는 작업임 
           ..........
           ............
      sleep(30); //30초마다 새로운 작업을 수행 
        } // while문 끝
   } // main문 끝 

데몬 스크립트(다른 데몬 스크립트를 복사해서 수정 한것입니다.);

#! /bin/sh
#
 
# chkconfig: 345 50 50
 
# description: ipdns dynamic dns ip update.
# processname: ipdns
# Author : yang-hyun Kim < <a href="mailto:admin@ipnara.com" rel="nofollow">admin@ipnara.com</a> >
# Date : 2007.01.01
# <a href="http://www.ipnara.com" rel="nofollow">http://www.ipnara.com</a>
# pidfile: /var/run/ipdns.pid
 
# Registe ipdns daemon on ntsysv and checking on it.
/sbin/chkconfig --add ipdns
/sbin/chkconfig --level 345 ipdns on
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Get config.
. /etc/sysconfig/network
 
# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
        exit 0
fi
 
[ -f /usr/sbin/ipdns ] || exit 0
 
# See how we were called.
case "$1" in
  start)
        echo -n "Starting ipdns: "
        daemon /usr/sbin/ipdns -x
 
        echo
        touch /var/lock/subsys/ipdns
        ;;
  stop)
        echo -n "Stopping ipdns: "
        killproc /usr/sbin/ipdns
        echo
        rm -f /var/lock/sbsys/ipdns
        ;;
  status)
        status ipdns
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: ipdns  {start|stop|status|restart}"
        exit 1
esac
 
exit 0

이것 때문에 며칠을 고생 하고 있습니다.
아직 내공이 약해 처음으로 이런작업을 할려니 여간 어려운게 아니군요.
도움 주시면 감사하겠습니다.

kimyh의 이미지

같은 문제로 혹시 고생 하시는 분이 계실까하여 올립니다.
위의 데몬 스크립트를 기존의 것을 수정하는 과정에서 오류가 있었습니다.
위의 데몬 스크립트중
daemon /usr/sbin/ipdns -x
이부분을
cd /usr/sbin/
daemon ipdns -x로 수정 하니까 해결 되더군요.

관심 가져주신분들께 감사드립니다.

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

puresupe의 이미지

큰 도움 되었습니다 ;-;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.