This article records the problems and solutions that are encountered when booting a chromium OS in Ubuntu (12.04) to start the script automatically. Chromium OS is an open-source operating system for Google, and in the Src/platform/factory/py/shopfloor directory is a script that controls production testing by executing under chroot./shopfloor_server.py -M cros.factory.shopfloor.target_shopfloor to start a specific production test program. Now requires the Target_shopfloor to be able to run automatically after the boot and can not be interrupted, so wrote a monitoring script monitor.py to monitor whether Target_shopfloor is executing, if not executed immediately start Target_shopfloor. Shopfloor_server.py is required to execute in the chroot environment, Shopfloor server can be called through cros_sdk--./shopfloor_server.py, because parameters need to be added here, and Cros_ The SDK enters the src/scripts directory by default, so it first passes through cros_sdk--.. /platform/factory/py/shopfloor/target_shopfloor.sh to execute a script to start Target_shopfloor indirectly, script target_shopfloor.sh content: #!/bin/ bash# because the current path is still SRC/SCRIPTSCD: /platform/factory/py/shopfloor./shopfloor_server.py-m cros.factory.shopfloor.target_ Shopfloor This allows you to write a Python script to monitor the execution of the Target_shopfloor and start it when the Target_shopfloor is found, monitor.py as follows: #!/usr/bin/ Pythonimport commandsimport osimport reimport thread import timedef call_shopfloor (): Cros_sdk_path = '/home/tplink /depot_tools ' # because CROS_SDK is in the path depot_tools, add that path to path if cros_sDk_path not in os.environ[' path ']: os.environ[' path ' = Cros_sdk_path + ': ' + os.environ[' path ']
Os.system ("cros_sdk--.. /platform/factory/py/shopfloor/tp_shopfloor.sh ") If __name__ = =" __main__ ": # match Target_shopfloor start command via [\s\S] To match any character, [. \ n] is wrong, within [], '. ' is no longer a meta-character regx = Re.compile (R ' [\s\s]*shopfloor_server.py-m Cros.factory.shopfloor.target_shopfloor ') while True: proc = commands.getoutput ("ps-x | grep Tp_shopfloor ") res = Regx.match (proc) if res:pass else: # Use a thread to start the target _shopfloor, avoid clogging. Thread.start_new_thread (Call_shopfloor, ()) Time.sleep (1) Execute the script manually in the Shell Python monitor.py everything is fine. The next step is to run the script automatically. The first thought was to add the script Cd/home/user/chromiumospython monitor.py & to/etc/ Rc.local, because rc.local at the start of the default is the root permission to execute, will cause errors in the Shopfloor_server error message can not be executed in root permission, so need to switch users. Sudo-u user python monitor.py & redirect rc.local output to rc.local.log:exec 2> for easy viewing of error messages Rc.local.logexec 1>&2set-x through the sudo service rc.local start to see the monitor.py start normally, and Target_shopfloor is normally started. But sudo reboot reboot to see the error message in Rc.local.log: sudo: No TTY present and no Askpass program Specifiedsorry, try Again.sudo:no tty present and no Askpass program Specifiedsorr Y, try Again.sudo:no tty present and no Askpass program Specifiedsorry, try again.sudo:3 Incorrect password attempts by VI sudo adding user All=nopasswd:all allows users to use sudo without requiring a password to temporarily resolve the issue. Later I thought of the Python pexpect module to solve this problem. Modify the monitor.py code to: #!/usr/bin/pythonimport commandsimport osimport pexpectimport reimport thread import timedef Call_ Shopfloor (): Cros_sdk_path = '/home/user/depot_tools ' if Cros_sdk_path not in os.environ[' path ': Os.envi ron[' path ' = Cros_sdk_path + ': ' + os.environ[' path '] #os. System ("cros_sdk--.. /platform/factory/py/shopfloor/target_shopfloor.sh ") Sub_proc = Pexpect.spawn (" cros_sdk--.. /platform/factory/py/shopfloor/target_shopfloor.sh ") res = sub_proc.expect ([' Password ', pexpect. TIMEOUT, Pexpect. EOF]) If res = = 0:sub_proc.sendline (' Password for user\r ') elif res = = 1:pass elif Res = = 2: Passif __name__ = = "__main__": regx = Re.compile (R ' [\s\s]*shopfloor_server.py-m Cros.factory.shopfloor.target_shopfloor ')
While True:proc = Commands.getoutput ("ps-x | grep Target_shopfloor ") res = Regx.match (proc) if Res:pass Else:thread.start_ New_thread (Call_shopfloor, ()) Time.sleep (8) time.sleep (1)
Sleep 8 sec is because it takes a little time to start Target_shopfloor.
Ubuntu boot automatically starts Chromium OS under Chroot script