apt-get update -qqy

第一次看到-qq参数,觉得比较新奇,特意确认了下:

-q, –quiet

Quiet. Produces output suitable for logging, omitting progress indicators. More q’s will produce more quiet up to a maximum of two. You can also use -q=# to set the quiet level, overriding the configuration file. Note that quiet level 2 implies -y, you should never use -qq without a no-action modifier such as -d, –print-uris or -s as APT may decided to do something you did not expect.

所以按照说明,-qq一般是搭配y选项的。
这个参数经常在docker的静默安装指令中使用。

参考:
https://linux.die.net/man/8/apt-get

centos7 vsftp 虚拟用户配置

搞过好多遍了,每次都要花不少时间确认一些小问题,所以做个笔记,供以后参考
1. 安装 vsftpd

yum install vsftpd
chkconfig vsftpd on
  1. 测试端口外网可访问性,用telnet就可以测试,如果不可访问,请确认vsftp端口已经监听,并且iptable 或者firewall配置正确,同时如果用的是阿里云之类的云主机,确认云平台的安全策略是否已经开放21端口
  2. 创建用户
    useradd virtual -s /sbin/nologin
    默认的vsftpd的服务宿主用户是root,但是这不符合安全性的需要。这里建立名字为virtual的用户,用他来作为支持Vsftpd的服务宿主用户。由于该用户仅用来支持vsftpd服务用,因此没有许可他登陆系统的必要,并设定他为不能登陆系统的用户。
    这个用户跟配置文件中的guest_username字段是对应的。
  3. 修改/etc/vsftpd.conf
    新增:
anonymous_enable=NO
chroot_local_user=YES
guest_enable=YES
guest_username=ftp
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/users
reverse_lookup_enable=NO
  1. 修改 /etc/pam.d/vsftpd,删除原有内容,新增:
auth    required    pam_userdb.so   db=/etc/vsftpd/virtual_users
account required    pam_userdb.so   db=/etc/vsftpd/virtual_users
session required    pam_loginuid.so
  1. 创建账号
    1)创建账号文件 login.txt:aaaa是密码,1111是密码,多个用户依次换行
aaa
111111
bbb
222

2)生成虚拟用户数据文件
db_load -T -t hash -f /etc/vsftpd/virtual_users.txt /etc/vsftpd/virtual_users.db
7. 创建虚拟账号
mkdir /etc/vsftpd/users
vi aaaa
这里面的权限要根据需要的权限来配置,下面是一个可读写的全权限用户配置

local_root=/var/ftp/aaa
write_enable=YES
anon_umask=022
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
  1. 对相关的路径给与权限,这样才能正常上传,否则会提示553错误
mkdir -p /var/ftp/aaa

chown virtual:virtual /var/ftp/aaa

chmod 755 /var/ftp/aaa
  1. 配置完成重启服务
    systemctl restart vsftpd

Dockerfile中RUN CMD ENTRYPOINT命令区别

简单总结如下:
1. run用于docker的构建,可以理解为构建docker本身的单次的程序安装,只是为了生成docker image的,在docker build阶段执行。
2. entrypoint 理解为docker run时的shell指令,一般实现需要每次开机动态更新的设置或者文件操作等
3. cmd只能支持一条,代表entrypoint额外的默认运行参数,当在外层通过 docker run传递参数时,cmd的参数可以被覆盖。

参考:
1. https://www.cnblogs.com/klvchen/p/9238410.html
2. https://www.jianshu.com/p/f0a0f6a43907

docker常用操作命令

创建

可以在hub.docker.com上创建一个新的repo,或者自己复制一个现有的repo.
绑定github后,也可以直接通过Dockerfile来发生成最新的镜像

查看镜像列表

docker images

查看容器列表

docker ps

查看所有的容器

docker ps -a

查看最近创建的容器

docker ps -l

查找在指定 image 之后创建的 image 中的父 image

docker image inspect --format='{{.RepoTags}} {{.Id}} {{.Parent}}' $(docker image ls -q --filter since=xxxxxx)

获取镜像

docker pull name/reponame

删除

docker rm          Remove one or more containers
docker rmi         Remove one or more images

删除已经退出运行的容器

docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm

删除none镜像

docker images |grep none |awk '{print $3}'|xargs docker rmi

要删除全部image的话

docker rmi $(docker images -q)

停止所有容器

停止容器,才能删除所包含的image

docker stop $(docker ps -a -q)

运行

ssh登陆:

docker run -it  username/imagename /bin/bash

ssh登陆,并挂载本地目录,默认读写权限:

docker run -it -v 宿主绝对路径:docker绝对路径 username/imagename /bin/bash

attach

docker attach --sig-proxy=false $CONTAINER_ID

detach

docker没有专用的命令,目前不能使用eixit,因为会导致主进程退出。使用ctl+p+ctl+q来detach当前的进程

查看底层信息,比如IP等

docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID

commit

docker commit CONTAINER_ID docker_hub用户名/镜像名:tagname

push

docker push docker_hub用户名/镜像名:tagname

其他参考

资深专家都知道的 Docker 常用命令—源英文:Top Docker Commands Any Expert Should Know
Docker之容器的创建、启动、终止、删除、迁移等
docker入门——构建镜像

基于ubuntu的LAMP dockerfile示例

简单的dockerfile例子

这里先给一个简单的例子,用来说明基本的dockerfile的组成:

# Barebones Apache installation on Ubuntu

FROM ubuntu

MAINTAINER DockerFan version 1.0

ENV DEBIAN_FRONTEND noninteractive

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

RUN apt-get update && apt-get install -y apache2

EXPOSE 8080

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

解释

Here’s what the instructions do:

  • FROM is always your first instruction, because it names the base image you’re building your new image from.

  • MAINTAINER is the creator of the Dockerfile.

  • ENV sets environment variables, in the form ENV [key] [value]. This assigns a single value to the key, as in our example Dockerfile. The value can be any string, including spaces and punctuation, so you can configure values like IP addresses, URLs, and passphrases. Note that when you set DEBIAN_FRONTEND noninteractive (for an unattended installation) in your Dockerfile there is no equals sign, as there is when you script a standard Debian or Ubuntu installation with export DEBIAN_FRONTEND=noninteractive.

  • There are multiple instructions for setting environment variables: ADD, COPY, ENV, EXPOSE, LABEL, USER, WORKDIR, VOLUME, STOPSIGNAL, and ONBUILD.

  • RUN executes commands. The example above, RUN apt-get update && apt-get install -y apache2, demonstrates two important steps. It is a good practice to use apt-get update && apt-get install foo together to ensure that an updated packaged will be installed. Docker makes generous use of caching, so this prevents a cached packaged from being installed. If you’re sure your cached packages are fresh enough then it’s not necessary, and will save you some download time. apt-get install -y must be used together with ENV DEBIAN_FRONTEND noninteractive; it means answer Yes to all prompts and run non-interactively.

  • EXPOSE defines which ports you want open at runtime, in a space-delimited list.

  • CMD can be used only once in your Dockerfile. If you have more than one, only the last one will run. The preferred syntax is CMD [“executable”,”param1″,”param2″]. The parameters are optional and comma-separated if you have more than one.

完整的LAMP dockerfile

# Ubuntu LAMP stack with Apache, MariaDB, PHP, and SSL

FROM ubuntu

MAINTAINER DockerFan version 1.0

ENV DEBIAN_FRONTEND noninteractive

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

# Install Apache, SSL, PHP, and some PHP modules

RUN apt-get update && apt-get install -y apache2 
 openssl 
 php5 
 php5-cli 
 php5-apcu

# Install MariaDB and set default root password

RUN echo 'mariadb-server mariadb-server/root_password  password mypassword' | debconf-set-selections
RUN echo 'mariadb-server mariadb-server/root_password_again password mypassword' | debconf-set-selections
RUN apt-get install mariadb-server -y

# Disable the default Apache site config
# Install your site's Apache configuration and activate SSL

ADD my_apache.conf /etc/apache2/sites-available/
RUN a2dissite 000-default
RUN a2ensite my_apache
RUN a2enmod ssl

# Remove APT files
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

EXPOSE 443 8080

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

The section that installs Apache, SSL, and PHP shows the proper Docker way to install multiple packages at once, with each package on its own line ending in a backslash. The MariaDB installation sections shows how to use debconf to automatically set the root DB password.

You will need your own Apache virtual host configuration file, and it should be in the same directory as your Dockerfile. Use the ADD instruction to build it into your image. I like to do a little housecleaning to keep my image as small as possible by running apt-get clean, and removing temp files.

Since we are using SSL, we’ll need port 443 available. On a production system, you would probably want only port 443 enabled, and use mod_rewrite to automatically redirect HTTP requests to HTTPS.

DEBIAN_FRONTEND选项

ENV DEBIAN_FRONTEND noninteractive
在基于ubuntu的dockerfile中我们经常看到如上的配置,那么,DEBIAN_FRONTEND到底是什么东西呢?

因为ubuntu是基于apt工具包进行软件安装的,而apt工具包是基于DebianPackageManagement的。而DEBIAN_FRONTEND就是DebianPackageManagement的基本选项。

dpkg-reconfigure 可以让我们简单的配置/重新配置包选项,而不需要重新安装。在配置的过程中我们就要面临frontend的选择。

正常情况下我们会选择交互式的配置过程,但是在很多脚本过程中,我们也需要自动化整个过程,而frontend就是用来指定我们的包配置模式的。DEBIAN_FRONTEND=noninteractive 实际上就是通过环境变量模式来指定的方式。

DEBIAN_FRONTEND支持的配置方式如下:

noninteractive
Do not ask any questions and assume the defaults.

dialog
Presents the user with the familiar text gray window on blue background. This is the default.

text
This removes the dialog interface and asks the configuration questions in a pure text-based format. This is well suited for slow connections or terminal emulators that don’t cooperate well with the dialog-based input and windowing system.

gtk
Prompts the user graphically using the GTK libraries. This may not work correctly on KDE. Also requires the package cdebconf-gtk and gkdebconf to be installed before use.

所以在dockerfile的自动化配置脚本中,我们一般选择noninteractive

蓝牙uart透传技术摘要

蓝牙uart透传技术摘要

基于 nRF5_SDK_15.3.0_59ac345

app->mcu->uart

  1. BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT); 执行时将ble_nus_on_ble_evt,进行了注册了绑定。
  2. nrf_sdh_ble_evts_poll 执行时,通过回调,调用ble_nus_on_ble_evt。
  3. 当有蓝牙数据发送时,会触发BLE_GATTS_EVT_WRITE,调用on_write
  4. 在on_write中会调用我们在业务中注册的nus service 回调nus_data_handler,这个回调作为参数在ble_nus_init中注册。
  5. 在nus_data_handler中我们就可以将数据通过串口发送函数app_uart_put发出了

uart->mcu->app

  1. uart_event_handle回调函数到nus发送函数ble_nus_data_send
  2. sd_ble_gatts_hvx协议栈函数会将内容通过蓝牙发送给app

Nordic SoftDevice 处理

来源:https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fgroup__nrf__sdh.html&anchor=ga574d17fdf1c59dec6355e3f525c484ec

SoftDevice Handler

API for initializing and disabling the SoftDevice. More…

Modules

ANT support in SoftDevice Handler
This file contains the declarations of types and functions required for ANT stack support.
BLE support in SoftDevice Handler
This file contains the declarations of types and functions required for BLE stack support.
SoftDevice handler configuration
SoC support in SoftDevice Handler
This file contains the declarations of types and functions required for SoftDevice Handler SoC support.

Data Structures

struct nrf_sdh_req_observer_t
SoftDevice Handler state request observer. More…
struct nrf_sdh_state_observer_t
SoftDevice Handler state observer. More…
struct nrf_sdh_stack_observer_t
SoftDevice stack event observer. More…

Functions

ret_code_t nrf_sdh_enable_request (void)
Function for requesting to enable the SoftDevice. More…
ret_code_t nrf_sdh_disable_request (void)
Function for requesting to disable the SoftDevice. More…
ret_code_t nrf_sdh_request_continue (void)
Function for restarting the SoftDevice Enable/Disable process. More…
bool nrf_sdh_is_enabled (void)
Function for retrieving the SoftDevice state. More…
void nrf_sdh_suspend (void)
Function for stopping the incoming stack events. More…
void nrf_sdh_resume (void)
Function for resuming polling incoming events from the SoftDevice.
bool nrf_sdh_is_suspended (void)
Function for retrieving the information about the module state. More…
void nrf_sdh_evts_poll (void)
Function for polling stack events from the SoftDevice. More…

Softdevice Handler dispatch models

#define NRF_SDH_DISPATCH_MODEL_INTERRUPT   0
SoftDevice events are passed to the application from the interrupt context.
#define NRF_SDH_DISPATCH_MODEL_APPSH   1
SoftDevice events are passed to the application using SchedulerMore…
#define NRF_SDH_DISPATCH_MODEL_POLLING   2
SoftDevice events are polled manually using nrf_sdh_evts_poll()More…

SoftDevice Handler state change requests

enum nrf_sdh_req_evt_t { 
  NRF_SDH_EVT_ENABLE_REQUEST
  NRF_SDH_EVT_DISABLE_REQUEST 
}
SoftDevice Handler state requests. More…
typedef bool(* nrf_sdh_req_evt_handler_t )(nrf_sdh_req_evt_t request, void *p_context)
SoftDevice Handler state request handler. More…
#define NRF_SDH_REQUEST_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice state change request observer. More…

SoftDevice Handler state events

enum nrf_sdh_state_evt_t { 
  NRF_SDH_EVT_STATE_ENABLE_PREPARE
  NRF_SDH_EVT_STATE_ENABLED
  NRF_SDH_EVT_STATE_DISABLE_PREPARE
  NRF_SDH_EVT_STATE_DISABLED 
}
SoftDevice Handler state events. More…
typedef void(* nrf_sdh_state_evt_handler_t )(nrf_sdh_state_evt_t state, void *p_context)
SoftDevice Handler state event handler.
#define NRF_SDH_STATE_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice state observer. More…

SoftDevice stack events

typedef void(* nrf_sdh_stack_evt_handler_t )(void *p_evt)
SoftDevice stack event handler.
#define NRF_SDH_STACK_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice stack events observer. More…

Detailed Description

API for initializing and disabling the SoftDevice.

Macro Definition Documentation

#define NRF_SDH_DISPATCH_MODEL_APPSH   1

SoftDevice events are passed to the application using Scheduler.

Note
Scheduler must be initialized before enabling the SoftDevice handler.

#define NRF_SDH_DISPATCH_MODEL_POLLING   2

SoftDevice events are polled manually using nrf_sdh_evts_poll().

Note
In this mode, a user application can also implement SD_EVT_IRQHandler() to receive a notification about incoming events.

#define NRF_SDH_REQUEST_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice state change request observer.

An observer of SoftDevice state change requests receives requests to change the state of the SoftDevice from enabled to disabled and vice versa. These requests may or may not be acknowledged by the observer, depending on the value returned by its request handler function. Thus, a request observer has the capability to defer the change of state of the SoftDevice. If it does so, it has the responsibility to call nrf_sdh_request_continue when it is ready to let the SoftDevice change its state. If such capability is not necessary and you only need to be informed about changes of the SoftDevice state, use the NRF_SDH_STATE_OBSERVER macro instead.

Note
This macro places the observer in a section named “sdh_req_observers”.
Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

#define NRF_SDH_STACK_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice stack events observer.

A SoftDevice stack event observer receives all events from the SoftDevice. These events can be either BLE, ANT, or SoC events. If you need to receive BLE, ANT, or SoC events separately, use the NRF_SDH_BLE_OBSERVERNRF_SDH_ANT_OBSERVER, or NRF_SDH_SOC_OBSERVER macros respectively.

Note
This macro places the observer in a section named “sdh_stack_observers”.
Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

#define NRF_SDH_STATE_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice state observer.

A SoftDevice state observer receives events when the SoftDevice state has changed or is about to change. These events are only meant to inform the state observer, which, contrary to a state change request observer, does not have the capability to defer the change of state. If such capability is required, use the NRF_SDH_REQUEST_OBSERVER macro instead.

This macro places the observer in a section named “sdh_state_observers”.

Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

Typedef Documentation

typedef bool(* nrf_sdh_req_evt_handler_t)(nrf_sdh_req_evt_t request, void *p_context)

SoftDevice Handler state request handler.

Return values
true If ready for the SoftDevice to change state.
false If not ready for the SoftDevice to change state. If false is returned, the state change is aborted.

Enumeration Type Documentation

SoftDevice Handler state requests.

Enumerator
NRF_SDH_EVT_ENABLE_REQUEST Request to enable the SoftDevice.
NRF_SDH_EVT_DISABLE_REQUEST Request to disable the SoftDevice.

SoftDevice Handler state events.

Enumerator
NRF_SDH_EVT_STATE_ENABLE_PREPARE SoftDevice is going to be enabled.
NRF_SDH_EVT_STATE_ENABLED SoftDevice is enabled.
NRF_SDH_EVT_STATE_DISABLE_PREPARE SoftDevice is going to be disabled.
NRF_SDH_EVT_STATE_DISABLED SoftDevice is disabled.

Function Documentation

ret_code_t nrf_sdh_disable_request ( void )

Function for requesting to disable the SoftDevice.

This function issues a NRF_SDH_EVT_DISABLE_REQUEST request to all observers that were registered using the NRF_SDH_REQUEST_OBSERVER macro. The observers may or may not acknowledge the request. If all observers acknowledge the request, the SoftDevice will be disabled. Otherwise, the process will be stopped and the observers that did not acknowledge have the responsibility to restart it by calling nrf_sdh_request_continue when they are ready for the SoftDevice to change state.

Return values
NRF_SUCCESS The process is started.
NRF_ERROR_INVALID_STATE The SoftDevice is already disabled.

ret_code_t nrf_sdh_enable_request ( void )

Function for requesting to enable the SoftDevice.

This function issues a NRF_SDH_EVT_ENABLE_REQUEST request to all observers that were registered using the NRF_SDH_REQUEST_OBSERVER macro. The observers may or may not acknowledge the request. If all observers acknowledge the request, the SoftDevice will be enabled. Otherwise, the process will be stopped and the observers that did not acknowledge have the responsibility to restart it by calling nrf_sdh_request_continue when they are ready for the SoftDevice to change state.

Return values
NRF_SUCCESS The process is started.
NRF_ERROR_INVALID_STATE The SoftDevice is already enabled.

void nrf_sdh_evts_poll ( void )

Function for polling stack events from the SoftDevice.

The events are passed to the application using the registered event handlers.

Note
NRF_SDH_DISPATCH_MODEL_POLLING must be selected to use this function.

bool nrf_sdh_is_enabled ( void )

Function for retrieving the SoftDevice state.

Return values
true If the SoftDevice is enabled.
false If the SoftDevice is disabled.

bool nrf_sdh_is_suspended ( void )

Function for retrieving the information about the module state.

Return values
true The SoftDevice handler is paused, and it will not fetch events from the stack.
false The SoftDevice handler is running, and it will fetch and dispatch events from the stack to the registered stack observers.

ret_code_t nrf_sdh_request_continue ( void )

Function for restarting the SoftDevice Enable/Disable process.

Modules which did not acknowledge a NRF_SDH_EVT_ENABLE_REQUEST or NRF_SDH_EVT_DISABLE_REQUEST request must call this function to restart the SoftDevice state change process.

Return values
NRF_SUCCESS The process is restarted.
NRF_ERROR_INVALID_STATE No state change request was pending.

void nrf_sdh_suspend ( void )

Function for stopping the incoming stack events.

This function disables the SoftDevice interrupt. To resume polling for events, call nrf_sdh_resume.


Documentation feedback | Developer Zone | Subscribe | Updated 2017-11-24


mtk编译环境和git环境sh.exe的冲突问题

如前面的文章mtk编译时的ole.pm相关问题 提到的问题,当时为了先把mtk的编译搞定,临时的方案就是git路径下的sh.exe重命名。
但是git也是高频使用的工具,重命名肯定不是长久方案。所以还是要从根本上解决这个问题。
分析mtk的编译环境,要串接window下的相关编译工具MSYS等,还是通过系统环境变量完成的。我们搜索系统环境的Path路径,确实发现了Git的 /usr/bin 的相关路径。
删除这个路径,将重命名的sh.exe恢复,发现mtk编译正常。
再回到git工作环境,发现再删除环境路径的情况下,也工作正常,git是会支持搜索本地递归路径的吧。

至此,这个sh.exe影响的问题算是彻底解决了。

MTK GSM方案模拟器相关问题

对于开发mtk方案来说,模拟器至关重要,是提升开发效率的利器。
除了硬件驱动相关的数据接口模拟器不能调试外,tcp,wifi 等数据通讯和业务逻辑等,大多都能在模拟器中完成,所以开发mtk一定要把模拟器用好。
拿到2503的代码后,发现了一些小问题,记录之。
1. cl.exe错误
在安装vs2008后,本地已经有了cl.exe,但是模拟器代码跑起来后报cl的相关错误,很显然是环境变量确实,导致脚本调用失败。
2. 头文件错误
fatal error C1083: 无法打开包括文件:“stdarg.h”: No such file or directory
本地搜索,文件是存在的。所以还是调用问题,经确认,make\modisConfig.mak 中有对vs的路径做设定,默认是按照c盘指定的,但是本人是安装到d盘,所以该项c盘相关的路径就可以了
3. 其他函数编译错误
拿到代码后,发现之前的开发并没有使用过modis,所以硬件配置是可以编译通过的,但是modis编译不行,主要是WIN32相关的宏生命周期范围有误,还有些是对应的新增文件没有生成进modis生成的vs工程中,导致编译时调用符号缺失,根据对应函数的名称,将相关的实现文件添加到vs的工程中就可以编译了。
4. 运行崩溃问题
因为工程可能并没有在modis下面验证过,所以即使编译通过,也可能运行时崩溃。崩溃的地方主要在模拟器和硬件的逻辑差异部分,自己确认逻辑,加上合适的WIN32,基本就能问题结局。
5. 硬件数据问题
因为模拟器不能真正的使用硬件,所以在使用模拟器的时候,我们要最大可能的尽量通过软件宏逻辑来模拟硬件的数据,保证模拟器的流程跟真实硬件相同。主要的工作包括数据模拟,定时器模拟等。