私たちはセントースを使用しています。サーバーが再起動してオペレーティングシステムが完全にロードされると、特定のユーザー(「foo」)はscreenを使用して3〜4個のスクリプトを実行したいと思います。
例えば、
screen -d -m -S script1 forever -o script1.log -e script1.log -l script1.log -c php /path/to/script1.php
CentOSを使用してこれを達成するための最良の方法は何ですか?私はinit.dをあまり調査しないようにしたいと思います。
systemdを使用してサービス(「通知」)を確認し、次のことを確認しました。
Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
Active: failed (Result: exit-code) since Sun 2016-03-20 15:08:04 EDT; 14s ago
Process: 1690 ExecStop=/usr/bin/screen -S notify -X quit (code=exited, status=1/FAILURE)
Process: 941 ExecStart=/usr/bin/screen -d -m -S notify forever -o notifyout.log -e notifyerr.log -l notifyforever.log -c php /path/to/script/notify.php (code=exited, status=0/SUCCESS)
Main PID: 946 (code=exited, status=0/SUCCESS)
なぜブロックされますか?デバッグをどのように開始できますか?
ベストアンサー1
CentOS 7なので、systemdサービスを使用してサービスを開始する必要があります。画面内で実行することもできます。 ~からアーチLinuxウィキ:
ファイルを生成します。/etc/systemd/system/[email protected]
[Unit]
Description=screen
After=network.target
[Service]
Type=simple
User=%i
ExecStart=/usr/bin/screen -DmS autoscreen
ExecStop=/usr/bin/screen -S autoscreen -X quit
[Install]
WantedBy=multi-user.target
その後、有効にします。どのユーザーでも実行したくない場合は、アクティブ化時にファイル名の@とユニット名の@USERNAMEを削除し、ユニットファイルにユーザーをハードコーディングできます。systemctl enable [email protected]