|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "os"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
gps "hnyfkj.com.cn/rtu/linux/air530z"
|
|
gps "hnyfkj.com.cn/rtu/linux/air530z"
|
|
@@ -11,6 +12,66 @@ import (
|
|
|
"hnyfkj.com.cn/rtu/linux/sshd"
|
|
"hnyfkj.com.cn/rtu/linux/sshd"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+const (
|
|
|
|
|
+ rcLocalTxt = `
|
|
|
|
|
+#!/bin/sh -e
|
|
|
|
|
+#
|
|
|
|
|
+# rc.local
|
|
|
|
|
+#
|
|
|
|
|
+# This script is executed at the end of each multiuser runlevel.
|
|
|
|
|
+# Make sure that the script will "exit 0" on success or any other
|
|
|
|
|
+# value on error.
|
|
|
|
|
+#
|
|
|
|
|
+# In order to enable or disable this script just change the execution
|
|
|
|
|
+# bits.
|
|
|
|
|
+#
|
|
|
|
|
+# By default this script does nothing.
|
|
|
|
|
+
|
|
|
|
|
+#设置系统主频
|
|
|
|
|
+echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
|
|
|
|
|
+echo 528000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
|
|
|
|
|
+
|
|
|
|
|
+#设置一秒落盘(是低功耗产品时, RTU数据板可能随时掉电, 长供电产品, 不需要设置)
|
|
|
|
|
+#echo 100 > /proc/sys/vm/dirty_writeback_centisecs
|
|
|
|
|
+#echo 100 > /proc/sys/vm/dirty_expire_centisecs
|
|
|
|
|
+
|
|
|
|
|
+#启动运行程序
|
|
|
|
|
+/home/root/rtu_linux_modules/script/stop
|
|
|
|
|
+/home/root/rtu_linux_modules/script/start
|
|
|
|
|
+
|
|
|
|
|
+exit 0
|
|
|
|
|
+`
|
|
|
|
|
+ rcLocalFile = "/etc/rc.local"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+func enableAutoStartOnBoot() error {
|
|
|
|
|
+ if _, err := os.Stat(rcLocalFile); err == nil {
|
|
|
|
|
+ bakFile := rcLocalFile + "." + time.Now().Format("20060102150405")
|
|
|
|
|
+ err = os.Rename(rcLocalFile, bakFile)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ f, err := os.OpenFile(rcLocalFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ defer f.Close()
|
|
|
|
|
+
|
|
|
|
|
+ _, err = f.WriteString(rcLocalTxt)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ err = os.Chmod(rcLocalFile, 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func main() {
|
|
func main() {
|
|
|
if baseapp.IsArgsParam("-h") {
|
|
if baseapp.IsArgsParam("-h") {
|
|
|
help()
|
|
help()
|
|
@@ -22,6 +83,16 @@ func main() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if baseapp.GetArgsParamStr("-install", "") == "boot" {
|
|
|
|
|
+ err := enableAutoStartOnBoot()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Printf("设置开机自启动失败: %v", err)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Println("设置开机自启动成功")
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
baseapp.ModuleInit()
|
|
baseapp.ModuleInit()
|
|
|
baseapp.SingleInstanceRun() // 异步非阻塞
|
|
baseapp.SingleInstanceRun() // 异步非阻塞
|
|
|
baseapp.Logger.Infof("程序版本: %s 构建时间: %s\n程序开始运行...",
|
|
baseapp.Logger.Infof("程序版本: %s 构建时间: %s\n程序开始运行...",
|
|
@@ -40,9 +111,7 @@ func main() {
|
|
|
netmgrd.WaitAllOK(time.Duration(10) * time.Second) // 等待联网成功和网路时间同步成功
|
|
netmgrd.WaitAllOK(time.Duration(10) * time.Second) // 等待联网成功和网路时间同步成功
|
|
|
|
|
|
|
|
// 04, 初始化远程运维模块, Todo: 根据项目不同, 远程运维连接的MQTT服务器不同, 具体看情况
|
|
// 04, 初始化远程运维模块, Todo: 根据项目不同, 远程运维连接的MQTT服务器不同, 具体看情况
|
|
|
- if err := sshd.ModuleInit("", "", ""); err != nil {
|
|
|
|
|
- baseapp.Logger.Warnf("初始化远程运维模块失败: %v", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ sshd.ModuleInit("", "", "")
|
|
|
|
|
|
|
|
// 05, 初始化相机拍照模块
|
|
// 05, 初始化相机拍照模块
|
|
|
if !camera1.ModuleInit() {
|
|
if !camera1.ModuleInit() {
|