logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

perpd.8 (15087B)


  1. .\" perpd.8
  2. .\" wcm, 2008.02.26 - 2013.01.09
  3. .\" ===
  4. .TH perpd 8 "January 2013" "perp-2.07" "persistent process supervision"
  5. .SH NAME
  6. perpd \- persistent process scanner/supervisor/controller
  7. .SH SYNOPSIS
  8. .B perpd [\-hV] [\-a
  9. .I secs
  10. .B ] [\-g
  11. .I gid
  12. .B ] [
  13. .I basedir
  14. .B ]
  15. .SH DESCRIPTION
  16. .B perpd
  17. scans a directory to start and monitor a collection of services.
  18. It is the principal daemon of an active perp installation.
  19. .PP
  20. .B perpd
  21. operates on a base directory containing a set of
  22. .BR perpetrate (5)
  23. service definitions.
  24. The base directory may be given by the
  25. .I basedir
  26. argument on the command line.
  27. If no
  28. .I basedir
  29. argument is given,
  30. .B perpd
  31. will look for a value associated with the environmental variable PERP_BASE.
  32. If neither of these is defined,
  33. .B perpd
  34. will operate on a compiled-in default directory,
  35. normally
  36. .IR /etc/perp .
  37. .PP
  38. Service definitions are installed,
  39. configured and activated as subdirectories of the base directory.
  40. As
  41. .B perpd
  42. sequentially scans the base directory,
  43. it looks for subdirectory names not beginning with `.'.
  44. If
  45. .B perpd
  46. then finds the `sticky' bit set on the subdirectory,
  47. it considers the service definition ``active'' and
  48. attempts to start the service.
  49. .PP
  50. First
  51. .B perpd
  52. inspects the service subdirectory.
  53. If the optional file named
  54. .I rc.log
  55. is present and executable,
  56. .B perpd
  57. spawns a child process to run it,
  58. setting up a pipe to link its stdin to the stdout
  59. of the main service.
  60. To start the logging process,
  61. .B perpd
  62. invokes
  63. .I rc.log
  64. as follows:
  65. .PP
  66. .RS
  67. .B ./rc.log start
  68. .I svname
  69. .RE
  70. .PP
  71. The first argument is the literal string ``start'',
  72. with the
  73. .I svname
  74. argument set to the basename of the subdirectory.
  75. .PP
  76. After starting the optional logger,
  77. .B perpd
  78. proceeds to spawn a child process to run the required file named
  79. .IR rc.main .
  80. If a logging process has been defined as described above,
  81. .B perpd
  82. will also connect the stdout of the main service to the stdin of the logger.
  83. .PP
  84. To start the main service,
  85. .B perpd
  86. invokes
  87. .I rc.main
  88. as follows:
  89. .PP
  90. .RS
  91. .B ./rc.main start
  92. .I svname
  93. .RE
  94. .PP
  95. The conventions and arguments for starting
  96. .I rc.main
  97. are the same as those described for
  98. .I rc.log
  99. above.
  100. .PP
  101. .B perpd
  102. runs each
  103. child process for
  104. .I rc.main
  105. and
  106. .I rc.log
  107. in a new session and separate process group.
  108. The current working directory of the child process is
  109. set to the service subdirectory.
  110. The environment for each process is defined with the variable
  111. .B PERP_BASE
  112. set to the absolute path of the
  113. .B perpd
  114. base directory as described above.
  115. .PP
  116. The files
  117. .I rc.main
  118. and
  119. .I rc.log
  120. are known as ``runscripts''.
  121. The result of running ``start'' on a runscript
  122. should normally be a persistent process,
  123. some long\-running program designed to start at system boot
  124. and continue running until system shutdown.
  125. Runscript conventions and examples may be found in the
  126. .BR perpetrate (5)
  127. manual.
  128. .PP
  129. .B perpd
  130. monitors its ``start'' processes to make sure they continue running.
  131. If any active service process terminates,
  132. .B perpd
  133. is triggered to reset and restart the service.
  134. .PP
  135. To reset a process that has terminated from a ``start'',
  136. .B perpd
  137. will invoke the associated runscript again in either one of two forms,
  138. depending on whether the process exited normally,
  139. or was killed by a signal:
  140. .PP
  141. .RS
  142. .B ./rc.main reset
  143. .I svname
  144. .B exit
  145. .I exitcode
  146. .RE
  147. or
  148. .RS
  149. .B ./rc.main reset
  150. .I svname
  151. .B signal
  152. .I signum signame
  153. .RE
  154. .PP
  155. The first argument in both cases is the literal string ``reset''.
  156. If the service exited normally,
  157. this is followed by the literal string ``exit'' and a string representation
  158. of the numeric exit code returned by the process.
  159. If the service was terminated by a signal,
  160. the ``reset'' is followed by the literal string ``signal'',
  161. a string representation of the numeric signal number that killed the process,
  162. and the symbolic name for the signal, such as SIGTERM.
  163. .PP
  164. A runscript process running ``reset'' will normally run to completion
  165. and return/exit promptly.
  166. After the resetting process terminates,
  167. .B perpd
  168. will then attempt to restart the service,
  169. again invoking its runscript with the same ``start'' and
  170. .I svname
  171. arguments as described above.
  172. .PP
  173. To avoid chronic service failures from looping too quickly,
  174. .B perpd
  175. will delay at least one second beyond the previous start time
  176. before trying to restart a service.
  177. .PP
  178. .B perpd
  179. may be triggered to immediately rescan the base directory with a
  180. SIGHUP signal or the
  181. .BR perphup (8)
  182. command.
  183. .B perpd
  184. may also be configured at startup to automatically rescan the
  185. base directory at fixed intervals given by the
  186. .B \-a
  187. option.
  188. For any new active service definitions found while scanning,
  189. .B perpd
  190. will attempt to start the service as described above.
  191. For any existing services whose subdirectory has been removed
  192. or is no longer sticky,
  193. .B perpd
  194. will bring down the service
  195. (terminating both the main and log processes,
  196. and then running ``reset'' on each),
  197. and remove the service from further active monitoring.
  198. .PP
  199. While
  200. .B perpd
  201. monitors its services,
  202. it also listens on a control interface for administrative commands
  203. and status requests from perp client applications such as
  204. .BR perpctl (8),
  205. .BR perpls (8),
  206. and
  207. .BR perpstat (8).
  208. .PP
  209. .B perpd
  210. will exit failure immediately after startup under certain conditions:
  211. being unable to find or change into the base directory;
  212. finding another instance of
  213. .B perpd
  214. running on the same base directory;
  215. or failure during initialization of its control files.
  216. Otherwise,
  217. .B perpd
  218. is designed to start at system boot and continue running until system shutdown.
  219. .PP
  220. Normally a system is configured to start
  221. .B perpd
  222. as part of its
  223. .BR init (8)
  224. sequence during system startup.
  225. The
  226. perp
  227. distribution
  228. includes a
  229. .BR perpboot (8)
  230. utility,
  231. specifically designed to provide a reliable method for starting
  232. .B perpd
  233. under many different
  234. .BR init (8)
  235. environments.
  236. .\" *** STARTUP MODIFICATION
  237. .SS STARTUP MODIFICATION
  238. .PP
  239. The service startup procedures
  240. described above may be modified by installing certain specific ``flag'' files
  241. into the service directory:
  242. .I flag.down
  243. and
  244. .IR flag.once .
  245. .PP
  246. If a file named
  247. .I flag.down
  248. is present,
  249. .B perpd
  250. will not attempt to start the
  251. .I rc.main
  252. control executable immediately at startup.
  253. In such cases,
  254. the
  255. .BR perpctl (8)
  256. utility may be used to tell
  257. .B perpetrate
  258. to start the service at a later time.
  259. .PP
  260. If a file named
  261. .I flag.once
  262. is present,
  263. .B perpd
  264. will attempt to start the
  265. .I rc.main
  266. control executable immediately at startup, as usual,
  267. and then reset it if it terminates.
  268. But when the reset completes,
  269. .B perpd
  270. will not restart the main service.
  271. Again,
  272. the
  273. .BR perpctl (8)
  274. utility may be used to tell
  275. .B perpd
  276. to restart the service if necessary,
  277. or to ``unflag'' its
  278. .I once
  279. setting.
  280. .PP
  281. If both files
  282. .I flag.down
  283. and
  284. .I flag.once
  285. are present when
  286. .B perpd
  287. is starting the service for the first time,
  288. the behavior described for
  289. .I flag.down
  290. takes precedence.
  291. .PP
  292. The existence of either of the flag files
  293. .I flag.down
  294. and
  295. .I flag.once
  296. only affects the behavior of the service at activation.
  297. If they are installed in the service directory after
  298. .B perpd
  299. has already started and is running the service,
  300. they will have no effect until the service is deactivated and then reactivated.
  301. .PP
  302. The presence of either of these flag files also has no effect
  303. on the optional logging service.
  304. If a file named
  305. .I rc.log
  306. is present and executable at startup,
  307. .B perpd
  308. will attempt to start and monitor a logger for the service,
  309. irrespective of the presence of any of the flag files described above.
  310. .PP
  311. These flag files are usually of zero length and may be installed with the
  312. .BR touch (1)
  313. command.
  314. .\" *** OPTIONS ***
  315. .SH OPTIONS
  316. .TP
  317. .B \-a secs
  318. Autoscan.
  319. Normally
  320. .B perpd
  321. runs in a quiet
  322. .BR poll (2)
  323. state until some external signal or event causes it to rescan the base directory.
  324. The
  325. .B \-a
  326. option may be used to set an interval
  327. that causes
  328. .B perpd
  329. to automatically rescan the base directory every
  330. .I secs
  331. seconds.
  332. For example,
  333. a
  334. .I secs
  335. argument of 5 will cause
  336. .B perpd
  337. to automatically rescan the base directory at least once every 5 seconds,
  338. imitating the behavior of daemontools
  339. .BR svscan (8).
  340. An argument of 0 disables autoscanning.
  341. .TP
  342. .B \-g gid
  343. Socket gid.
  344. Normally the control socket is created with the same ownership
  345. as the
  346. .B perpd
  347. process and with an explicit access mode 0700.
  348. The
  349. .B -g
  350. option sets the group ownership on the control socket according to the
  351. .IR gid
  352. argument and changes the access mode on the socket to 0770.
  353. The
  354. .I gid
  355. argument may be given as either a numeric group id
  356. or as a group name.
  357. Note that the designated group will also require
  358. access to the
  359. .I .control
  360. directory (or related symlink) in which the control socket is installed.
  361. .TP
  362. .B \-h
  363. Help.
  364. Display a brief help message on stderr and exit.
  365. .TP
  366. .B \-V
  367. Version.
  368. Display the version string on stderr and exit.
  369. .\" *** EXAMPLES ***
  370. .SH EXAMPLES
  371. .B perpd
  372. is designed to permit easy service activation/deactivation using the
  373. .BR chmod (1)
  374. utility.
  375. .PP
  376. To activate a service within the
  377. .B perpd
  378. base directory,
  379. set the sticky bit of the subdirectory containing the
  380. service definition:
  381. .PP
  382. .RS
  383. chmod +t myservice && perphup
  384. .RE
  385. .PP
  386. .B perpd
  387. will notice the service definition is now active
  388. and will initiate the startup procedures for it.
  389. Alternatively, the
  390. .B A
  391. command to
  392. .BR perpctl (8)
  393. may be used instead to perform the equivalent activation:
  394. .PP
  395. .RS
  396. perpctl A myservice
  397. .RE
  398. .PP
  399. To deactivate a service, unset the sticky bit:
  400. .PP
  401. .RS
  402. chmod -t myservice && perphup
  403. .RE
  404. .PP
  405. .B perpd
  406. will notice the service has now been deactivated and will
  407. initiate a shutdown sequence on it.
  408. The
  409. .B X
  410. command to
  411. .BR perpctl (8)
  412. may also be used to perform the equivalent deactivation:
  413. .PP
  414. .RS
  415. perpctl X myservice
  416. .RE
  417. .PP
  418. Note that there is generally no need to use the
  419. .BR perpctl (8)
  420. .B D
  421. command to bring down a service before deactivating it.
  422. Simply unsetting the sticky bit will bring the service down properly.
  423. .PP
  424. On some platforms/terminals,
  425. colorized
  426. .BR ls (1)
  427. listings may be configured to display the `sticky' entries within a directory
  428. so they are readily visible.
  429. Othewise,
  430. request
  431. .BR ls (1)
  432. to display a long listing format that presents directory permissions in the first column:
  433. .PP
  434. .RS
  435. .nf
  436. .B # ls -l
  437. drwxr-xr-x goodbye
  438. drwxr-xr-t hello
  439. .fi
  440. .RE
  441. .PP
  442. In this truncated and contrived example,
  443. the service directory
  444. .I hello
  445. is active (has sticky bit set; see the `t' in its permission string),
  446. and the service directory
  447. .I goodbye
  448. is not active (sticky bit not set.)
  449. .PP
  450. The
  451. .BR stat (1),
  452. .BR perpstat (8),
  453. and
  454. .BR perpls (8)
  455. utilities may also be used to display the active services within a directory.
  456. .\" *** FILES ***
  457. .SH FILES
  458. .I /etc/perp
  459. .RS
  460. The default base operating directory monitored by
  461. .BR perpd ,
  462. containing the set of service definition directories as described in
  463. .BR perpetrate (5).
  464. .RE
  465. .PP
  466. .I /PERP_BASE/.control
  467. .RS
  468. .B perpd
  469. maintains associated runtime files and IPC interfaces within a subdirectory named
  470. .IR .control .
  471. Normally this will be configured as a symbolic link
  472. to a directory within the
  473. .I /var
  474. hierarchy before starting
  475. .BR perpd .
  476. For example, the symlink:
  477. .PP
  478. .RS
  479. .I .control
  480. ->
  481. .I /var/run/perp
  482. .RE
  483. .PP
  484. will cause
  485. .B perpd
  486. to maintain its runtime files under
  487. .IR /var/run/perp .
  488. If
  489. .B perpd
  490. finds that
  491. .I .control
  492. is a dangling symlink on startup,
  493. it will attempt to make the directory that
  494. .I .control
  495. points to.
  496. .RE
  497. .PP
  498. .I /PERP_BASE/.control/perpd.pid
  499. .RS
  500. The lock file used by
  501. .B perpd
  502. to constrain execution to a single instance on a base directory.
  503. This file also contains the pid of the active
  504. .B perpd
  505. process.
  506. .RE
  507. .PP
  508. .I /PERP_BASE/.control/perpd.sock
  509. .RS
  510. The domain socket used by
  511. .B perpd
  512. to perform inter-process communications with perp client utilities
  513. such as
  514. .BR perpctl (8)
  515. and
  516. .BR perpls (8).
  517. .RE
  518. .SH ENVIRONMENT
  519. PERP_BASE
  520. .RS
  521. The base scanning directory for the
  522. .B perpd
  523. process.
  524. If no
  525. .I basedir
  526. argument is given on the command-line at startup,
  527. .B perpd
  528. checks for a value defined with PERP_BASE.
  529. If this variable is not defined or empty,
  530. .B perpd
  531. uses a compiled-in default,
  532. usually
  533. .IR /etc/perp .
  534. Irrespective of how
  535. .I basedir
  536. is determined at startup,
  537. .B perpd
  538. will use its value to define PERP_BASE within the environment of each
  539. service runscript it starts.
  540. If defined,
  541. PERP_BASE should be given as an absolute pathname.
  542. .RE
  543. .PP
  544. PERP_SVPID
  545. .RS
  546. The process ID of the active or terminated service.
  547. .B perpd
  548. supplies the process ID of the service process in the value of the PERP_SVPID variable
  549. within the environment of both the ``start'' and ``reset'' invocations of the runscript.
  550. In the case of the ``start'' target,
  551. the value given in PERP_SVPID is the process ID of the script itself,
  552. and which normally becomes the pid of the active service,
  553. as when the script calls the
  554. .B exec
  555. command to run the service program.
  556. In the case of the ``reset'' target,
  557. the value given in PERP_SVPID is the process ID of the service
  558. that has just terminated.
  559. .RE
  560. .PP
  561. PERP_SVSECS
  562. .RS
  563. The uptime in seconds of the terminated service.
  564. .B perpd
  565. supplies the total wallclock runtime of the process that has just terminated
  566. in the value of the PERP_SVSECS variable.
  567. This variable is defined only within the environment of the ``reset''
  568. invocation of the runscript.
  569. .RE
  570. .SH ERROR LOGGING
  571. .B perpd
  572. emits diagnostics to stderr.
  573. To capture and log such messages,
  574. .B perpd
  575. will usually be started with an associated logger;
  576. see
  577. .BR perpboot (8)
  578. for a utility designed to start
  579. .B perpd
  580. with an associated logger.
  581. In such an installation,
  582. the stderr of
  583. .B perpd
  584. will be redirected to stdout,
  585. and, in turn, its stdout will be piped to the stdin of the logger.
  586. .PP
  587. Each activated service starts with its stdout and stderr file descriptors
  588. inherited from
  589. .BR perpd .
  590. If these are not subsequently redirected elsewhere,
  591. any diagnostics emitted by a service will also appear in the
  592. .B perpd
  593. logger.
  594. .\" *** SIGNALS ***
  595. .SH SIGNALS
  596. SIGHUP
  597. .RS
  598. Triggers
  599. .B perpd
  600. to immediately rescan the base directory.
  601. .RE
  602. .PP
  603. SIGTERM
  604. .RS
  605. Triggers
  606. .B perpd
  607. to begin a shutdown sequence on
  608. each service process it is currently monitoring.
  609. After all service
  610. processes have terminated from their ``start'' and final ``reset'',
  611. .B perpd
  612. itself exits 0.
  613. .RE
  614. .\" *** LIMITS ***
  615. .SH LIMITS
  616. Each
  617. .B perpd
  618. instance can monitor a compile-time maximum number
  619. of active services,
  620. normally 200.
  621. The runtime environment of the
  622. .B perpd
  623. process should be configured to permit sufficient child processes
  624. (up to 2 per service),
  625. and open file descriptors
  626. (up to 3 per service, plus 7 requisite,
  627. plus a number for concurrent client connections, usually 20)
  628. to handle the actual number of services to be installed and activated.
  629. See
  630. .BR getrlimit (2),
  631. .BR runlimit (8)
  632. and the references to RLIMIT_NPROC and RLIMIT_NOFILE
  633. for more information.
  634. .\" *** AUTHOR ***
  635. .SH AUTHOR
  636. Wayne Marshall, http://b0llix.net/perp/
  637. .\" *** SEE ALSO ***
  638. .SH SEE ALSO
  639. .nh
  640. .BR chmod (1),
  641. .BR perp_intro (8),
  642. .BR perp-setup (8),
  643. .BR perpboot (8),
  644. .BR perpctl (8),
  645. .BR perpetrate (5),
  646. .BR perphup (8),
  647. .BR perpls (8),
  648. .BR perpok (8),
  649. .BR perpstat (8),
  650. .BR sissylog (8),
  651. .BR tinylog (8)
  652. .\" EOF (perpd.8)