Linux起動自己起動スクリプト(Ubuntu:あるユーザで実行、OpenSUSE、CentOS)
2783 ワード
Ubuntu/Debian
rc.localのコマンドは、システム起動後に実行されます。1.編集:
注:特別な場合があります。
2.所望のユーザでコマンドを実行します。
3.起動してscreenでプログラムスクリプトを実行し、環境変数(no-login)を追加します。
OpenSUSE:
OpenSUSE起動プログラムの設定は特殊です(
1.
2.
3.
したがって、ほとんどの起動プログラムには、
システムがSystemdを使用する場合、対応するファイルは:https://unix.stackexchange.com/questions/43230/how-to-run-my-script-after-suse-finished-booting-up https://www.cnblogs.com/toSeek/articles/3011455.html CentOS:
1、
rc.localのコマンドは、システム起動後に実行されます。1.編集:
/etc/rc.local
実行したいコマンドを追加すればいいです。注:特別な場合があります。
/etc/rc.local
は実行されません。/etc/init.d/rc.local
see linkを編集できます。http://www.linuxidc.com/Linux/2016-12/138665.htm 2.所望のユーザでコマンドを実行します。
su -c 'ls -l "myfile.txt"' guowei &
説明:実行が必要なコマンドはls -l "myfile.txt"
であり、所望のユーザのguowei
、&
はバックグラウンドで実行される。3.起動してscreenでプログラムスクリプトを実行し、環境変数(no-login)を追加します。
#!/bin/bash
# su , sudo -E
# root , su -p su -m
export GUOWEI_DIR=/home/guowei
export PATH=/opt/bin:$PATH
source /home/guowei/.bashrc
if [ -e /opt/my_app ]; then
# sudo -E su -p -l guowei << BASH # guowei , 。 su - ,sudo -E 。
su -p guowei << BASH # guowei , sudo, sudo -E 。
cd /home/guowei
screen -d -m /opt/my_app
# BASH
fi
# export -c , -c :
su guowei -c 'export A=/opt/bla; blabla~; /opt/my_app' // :
その後、ssh登録後、対応するユーザに切り替えられ、screen -ls
は、バックグラウンドで実行されるプログラムを見ることができる。OpenSUSE:
OpenSUSE起動プログラムの設定は特殊です(
/ect/rc.local
ファイルがありません)。主にこの3つのファイル(SysVinit)があります。1.
/etc/init.d/after.local
このファイルはデフォルトでは存在しません。手動で作成する必要があります。システムが実行レベルの起動を完了した後に実行するスクリプトです。他のシステムの/etc/rc.local
と同様である。2.
/etc/init.d/boot.local
このファイルはシステム起動後、実行レベルに入る前に実行するユーザスクリプトです。注意このファイルを実行する時、ネットワークなどの設備はまだ整っていません(ネット接続がありません)。使う時は注意してください。3.
/etc/init.d/before.local
このファイルはrcがスクリプトを開始する前に実行されますが、boot.localの後に実行されます。したがって、ほとんどの起動プログラムには、
/etc/init.d/after.local
に加えるのが適切である。システムがSystemdを使用する場合、対応するファイルは:
/etc/init.d/after-local
To enable/etc/init.d/after-local:systemctl enable after-local.service
To check status of /etc/init.d/after-local
:systemctl status after-local.service
全体的には、SysVinit
システムを使用するには、一般的なユーザプログラムであれば、ファイルの新規作成のみが必要となる。vi /etc/init.d/after.local
カスタム起動コマンドを追加すればいいです。#!/bin/sh
/usr/local/bin/redis-server /etc/redis/6379.conf
ref link:1、
/etc/init.d/
ディレクトリの下に新しいファイルを作成します。autostart.sh
#!/bin/sh
#chkconfig: 2345 80 80
#description: auto start my app
sh xxx & #
2、cdから/etc/init.dディレクトリに、コマンドを入力します。chkconfig --add autostart.sh
chkconfig autostart.sh on