unvt / portable

UNVT Portable
18 stars 7 forks source link

再起動時にサーバを自動起動する方法 #5

Open mapconcierge opened 2 years ago

mapconcierge commented 2 years ago

再起動時にサーバを自動起動する

  1. ラズベリーパイの特定のディレクトリ内(/usr/local/bin/)に自動起動用のシェルを作成する。
    sudo nano /usr/local/bin/autostart.sh
  2. 自動起動用のシェルを作成する(nano)。hostapdを再起動する。
    #!/bin/sh
    sudo systemctl restart hostapd
  3. 作成したシェルスクリプトに実行権限を付与する。
    chmod 755 /usr/local/bin/autostart.sh
  4. 起動時に作成したシェルスクリプトが実行するように設定する。
    • /etc/rc.localというファイルは起動時に実行されるので、そこに先ほどのシェルスクリプトを追加します。
      
      #!/bin/sh -e
      #
      # rc.local
      #
      # This script is executed at the end of each multiuser runlevel.
      # Make sure that the script will "exit 0" on success or any other
      # value on error.
      #
      # In order to enable or disable this script just change the execution
      # bits.
      #
      # By default this script does nothing.

Print the IP address

_IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi

Automatically start UNVT4TCG

autostart.sh printf "UNVT4TCG is working..."

exit 0


- autostart.sh以下を追記。※画面上で実行された事が確認できるようにprintfも追記
hfu commented 2 years ago

systemd でのサービス化方法について、以下のリンク先でまとめていましたので、ご参考にされてください。どちらの方法でも大丈夫だと思います。

https://qiita.com/hfu/items/e273ae658ad2d27f1633