2017-08-10 482 views
1

你好,這是我的圖層樹使用啓用systemd服務yocto

├── conf 
│   └── layer.conf 
├── COPYING.MIT 
├── README 
└── recipes-hello 
    ├── helloworld 
    │   ├── helloworld-0.1 
    │   │   ├── helloworld.c 
    │   │   ├── helloworld.patch 
    │   │   └── newhelloworld.c 
    │   └── helloworld_0.1.bb 
    ├── message 
    │   ├── message-0.1 
    │   │   └── message.txt 
    │   └── message_0.1.bb 
    └── service 
     ├── service-0.1 
     │   ├── test_systemd.service 
     │   └── test_systemd.sh 
     └── service_0.1.bb 

這裏test_systemd.service是必須調用test_systemd.sh,而我試圖用service_0.1.bb

實現服務文件
# This recipe performs the following tasks 
    # 1) Install .sh file in /home/root/ and .sh script creates a random text file 
    # 2) Install the .service file in systemd directory 
    # 3) Invoke the .sh script via .service file 
    inherit systemd 

SUMMARY = "Install and start a systemd service" 
SECTION = "examples" 
LICENSE = "MIT" 
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" 

#here we specify the source we want to build 
SRC_URI = "file://test_systemd.sh" 
SRC_URI += "file://test_systemd.service" 
#here we specify the source directory, where we can do all the building and expect sources to be placed 
S = "${WORKDIR}" 

SYSTEMD_SERVICE_${PN} = "test_systemd.service" 


#bitbake task 
#created a directory /home/root for target install the script 
do_install() { 
      install -d ${D}/home/root 
      install -m 0755 ${WORKDIR}/test_systemd.sh ${D}/home/root 

      install -d ${D}{systemd_system_unitdir} 
      install -m 0644 ${WORKDIR}/test_systemd.service ${D}{systemd_system_unitdir} 
} 

#Pack the path 
FILES_${PN} += "/home/root" 
FILES_${PN} += "/lib/systemd/system" 

REQUIRED_DISTRO_FEATURES= "systemd" 

問題是,當我嘗試BitBake的系統方案,拋出bitbake的一個錯誤說法test_systemd.service沒有找到。 我設法將這兩個文件都安裝在RFS中,但是當我包含systemd概念時。我得到沒有這樣的文件錯誤。可能是什麼原因 ? 錯誤消息

NOTE: Executing SetScene Tasks 
NOTE: Executing RunQueue Tasks 
ERROR: service-0.1-r0 do_package: SYSTEMD_SERVICE_service value test_systemd.service does not exist 
ERROR: service-0.1-r0 do_package: Function failed: systemd_populate_packages 
ERROR: Logfile of failure stored in: /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/service/0.1-r0/temp/log.do_package.2860 
ERROR: Task (/home/guest/yocto_practice/meta-testlayer/recipes-hello/service/service_0.1.bb:do_package) failed with exit code '1' 
NOTE: Tasks Summary: Attempted 514 tasks of which 506 didn't need to be rerun and 1 failed. 

Summary: 1 task failed: 
    /home/guest/yocto_practice/meta-testlayer/recipes-hello/service/service_0.1.bb:do_package 
Summary: There were 2 ERROR messages shown, returning a non-zero exit code. 

而且這是寫systemd BB配方正確的做法,什麼是不bitbake的這個錯誤拋出寫這篇

#Pack the path 
    FILES_${PN} += "/home/root" 
    FILES_${PN} += "/lib/systemd/system" 

的意義。

回答

3
SYSTEMD_SERVICE_${PN} += "file://test_systemd.service" 

這應該是:

SYSTEMD_SERVICE_${PN} = "test_systemd.service" 

其他說明(無關的錯誤):

  • 安裝東西到/ home是可能不是一個好主意(你可以使用如${libexecdir}對於其他腳本需要的腳本
  • 沒有理由在bb文件中有do_install_append():您可以將所有內容ñdo_install()
  • 如果您Yocto是最近,使用${systemd_system_unitdir}代替/lib/systemd/system是一個好主意(在舊版本中${systemd_unitdir}/system/作品)
+0

感謝提示了MODS。我根據你做了改變,但仍然出現錯誤。將更新問題 – user7345878

+0

我仍然得到相同的錯誤。不知道爲什麼Bitbake無法在其存在的位置找到該文件。 – user7345878

+2

您目前的食譜指向'$ {D} {systemd_system_unitdir}'兩次。它應該是'$ {D} $ {systemd_system_unitdir}'。否則它在這裏工作。 – jku