0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

systemdの無いyoctoで起動時に自動実行

0
Posted at

自分用

update-rc.d を使用する

ファイル構成例(rear-nodeというレシピを作成する)

recipes-なんちゃら
 ├─ rear-node
 │   ├─ rear-node
 │   │   ├─ myapp.sh # これが自動実行させたい何か
 │   │   └─ rear-node.sh # これがinitスクリプト
 │   └─ rear-node.bb
...<snip>

rear-node.bb

LICENSE = "CLOSED"

SRC_URI = " \
    file://myapp.sh \
    file://rear-node.sh \
"
RDEPENDS:${PN} = "bash"

do_install:append() {
    install -d ${D}/etc/init.d
    install -m 0755 ${WORKDIR}/rear-node.sh ${D}/etc/init.d/rear-node
    install -d ${D}/usr/bin
    install -m 0755 ${WORKDIR}/myapp.sh ${D}/usr/bin/myapp.sh
}

pkg_postinst_ontarget:${PN} () {
    if [ -z "$D" ]; then
        echo "Running rear-node init setup..."
        update-rc.d rear-node defaults
    fi
}

FILES:${PN} = " \
    /usr/bin/myapp.sh \
    /etc/init.d/rear-node \
"

initスクリプト(rear-node.sh)

#!/bin/sh

case "$1" in
  start)
    echo "Starting myapp"
    /usr/bin/myapp.sh &
    ;;
  stop)
    echo "Stopping myapp"
    killall myapp.sh
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit 0

myapp.sh(自動実行させたい何か)

#!/bin/bash

echo "myapp dayo" | tee -a /tmp/log.log

conf/local.conf の IMAGE_INSTALL:append にも登録する
例)

IMAGE_INSTALL:append = " ros-core exusers openssh bash gcc g++ sudo rear-node "

上の赤丸は初回起動時だけ走るinitスクリプトの登録
下の赤丸でinitスクリプトが実行されている
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?