home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume16 / ichk / part01 next >
Internet Message Format  |  1991-01-19  |  22KB

  1. From: jgd@Dixie.Com (John G. DeArmond)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i075:  Ichk - The inode/filesystem checker, Part01/01
  4. Message-ID: <1991Jan14.223223.28476@sparky.IMD.Sterling.COM>
  5. Date: 14 Jan 91 22:32:23 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 70760352 2ac63ed3 220050e1 2afcf83f
  8.  
  9. Submitted-by: jgd@Dixie.Com (John G. DeArmond)
  10. Posting-number: Volume 16, Issue 75
  11. Archive-name: ichk/part01
  12.  
  13. Ichk is a quick program and script that I wrote in order to address the
  14. Interactive (and other) System V Inode bug.  Ichk sits as a daemon and
  15. checks the  designated filesystem at specified intervals against
  16. specified limits.  If a problem is found such as too few inodes, too few
  17. free blocks or the ratio of blocks to inodes becomes too large, then a
  18. child process is started which is passed an argument that indicates the
  19. problem.  The child process or script should look at the arguments and
  20. take corrective action. An example script that works against the news
  21. partition on Dixie.com is included.  
  22.  
  23. Though a fix for the inode problem from ISC would be ideal and a patch
  24. for the kernel has been posted to the net, this programs directly
  25. addresses the problem without kernal patches (which indicates a full
  26. backup to any responsible sysadm - you got any idea how long it takes to
  27. backup 1GB to 60 meg tape? :-).  Plus it catches other problems such as
  28. the news partition just flat running out of space from a flood of news. 
  29.  
  30. This program is free of any encumbrances on use (see inode.txt for
  31. details) and is free of the GNU General Public Virus.  Comments, bug
  32. reports and improvements appreciated.   In particular, I'd appreciate
  33. the results of porting this program to Berzerkly or other variant
  34. Unixes.
  35.  
  36. John De Armond
  37. jgd@dixie.com
  38.  
  39. ---- Cut Here and unpack ----
  40. #!/bin/sh
  41. # This is ichk, a shell archive (shar 3.11)
  42. # made 01/14/1991 06:07 UTC by jgd@dixie.com
  43. # Source directory /usr/local/tools/ichk
  44. #
  45. # existing files WILL be overwritten
  46. #
  47. # This shar contains:
  48. # length  mode       name
  49. # ------ ---------- ------------------------------------------
  50. #   1963 -rwxr-xr-x Inodes
  51. #   1389 -rw-r--r-- README
  52. #   5937 -r--r--r-- ichk.c
  53. #   7310 -rw-r--r-- ichk.txt
  54. #    567 -rw-rw---- makefile
  55. #
  56. touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
  57. if [ -s /tmp/s3_touch$$ ]
  58. then
  59.     TOUCH=can
  60. else
  61.     TOUCH=cannot
  62. fi
  63. rm -f /tmp/s3_touch$$
  64. # ============= Inodes ==============
  65. echo "x - extracting Inodes (Text)"
  66. sed 's/^X//' << 'SHAR_EOF' > Inodes &&
  67. X# @(#) Inodes 1.7 91/01/14  00:29:18";  
  68. X
  69. X
  70. X# this shell script is invoked by ichk whenever there is a news filesystem
  71. X# emergency such as if the inodes count or free disk should fall 
  72. X# below critical levels
  73. X
  74. XLIBD=/usr/local/news/bin
  75. XSPOOLD=/news/spool
  76. XLOCK=/usr/spool/locks/LCK..news
  77. X#NEWSSLICE=/dev/dsk/c0d1p5
  78. XNEWSSLICE=`grep $1 /etc/fstab | cut -d" " -f1`
  79. XEXPIRE=/usr/local/news/bin/expire
  80. XTMPFILE=/tmp/Clean.tmp
  81. XNNMASTER="/usr/local/news/nnbin/nnmaster -r -E -C"
  82. XDAYS=5
  83. X
  84. XFLAG=0
  85. X# first, check for inode shortage.
  86. X#
  87. Xif [ "$2" = "inode" -o "$2" = "ratio" ]
  88. Xthen
  89. X
  90. X    trap "rm -f $LOCK; exit" 0 1 2 3 15
  91. X    /bin/touch $LOCK
  92. X    echo Cleaning /news: inodes problem ---- `date` >>$LIBD/cleanlog
  93. X    echo Cleaning /news: inodes problem >/dev/osm
  94. X
  95. X
  96. X# algorithm changed 09/28/90 JGD.  If we are out of Inodes, then
  97. X# we're dumping news on the ground anyway so go ahead and kill rnews
  98. X# and/or any other process running on the partition.
  99. X
  100. X    echo "
  101. X                     ATTENTION: 
  102. X    The news partition must be cleaned up.  All news-related
  103. X    processes will be terminated in 30 seconds.  Please
  104. X    finish your work and clear out of news.
  105. X    " | \
  106. X    /etc/wall     
  107. X
  108. X    sleep 30
  109. X    touch $LOCK
  110. X    /etc/fuser -k $NEWSSLICE >/dev/null 2>&1
  111. X    #just to be sure
  112. X    /etc/fuser -k $NEWSSLICE >/dev/null 2>&1
  113. X    # lock again just in case anything that got "fused" removed a lock"
  114. X    touch $LOCK
  115. X
  116. X    # then run the fsck
  117. X    #$LIBD/fixnewsfs $NEWSSLICE >/dev/null 2>&1
  118. X    /etc/umount $NEWSSLICE
  119. X    /etc/fsck -y $NEWSSLICE >/dev/null 2>&1
  120. X    /etc/mount $NEWSSLICE
  121. X
  122. X    # finally, restart nnmaster
  123. X    $NNMASTER
  124. X
  125. X    echo "Subject: Inode cleanup \nInodes cleaned up at `date` " | mail jgd pda
  126. X
  127. Xfi
  128. X
  129. X# next, check to see if we ran out of blocks 
  130. X#
  131. Xif [ "$2" = "block" ]
  132. Xthen
  133. X        echo "Freespace hit danger mark, cleaning up - `date`" >>$LIBD/cleanlog
  134. X        echo "Freespace hit danger mark, cleaning up" >/dev/osm
  135. X
  136. X        find $SPOOLD -type f -mtime +$DAYS -print | xargs rm -f 
  137. X        FLAG=1
  138. Xfi
  139. X
  140. Xif [ $FLAG -eq 1 ]
  141. Xthen
  142. X    $EXPIRE -r -I -e 999999 -E 999999
  143. Xfi
  144. Xrm -f $LOCK
  145. X
  146. SHAR_EOF
  147. chmod 0755 Inodes || echo "restore of Inodes fails"
  148. if [ $TOUCH = can ]
  149. then
  150.     touch -am 0114003091 Inodes
  151. fi
  152. set `wc -c Inodes`;Wc_c=$1
  153. if test "$Wc_c" != "1963"
  154. then echo original size 1963, current size $Wc_c;fi
  155. # ============= README ==============
  156. echo "x - extracting README (Text)"
  157. sed 's/^X//' << 'SHAR_EOF' > README &&
  158. X                       ICHK - The Inode Checker
  159. X
  160. XIchk is a quick program and script that I wrote in order to address the
  161. XInteractive (and other) System V Inode bug.  Ichk sits as a daemon and
  162. Xchecks the  designated filesystem at specified intervals against
  163. Xspecified limits.  If a problem is found such as too few inodes, too few
  164. Xfree blocks or the ratio of blocks to inodes becomes too large, then a
  165. Xchild process is started which is passed an argument that indicates the
  166. Xproblem.  The child process or script should look at the arguments and
  167. Xtake corrective action. An example script that works against the news
  168. Xpartition on Dixie.com is included.  
  169. X
  170. XThough a fix for the inode problem from ISC would be ideal and a patch
  171. Xfor the kernel has been posted to the net, this programs directly
  172. Xaddresses the problem without kernal patches (which indicates a full
  173. Xbackup to any responsible sysadm - you got any idea how long it takes to
  174. Xbackup 1GB to 60 meg tape? :-).  Plus it catches other problems such as
  175. Xthe news partition just flat running out of space from a flood of news. 
  176. X
  177. XThis program is free of any encumbrances on use (see inode.txt for
  178. Xdetails) and is free of the GNU General Public Virus.  Comments, bug
  179. Xreports and improvements appreciated.   In particular, I'd appreciate
  180. Xthe results of porting this program to Berzerkly or other variant
  181. XUnixes.
  182. X
  183. XJohn De Armond
  184. Xjgd@dixie.com
  185. X
  186. SHAR_EOF
  187. chmod 0644 README || echo "restore of README fails"
  188. if [ $TOUCH = can ]
  189. then
  190.     touch -am 0114010791 README
  191. fi
  192. set `wc -c README`;Wc_c=$1
  193. if test "$Wc_c" != "1389"
  194. then echo original size 1389, current size $Wc_c;fi
  195. # ============= ichk.c ==============
  196. echo "x - extracting ichk.c (Text)"
  197. sed 's/^X//' << 'SHAR_EOF' > ichk.c &&
  198. X
  199. X#ifdef SCCSID
  200. Xstatic sccsid[] = "@(#) ichk.c 1.4 91/01/14  00:51:20";  
  201. X#endif
  202. X
  203. X#include <stdio.h>
  204. X#include <sys/types.h>
  205. X#include <sys/statfs.h>
  206. X#include <sys/signal.h>
  207. X
  208. X/* this program checks vital parameters on the file system it is invoked
  209. X** against and when a problem is found, runs a specified program that
  210. X** remedies the problem (hopefully).
  211. X**
  212. X** This program must be setuid root and/or run from root 
  213. X*/
  214. X
  215. Xstruct statfs buf;
  216. Xlong inode_trigger = 200L;
  217. Xlong block_trigger = 1000L;
  218. Xlong ratio = 5L;
  219. Xint i;
  220. Xchar file_sys[256];
  221. Xchar action[256];
  222. Xchar c;
  223. Xint verbose=0;
  224. Xint snooze=10;
  225. Xlong i_ratio;
  226. Xint talk=0;
  227. X
  228. Xextern int optind;
  229. Xextern char *optarg;
  230. Xextern int errno;
  231. Xextern void usage();
  232. Xextern void take_action();
  233. Xextern char *decimalize();
  234. Xextern void terminator();
  235. X
  236. Xmain(argc,argv)
  237. Xint argc;
  238. Xchar **argv;
  239. X{
  240. X
  241. X#ifdef DAEMON
  242. X    /* do NOT do this if you run ichk from init.  Init gets real pissed */
  243. X    /* with processes that try to daemonize themselves */
  244. X    if (fork())
  245. X        exit(0);
  246. X#endif
  247. X
  248. X    setpgrp();    /* make us a little bit independent */
  249. X
  250. X
  251. X    signal(SIGTERM,terminator);
  252. X    signal(SIGINT,terminator);
  253. X    signal(SIGHUP,terminator);
  254. X
  255. X    action[0] = '\0';
  256. X
  257. X    if (argc < 2) {
  258. X        usage();
  259. X    }
  260. X
  261. X    if ( setuid(0) ) {
  262. X        fprintf(stderr,"*** ERROR: Setuid root failed");
  263. X        sleep(5);
  264. X        exit(2);
  265. X    }            
  266. X    
  267. X    if ( setgid(0) ) {
  268. X        fprintf(stderr,"*** ERROR: Setgid root failed");
  269. X        sleep(5);
  270. X        exit(3);
  271. X    }            
  272. X
  273. X    while ( (c =  getopt(argc, argv, "a:b:i:r:s:vt")) != -1 ) {
  274. X        switch (c) {
  275. X            case 'a':    /* specifies the action to take */
  276. X                strcpy(action,optarg);
  277. X                break;
  278. X            case 'b':    /* low block count threshold */
  279. X                block_trigger = atol(optarg);
  280. X                if (block_trigger == 0L)
  281. X                    usage();
  282. X                break;
  283. X            case 'i':
  284. X                inode_trigger=atol(optarg);
  285. X                if (inode_trigger == 0L)
  286. X                    usage();
  287. X                break;
  288. X            case 'r':
  289. X                ratio=atol(optarg);
  290. X                if (ratio == 0L) 
  291. X                    usage();
  292. X                break;
  293. X            case 'v':
  294. X                verbose=1;
  295. X                break;
  296. X            case 's':
  297. X                snooze = atoi(optarg);
  298. X                if (snooze == 0 ) 
  299. X                    usage();
  300. X                break;
  301. X            case 't':    /* give a report only or (t)alk */
  302. X                talk=1;
  303. X                break;
  304. X            case '?':
  305. X                usage();
  306. X                break;
  307. X        }
  308. X    }
  309. X    if (talk) verbose = 0;
  310. X
  311. X    strcpy(file_sys,argv[optind]);
  312. X
  313. X    if (verbose)
  314. X        printf("pid = %d\n", getpid());
  315. X
  316. X    errno=0;
  317. X    if ( statfs(file_sys, &buf, sizeof(struct statfs), 0) == -1) {
  318. X        fprintf(stderr,"*** ERROR: statfs() failed, errno = %d\n",errno);
  319. X        fprintf(stderr,"file_sys = <%s>\n", file_sys);
  320. X        fprintf(stderr,"sizeof(struct statfs) = %d \n", sizeof(struct statfs));
  321. X        sleep(10); /* keeps init happy */
  322. X        exit(4);
  323. X    }
  324. X
  325. X    if (talk) {
  326. X        printf("%s %ld %ld ", buf.f_fname, buf.f_blocks, buf.f_bfree);
  327. X        printf("%ld %ld %s\n", buf.f_files, buf.f_ffree, 
  328. X            decimalize((buf.f_bfree*10L) / (buf.f_ffree))); 
  329. X        exit(0);
  330. X
  331. X    }
  332. X
  333. X
  334. X    if (verbose) {
  335. X        printf("File system type =    %d\n", buf.f_fstyp);
  336. X        printf("Total blocks =        %ld\n", buf.f_blocks);
  337. X        printf("Free blocks =         %ld\n", buf.f_bfree);
  338. X        printf("Total inodes =        %ld\n", buf.f_files);
  339. X        printf("Free inodes =         %ld\n", buf.f_ffree);
  340. X        printf("Volume name =         %s\n", buf.f_fname);
  341. X    }
  342. X
  343. X    while (1) {
  344. X
  345. X        i_ratio = (buf.f_bfree*10L) / buf.f_ffree;  
  346. X        /* preserving one decimal place of rounding */
  347. X
  348. X        /* ratio of blocks to inodes will go UP when the system starts losing
  349. X            inodes */
  350. X        if ( i_ratio >= (ratio*10L) ) {
  351. X            if (verbose)
  352. X                printf("Block to Inode ratio %s is too high\n", decimalize(i_ratio));
  353. X            take_action("ratio");
  354. X            goto slumber;
  355. X        } else {
  356. X            if (verbose)
  357. X                printf("Block to Inode ratio is %s\n", decimalize(i_ratio));
  358. X        }
  359. X
  360. X        if (buf.f_ffree < inode_trigger) {
  361. X            if (verbose)
  362. X                printf("Inodes low threshold triggered at %ld inodes\n", 
  363. X                    buf.f_ffree);
  364. X            take_action("inode");
  365. X            goto slumber;
  366. X        } else {
  367. X            if (verbose)
  368. X                printf("Inodes = %ld\n", 
  369. X                    buf.f_ffree);
  370. X        }    
  371. X
  372. X        if (buf.f_bfree < block_trigger) {
  373. X            if (verbose)
  374. X                printf("Blocks low threshold triggered at %ld blocks\n", 
  375. X                    buf.f_bfree);
  376. X            take_action("block");
  377. X            goto slumber;
  378. X        } else {
  379. X            if (verbose)
  380. X                printf("Blocks = %ld\n", 
  381. X                    buf.f_bfree);
  382. X        }    
  383. X
  384. X    slumber:
  385. X        sleep(snooze);
  386. X
  387. X    } /* for (;;) */
  388. X
  389. X    /* NOTREACHED */
  390. X    sleep(5);
  391. X    exit(0);
  392. X} /* main */
  393. X
  394. Xvoid
  395. Xtake_action(x)
  396. Xchar x[]; /* problem to be remedied */
  397. X{
  398. X    char buff[256];
  399. X
  400. X    if (!strlen(action)) 
  401. X        return;
  402. X
  403. X    sprintf(buff,"%s %s %s", action, file_sys, x);
  404. X    if (verbose)
  405. X        printf("Action taken:  Command line to system()\n\t%s\n",buff);
  406. X
  407. X    system(buff);
  408. X    return;
  409. X}
  410. X
  411. Xchar *
  412. Xdecimalize(x)
  413. Xlong x;
  414. X{
  415. X    static char buff[256];
  416. X    int len;
  417. X
  418. X    memset(buff,'\0',256);
  419. X
  420. X    sprintf(buff,"%ld", x);
  421. X    len = strlen(buff);
  422. X
  423. X    buff[len] = buff[len-1]; /* move last char over one to the right*/
  424. X    buff[len-1] = '.';
  425. X
  426. X    return(buff);
  427. X}
  428. X
  429. Xvoid
  430. Xusage()
  431. X{
  432. X
  433. X    fprintf(stderr,
  434. X    "\nUsage:\n\nichk <-a action>\n  <-i inode_trig>\n  <-r ratio>\n  <-v>\n");
  435. X    fprintf(stderr,
  436. X    "  <-s sleep_secs>\n  <-b block_count_trigger>\n  <-t>\n file_system_name\n");
  437. X    fprintf(stderr,
  438. X       "\nThe defaults are %ld inodes, %ld:1 block_to_inodes_ratio,\n", 
  439. X       inode_trigger, ratio);    
  440. X    fprintf(stderr,
  441. X       "%ld blocks, action = nothing and %d seconds between checks.\n", 
  442. X       block_trigger, snooze);
  443. X    fprintf(stderr,
  444. X        "\nWhen the <action> program is invoked, the program is passed the\n");
  445. X    fprintf(stderr,
  446. X    "following arguments:\nargv[1] == the file system\nargv[2] == the problem\n");
  447. X    fprintf(stderr,
  448. X    "\nargv[2] can be:\nratio      = ratio of blocks to inodes exceeded.\n");
  449. X    fprintf(stderr,
  450. X    "inode      = the low inode threshold exceeded.\n");
  451. X    fprintf(stderr,
  452. X    "block      = the low block threshold exceeded.\n");
  453. X    fprintf(stderr,
  454. X    "If the -t (talk) flag is specified, all other options are ignored and\n");
  455. X    fprintf(stderr,
  456. X    "ichk reports the status of the file system in the form:\n fs_name ");
  457. X    fprintf(stderr,
  458. X    "block_count blocks_free inode_count inodes_free ratio_blocks_2_inodes\n");
  459. X    
  460. X    sleep(5);
  461. X    exit(1);
  462. X}
  463. Xvoid
  464. Xterminator(x)
  465. Xint x;
  466. X{
  467. X    fprintf(stderr,"Signal caught: ichk going down on signal %d\n", x);
  468. X    exit(0);
  469. X}
  470. SHAR_EOF
  471. chmod 0444 ichk.c || echo "restore of ichk.c fails"
  472. if [ $TOUCH = can ]
  473. then
  474.     touch -am 0114005191 ichk.c
  475. fi
  476. set `wc -c ichk.c`;Wc_c=$1
  477. if test "$Wc_c" != "5937"
  478. then echo original size 5937, current size $Wc_c;fi
  479. # ============= ichk.txt ==============
  480. echo "x - extracting ichk.txt (Text)"
  481. sed 's/^X//' << 'SHAR_EOF' > ichk.txt &&
  482. X
  483. X                          Ichk - The Inode Checker.
  484. X                            Version 1.0 01/13/91
  485. X
  486. XIchk is designed to watch the condition of a file system and if specified
  487. Xbounds are exceeded, to fire off a corrective process or script.  Ichk is
  488. Xdesigned to be run from init(1) as a respawned job.  The program was originally
  489. Xwritten to address the famous SysV inode bug that typically manifests 
  490. Xitself in conjunction with news but it has many more uses.
  491. X
  492. XWhen ichk is invoked, it uses statfs(2) to collect statistics on the 
  493. Xfile system specified in the command line.  It then compares the number
  494. Xof free blocks, the number of free inodes and the ratio of free blocks
  495. Xto free inodes to specified values or defaults.  If any limits are
  496. Xexceeded, a child process is started via system(3S).  
  497. X
  498. XThe child process is passed the name of the file system and a keyword
  499. Xthat specifies the problem to be addresses.  Typical action would be in
  500. Xthe case of low inodes or increasing blocks to inodes would be to unmount
  501. Xthe affected partition and fsck it and remount it.  Typical action for
  502. Xlow blocks might be to run an emergency expire on the news partition. 
  503. X
  504. XI have observed that when the inode bug is manifesting itself, the 
  505. Xfirst indication is that as the inode count decreases rapidly, the
  506. Xratio of blocks to inodes increases.  Thus, it is possible to catch the
  507. Xproblem before the inodes run completely out and data is dropped.
  508. X
  509. XAfter any corrective action is run or if there is no problem, the daemon 
  510. Xsleeps for a designated period and then repeats the process.  Here at
  511. XDixie Communications, ichk is designated to examine things once a 
  512. Xminute.
  513. X
  514. XIchk also has an information, or "talk" mode that only reports statistics
  515. Xand then exits.  This makes ichk useful for reporting file system information
  516. Xto a corrective script and is somewhat easier and less resource intensive
  517. Xto use than df.
  518. X
  519. XIchk is equipped with sleeps of 5 seconds at all exit points which should
  520. Xkeep init happy in case something makes the program exit prematurely.
  521. XNote that if ichk is killed while a corrective process is running, ichk
  522. Xmakes no attempt to kill the child.  It is assumed that the child may
  523. Xbe  executing  actions that would be destructive if  not  run  to 
  524. Xcompletion.
  525. XTherefore if you want to kill the child process, you'll have to do it
  526. Xmanually.
  527. X
  528. XOPTIONS
  529. X
  530. XIchk has several options that may be specified at invocation.  Most options
  531. Xhave reasonable defaults.  Following are listed each of the options and
  532. Xan explanation of each.
  533. X
  534. X
  535. XUsage:
  536. X
  537. ichk <-a action> <-i inode_trig> <-r ratio> <-v> <-s sleep_secs>
  538. X  <-b block_count_trigger> <-t> file_system_name
  539. X
  540. X
  541. X-a action  Specifies the process or script to be invoked in the event a 
  542. X    limit is exceeded.  Multiple options to the child process should
  543. X    be quoted to keep the shell happy.  When the child process is invoked,
  544. X    it receives all commands specified with the -a option plus the
  545. X    name of the affected file system and a keyword that specifies the
  546. X    problem.  The keywords are:
  547. X
  548. X        ratio      = ratio of blocks to inodes exceeded.
  549. X        inode      = the low inode threshold exceeded.
  550. X        block      = the low block threshold exceeded.
  551. X    
  552. X    The default is to do nothing; ie, there is no default command 
  553. X    specified and ichk will do nothing without a specification.
  554. X
  555. X-i inode_trigger  Specifies the low inode trigger point.  When the free 
  556. X    inode count is found to fall below this point, the <action> child
  557. X    process is invoked. If -i is not specified, then the default of 200 
  558. X    inodes is used.
  559. X
  560. X-r ratio  Specifies the integer ratio of blocks to inodes above which the
  561. X    <action> child process is invoked.  The default value is 5:1.
  562. X
  563. X-s seconds  Specifies how many seconds ichk waits between checks of the
  564. X    filesystem.  The default is 10 seconds.
  565. X
  566. X-b block_count  Specifies the minimum block count below which the <action>
  567. X    child process is invoked.  The default is 1000 blocks.
  568. X
  569. X-t  Specifies the "talk mode" which reports the statistics of the file system
  570. X    and then exits.  The statistics are presented in a format easily used
  571. X    in script files.  The format is:
  572. X
  573. X     fs_name block_count blocks_free inode_count inodes_free \
  574. X    ratio_blocks_2_inodes
  575. X
  576. X-v  Specifies verbose mode.  Quite a bit of information is returned in
  577. X    verbose mode so it is suggested that it only be used for debugging 
  578. X    purposes.
  579. X
  580. Xfilesystem  Specifies the filesystem to examine.  This filesystem must
  581. X    be mounted.  The FM is somewhat vague as to how the statfs(2) call 
  582. X    works but at least with Interactive Unix, the call works correctly
  583. X    whether the actual mount point or a file on the file system is
  584. X    specified.
  585. X
  586. X
  587. XOPERATIONS
  588. X
  589. XBecause most any corrective action requires root privileges, this program
  590. Xshould be run as root.  Because it provides a tremendous opportunity for a 
  591. Xsecurity breach, the permission mask should be set as 
  592. follows:
  593. X
  594. X-r-s------   1 root     root        6644 Jan 13 13:12 /etc/ichk
  595. X
  596. Xor 04500.
  597. X
  598. XThe typical usage is for ichk to be run from init(1).  A typical inittab
  599. Xentry is as follows:
  600. X
  601. Xk2:2345:respawn:/etc/ichk -a /usr/local/news/bin/Inodes -s 60 /news >/dev/null 2>&1
  602. X
  603. XThis line uses the default values for inodes, blocks and inode to blocks ratio
  604. Xand it checks the /news filesystem every 60 seconds.  If a problem is
  605. Xfound, then the Inodes script is run.
  606. X
  607. XThe script /usr/local/news/bin/Inodes or whatever your protective program
  608. Xis named must also be owned by root and must have the permissions 0500 in
  609. Xorder to prevent a security hole.  It is also suggested that the
  610. Xdirectory that the script is in be set so that users cannot access it. 
  611. X
  612. XA copy of a typical Inodes script is included with this package.  It 
  613. Xshould examine the specified problem and take action as appropriate.
  614. X
  615. XThough most people will want to run ichk from init(1) because it makes it
  616. Xso easy to manage, there are provisions to run ichk as a true daemon.  If
  617. Xyou want to run ichk as a daemon, for instance as from /etc/rc2.d/xxx,
  618. Xsimply specify -DDAEMON on the compile line in the makefile and remake
  619. Xichk.  It will then daemonize itself when invoked. 
  620. X
  621. XOTHER USES
  622. X
  623. XThough ichk has its primary use with news, there are other uses.  For 
  624. Xexample, if you configure your system such that all log files are kept
  625. Xon a separate partition, you can have ichk monitor the free blocks on
  626. Xthe partition and fire off cleanup scripts to delete old or obese files.
  627. X
  628. XAnother use is to run ichk -t periodically against the news partition and
  629. Xdirect the output to a log file.  In this manner, you can collect use
  630. Xstatistics and in particular, monitor the block to inode ratio.   Since  
  631. Xthe needed block to inode ratio for news is typically much different
  632. Xthan that for normal file systems, you can quickly determine what 
  633. Xthe optimum ratio is.
  634. X
  635. XCOPYRIGHTS, ETC.
  636. X
  637. XThis package is copyright 1991 John De Armond, All rights reserved.  You
  638. Xmay freely copy, modify and use this program provided that if you modify
  639. Xit, you do not distribute it as ichk. If you distribute ichk, you must
  640. Xdistribute it intact with the source and documentation.    You may not
  641. Xsell it  or claim you wrote it.  I specifically disclaim any association
  642. Xwith the GNU General Public Virus, er, license.  I also specifically
  643. Xdisclaim any warranty of any kind.   
  644. X
  645. XAny feedback, errors, bugs, nicely worded gripes :-) or other comments
  646. Xwelcome.
  647. X
  648. XJohn De Armond
  649. Xjgd@dixie.com
  650.  
  651. X
  652. SHAR_EOF
  653. chmod 0644 ichk.txt || echo "restore of ichk.txt fails"
  654. if [ $TOUCH = can ]
  655. then
  656.     touch -am 0114004591 ichk.txt
  657. fi
  658. set `wc -c ichk.txt`;Wc_c=$1
  659. if test "$Wc_c" != "7310"
  660. then echo original size 7310, current size $Wc_c;fi
  661. # ============= makefile ==============
  662. echo "x - extracting makefile (Text)"
  663. sed 's/^X//' << 'SHAR_EOF' > makefile &&
  664. X
  665. X# This install must be run as root
  666. X# This makefile links with shared libraries.  Remove the "-lc_s" if 
  667. X# shared libraries are not desired for some reason.
  668. X# If you want ichk to automatically demonize itself (NOT when run from
  669. X# init(1)), add the string "-DDAEMON" to the cc line.
  670. X
  671. Xichk:    ichk.c
  672. X    cc -o ichk -O ichk.c -lc_s
  673. X    strip ichk
  674. X    mcs -d ichk
  675. X
  676. Xinstall: ichk
  677. X    chown root ichk
  678. X    chgrp other ichk
  679. X    mv /etc/ichk /etc/old  # so we can move new ichk in with old one running
  680. X    mv ichk /etc
  681. X    chmod 04750 /etc/ichk
  682. X    #"be sure to kill old ichk process and delete /etc/old"
  683. SHAR_EOF
  684. chmod 0660 makefile || echo "restore of makefile fails"
  685. if [ $TOUCH = can ]
  686. then
  687.     touch -am 0114003791 makefile
  688. fi
  689. set `wc -c makefile`;Wc_c=$1
  690. if test "$Wc_c" != "567"
  691. then echo original size 567, current size $Wc_c;fi
  692. exit 0
  693. -- 
  694. John De Armond, WD4OQC        | "Purveyors of speed to the Trade"  (tm)
  695. Rapid Deployment System, Inc. |  Home of the Nidgets (tm)
  696. Marietta, Ga                  | 
  697. {emory,uunet}!rsiatl!jgd      |"Politically InCorrect.. And damn proud of it  
  698.  
  699. exit 0 # Just in case...
  700. -- 
  701. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  702. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  703. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  704. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  705.