月度归档:2018年10月

openssh的编译

1.执行autoheader,使其生成config.h.in文件。
2.执行autoconf,使其生成configure文件。
3.执行./configure,生成makefile文件。
4.make生成ssh

利用systemd作守护进程的脚本

#!/bin/sh
 
path_current=`pwd`
path_script=$(cd "$(dirname "$0")"; pwd)
mode=$1
name=receipt
systemd_dir=/usr/lib/systemd/system
app_process=`ps -ef | grep "$program"| grep -v grep`
force=$2

case "$mode" in
   'install')
        if [ -d $systemd_dir ];then
           if [ -f $systemd_dir/${name}.service ] && [ "$force" != "--force" ]; then
              echo "The ${name}.service had exist.!!!"
              echo "Force to install by command: install --force"
              exit
           fi
           echo "Description=$name service" > $systemd_dir/${name}.service
           echo "After=network.target" >> $systemd_dir/${name}.service
           echo "" >> $systemd_dir/${name}.service
           echo "[Service]" >> $systemd_dir/${name}.service
           echo "ExecStart=$path_script/$name --config=$path_script/config/config.toml" >> $systemd_dir/${name}.service
           echo "KillMode=process" >> $systemd_dir/${name}.service
           echo "Restart=on-failure" >> $systemd_dir/${name}.service
           echo "RestartSec=3s" >> $systemd_dir/${name}.service
           echo "" >> $systemd_dir/${name}.service
           echo "[Install]" >> $systemd_dir/${name}.service
           echo "WantedBy=multi-user.target" >> $systemd_dir/${name}.service
           systemctl daemon-reload
           systemctl enable $name
           systemctl start $name
        else
           echo "it's not support systemd feature"
        fi
        ;;
   'uninstall')
        if [ -f $systemd_dir/${name}.service ]; then
           systemctl stop $name
           systemctl disable $name
           rm -f /etc/systemd/system/multi-user.target.wants/${name}.service
           rm -f $systemd_dir/${name}.service
        fi
        ;;
   'migrate')
 	echo "it's ready to migrate database...."
	$path_script/$name --config=$path_script/config/config.toml --migrate=true
	;;
   'start')
        echo "it's ready to start op...."
        systemctl start $name
        systemctl status $name
        echo "start end......"
        ;;
   'stop')
        echo "it's ready to check process..."
        systemctl stop $name
        systemctl status $name
        echo 'success to kill.'
        ;;
   'status')
        echo "it's ready to check status..."
        systemctl status $name
        ;;
    *)
        basename=`basename "$0"`
        echo "Usage: $basename  {install|uninstall|start|stop}  [ server options ]"
        exit 1
        ;;
esac
exit 1

zipkin的docker配置

参照https://github.com/openzipkin/docker-zipkin的配置

version: '3.1'

services:
  storage:
    image: openzipkin/zipkin-mysql:2.11.7
    container_name: zipkin-mysql
    # Uncomment to expose the storage port for testing
    # ports:
    #   - 3306:3306

  zipkin:
    image: openzipkin/zipkin:2.11.7
    restart: always
    container_name: zipkin
    ports:
      - 9411:9411
    environment:
      - STORAGE_TYPE=mysql
      - MYSQL_HOST=zipkin-mysql
      # Uncomment to enable scribe
      - SCRIBE_ENABLED=true
      # Uncomment to enable self-tracing
      - SELF_TRACING_ENABLED=true
      # Uncomment to enable debug logging
      - JAVA_OPTS=-Dlogging.level.zipkin=DEBUG -Dlogging.level.zipkin2=DEBUG
    depends_on:
      - storage

sql5.7报错

match error:Error 1055: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘appstore_wps_cn.app_stores.app_type’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”

如何解决?

SET @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SELECT @@sql_mode
SELECT app_id,app_type,MAX(app_ver)app_ver,sdk_ver,app_name,client_id,client_os,package_info,down_url FROM `app_stores`  WHERE `app_stores`.`deleted_at` IS NULL AND ((`app_type`='tools') AND (`client_os`='pc') AND (`sdk_ver`<='00002.00007')) GROUP BY app_id

mintty的Cmake配置

cmake_minimum_required(VERSION 3.12)
project(src C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -include std.h -Wall -Wextra -Wundef -Werror -mtune=atom -g -O0  -fstack-check")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -MMD -MP")   

#当使用add_definitions设置时,res.rc文件是无法编译通过的,要使用CMAKE_C_FLAGS。
#add_definitions(-static-libgcc -MMD -MP -std=gnu99 -include std.h -Wall -Wextra -Wundef -Werror -mtune=atom -g -O0  -fstack-check)
message("CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
message("CMAKE_RC_COMPILER=${CMAKE_RC_COMPILER}")

include_directories(.)

link_directories(/usr/lib/w32api)

add_executable(mintty WIN32
        appinfo.h
        base64.c
        base64.h
        charset.c
        charset.h
        child.c
        child.h
        config.c
        config.h
        ctrls.c
        ctrls.h
        jumplist.c
        jumplist.h
        mcwidth.c
        minibidi.c
        minibidi.h
        print.h
        printers.c
        res.h
        sixel.c
        sixel.h
        sixel_hls.c
        sixel_hls.h
        std.c
        std.h
        term.c
        term.h
        termclip.c
        termline.c
        termmouse.c
        termout.c
        termpriv.h
        textprint.c
        win.h
        winclip.c
        winctrls.c
        winctrls.h
        windialog.c
        winids.h
        winimg.c
        winimg.h
        wininput.c
        winmain.c
        winpriv.h
        winsearch.c
        winsearch.h
        wintext.c
        wintip.c
        res.rc)

target_link_libraries(mintty libusp10.a libgdiplus.a libcomctl32.a  libimm32.a libwinmm.a libwinspool.a libole32.a libuuid.a)

validator检验

package validator

import (
	"fmt"
	"reflect"
)


func isStructPtr(t reflect.Type) bool {
	return t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct
}

func isNilOrZero(v reflect.Value) bool {
	switch v.Kind() {
	default:
		return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())
	case reflect.Interface, reflect.Ptr:
		return v.IsNil()
	}
}

func CheckRequired(obj interface{}, fields ...string) error  {
	reflectType := reflect.TypeOf(obj)
	reflectValue := reflect.ValueOf(obj)
	if !isStructPtr(reflectType) {
		return fmt.Errorf(
			"expected unnamed object value to be a pointer to a struct but got type %s "+
				"with value %v",
			reflectType,
			obj,
		)
	}
	elem := reflectValue.Elem()
	for i := 0; i < len(fields); i++ {
		name := fields[i]
		val := elem.FieldByName(name)
		if isNilOrZero(val) {
			return fmt.Errorf("the field of [ %s ] can't be empty", name)
		}
	}
	return nil
}