Last modified: 04/09/01 00:41:24 JST

cron の設定

clock daemon(cron) をサービスに登録し動作させます。

cron は Cronos というギリシャ神話の神の名前が由来のようです。


1. cron と cygrunsrv のインストール

cron がインストールしてあるかどうか確認します。

$ ls -l /usr/sbin/cron
-rwxrwxrwx 1 Administ none 29184 Mar 6 10:31 /usr/sbin/cron
$

cygrunsrv がインストールしてあるか確認します。

$ ls -1 /etc/setup/ | grep -i cygrunsrv
cygrunsrv.lst.gz
$

インストールしていない場合は、http://cygwin.com/setup.exe を使用してインストールします。


2. cygrunsrv コマンド

cron のサービスを登録するのに必要な cygrunsrv コマンドのオプションを以下に示します。

Usage: cygrunsrv [OPTION]...
option description
-I, --install <svc_name> <svc_name> の名前で新規にサービスをインストールします
table 2-2 に示すパス指定のオプションを同時に指定します
-R, --remove <svc_name> <svc_name> の名前のサービスを抹消します
-S, --start <svc_name> <svc_name> の名前のサービスを開始します
-E, --stop <svc_name> <svc_name> の名前のサービスを終了します

table 2-1 Main options: Exactly one is required.

option description
-p, --path <app_path> サービスとして起動するプログラムのパスを指定します

table 2-2 Required install options

option description
-a, --args <args> Optional string with command line options which is given to the service application on startup.
-c, --chdir <directory> Optional directory which will be used as working directory for the application.
-e, --env <VAR=VALUE> Optional environment strings which are added to the environment when service is started. You can add up to 255 environment strings using the `--env' option. Note: /bin is always added to $PATH to allow all started applications to find at least cygwin1.dll.
-d, --disp <display name> Optional string which contains the display name of the service. Defaults to service name.
-f, --desc <description> Optional string which contains the service description.
-t, --type [auto|manual] Optional start type of service. Defaults to `auto'.
-u, --user <user name> Optional user name to start service as. Defaults to SYSTEM account.
-w, --passwd <password> Optional password for user. Only needed if a user is given. If a user has an empty password, enter `-w '. If a user is given but no password, cygrunsrv will ask for a password interactively.
-s, --termsig <signal> Optional signal to send to service application when service is stopped. <signal> can be a number or a signal name such as HUP, INT, QUIT, etc. Default is TERM.
-y, --dep <svc_name2> Optional name of service that must be started before this new service. The --dep option may be given up to 16 times, listing another dependent service each time.
-0, --stdin <file> Optional input file used for stdin redirection. Default is /dev/null.
-1, --stdout <file> Optional output file used for stdout redirection. Default is /var/log/<svc_name>.log.
-2, --stderr <file> Optional output file used for stderr redirection. Default is /var/log/<svc_name>.log.
-o, --shutdown Stop service application during system shutdown.

table 2-3 Miscellaneous install options

option description
-h, --help print this help, then exit.
-v, --version print cygrunsrv program version number, then exit.

table 2-4 Informative output


3. サービスへの登録と起動

cygrunsrv (NT/W2K service initiator) コマンドを使用して、cron をサービスに登録します。

$ cygrunsrv --install cron --path /usr/sbin/cron --args -D
$

[設定]-[コントロールパネル]-[管理ツール]-[サービス] から、cron がサービスに登録されたことを確認します (figure 3-1)。

cron のプロパティ

figure 3-1

cron サービスを開始します。

$ cygrunsrv --start cron
$

net start cron でも起動できます。

cron が起動したことを確認します。

$ ps -ef | grep cron
SYSTEM 1424 1400 ? 22:57:59 /usr/sbin/cron
$

4. cron の自動起動

cygrunsrv でサービスを登録すると default では OS 起動時にサービスも自動起動します。

手動起動に切り替えるには一度サービスを抹消し、手動起動を指定してもう一度インストールします。

$ cygrunsrv --stop cron
$ cygrunsrv --remove cron
$ cygrunsrv --install cron --path /usr/sbin/cron --args -D --type manual
$

以上で cron の設定は終わりです。おつかれさま(^-^)


もどる