ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

623 items(1/63) 2 3 4 5 Next » Last »|
โดย Little Bear on 15 ก.ค. 69 07:48

เหตุการณ์ที่เกิดขึ้นคือ Mac เกิดอาการกระตุก trackpad กระโดด คุมไม่อยู่ เพลงที่เปิดเสียงติดๆ ขัดๆ ตรวจสอบ process CPU เป็นปกติ RAM กินเยอะมาก

เบื้องต้นมีปัญหาเรื่องการอ่าน/เขียน SSD คาดว่าเกิดจาก Spotlight จึงทำการปิดระบบ Spotlight ทั้งระบบไม่ให้ทำงาน

ลำดับเหตุการณ์ที่ทำให้เกิดปัญหานี้ (The Root Cause):

  1. Flutter Extension ตรวจเจอ Xcode: พอคุณเปิด VS Code ตัวปลั๊กอินเห็นว่าเครื่องนี้มีแอป Xcode ติดตั้งอยู่ (Xcode 26.6) มันจึงเข้าใจว่าคุณต้องการจะพัฒนาแอปสำหรับ iOS ด้วย [1]
  2. ปลั๊กอินพยายามสั่งเปิด simctl: ปลั๊กอินจึงส่งคำสั่ง xcrun simctl ไปยังระบบปฏิบัติการ เพื่อดึงรายชื่อเครื่องจำลอง iPhone/iPad ออกมาแสดงบนหน้าจอ [1]
  3. เกิดการ Crash (พัง) เบื้องหลัง: แต่เนื่องจากคุณไม่ได้กดดาวน์โหลดตัว iOS Simulator (Component) เก็บไว้ใน Xcode พอคำสั่ง simctl วิ่งไปหาไฟล์จำลองระบบแล้วไม่เจออะไรเลย มันจึงช็อกและปิดตัวเองลงทันที (Shutting down / Cleaning up ที่เราเห็นใน Log รอบแรก) [1]
  4. ติดลูปไร้สิ้นสุด: ตัว Flutter Extension ใน VS Code ไม่ยอมแพ้ พอมันเห็นว่ากระบวนการเช็กอุปกรณ์ดับไปโดยยังไม่ได้คำตอบ มันจึงสั่งรันคำสั่ง simctl ใหม่ซ้ำอีกครั้งในอีก 4 วินาทีถัดไป วนลูปไปเรื่อย ๆ จนทำให้ฮาร์ดดิสก์ทำงานหนัก [1]

สรุปคำแนะนำ

การที่เราแก้ปัญหาด้วยการเปลี่ยนชื่อไฟล์ simctl เป็น .bak ไปก่อนหน้านี้ ถือเป็นการแก้ทางที่ถูกต้องและปลอดภัยที่สุดสำหรับกรณีของคุณแล้วครับ เพราะเป็นการบอกตัวปลั๊กอินตรง ๆ ว่าไม่ต้องพยายามไปเรียกหาเครื่องจำลองที่ไม่มีอยู่จริงอีกต่อไป [1]

ตราบใดที่คุณยังไม่ได้ใช้ทดสอบ iOS คุณสามารถปล่อยให้ flutter doctor ขึ้นเครื่องหมาย ! แบบนี้ทิ้งไว้ได้เลย โดยไม่มีผลเสียใด ๆ กับการเขียนโค้ดฝั่ง Android หรือ Web ครับ [1]

แก้อาการอ่าน/เขียน SSD ตลอดเวลาเพื่อยืดอายุ SSD

จัดการกับ Spotlight

  1. คำสั่งปิดการทำงานทั้งหมดของ Spotlight:

bash sudo mdutil -a -i off

  1. คำสั่งเปิดกลับมาใช้งานตามปกติ:

bash sudo mdutil -a -i on

วิธีปิดการทำงาน mds_stores แบบถาวร

  1. ปิด

bash sudo mdutil -a -i off

  1. ปิดกระบวนการที่ค้างอยู่ทันที: bash sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist<br />

แก้อาการ launchd ทำงานตลอดเวลาเพื่อ run app simctl

ตรวจสอบว่า launchd ว่ากำลังทำอะไรอยู่ด้วยคำสั่ง:

bash log show --predicate 'process == "launchd"' --last 1m

พบว่าทุก 4 วินาทีจะทำการ run simctl แต่ไม่สำเร็จ ก็เลยสั่ง run ใหม่ทุก 4 วินาที ทำให้เกิดการทำงานที่ไม่ควรทำขึ้น

หลังจากพยายามมาหลายวิธีก็ยังไม่สำเร็จ จึงจัดการขั้นเด็ดขาดด้วยการ rename ชื่อ app simctl เพื่อไม่ให้ระบบ run app ได้อีกต่อไป

วิธีที่ 1: เปลี่ยนชื่อเครื่องมือค้นหา iOS เบื้องหลัง (เด็ดขาดและตรงจุดที่สุด)

เมื่อคุณไม่ได้ใช้ Xcode และไม่ได้ลงตัวจำลอง iOS ไว้ ไฟล์คำสั่ง simctl ในเครื่องคุณมักจะมาจากโฟลเดอร์ของ Command Line Tools เราจะไปทำการเปลี่ยนชื่อไฟล์หรือตัดสิทธิ์เพื่อไม่ให้ปลั๊กอิน Flutter สามารถหาคำสั่งนี้เจออีกต่อไป:

  1. เปิดแอป Terminal
  2. คัดลอกและวางคำสั่งด้านล่างนี้เพื่อตรวจสอบว่าระบบ macOS นำไฟล์ simctl ไปซ่อนไว้ที่ไหน:

bash xcrun -f simctl

  1. โดยปกติระบบจะแสดงที่อยู่ไฟล์ เช่น /Library/Developer/CommandLineTools/usr/bin/simctl ให้คุณสั่งเปลี่ยนชื่อไฟล์นั้นเพื่อซ่อนมันจาก VS Code ด้วยคำสั่งนี้ครับ:

bash sudo mv $(xcrun -f simctl) $(xcrun -f simctl).bak (ระบบจะให้พิมพ์รหัสผ่านเครื่อง Mac ของคุณเพื่อยืนยัน)

  1. เมื่อเปลี่ยนชื่อไฟล์เสร็จแล้ว ต่อให้ VS Code หรือตัวปลั๊กอินจะพยายามสั่งรันถี่ยิบแค่ไหน ระบบก็จะขึ้นว่าหาไฟล์ไม่เจอ (Command Not Found) ทันที และลูปทุก 4 วินาทีจะหยุดทำงานอย่างถาวรครับ!
  2. ตรวจสอบว่า simctl ยังคง run อยู่อีกหรือไม่

bash log show --predicate 'process == "launchd"' --last 1m

  1. อนาคตหากต้องทำงานกับ iOS ให้เปิดกลับมาใหม่ เนื่องจากได้ลองปิด services ไปหลายตัวมาก เช่น VSCODE, Flutter อาจะต้องเปิดกลับมาหลายรายการ bash sudo mv $(xcrun -f simctl).bak $(xcrun -f simctl) flutter config --enable-ios
โดย Little Bear on 7 ก.ค. 69 07:43

เช้าวันนี้ MariaDB หยุดทำงาน (อีกแล้ว....)

ก่อนอื่นให้ปิดเว็บก่อน เพื่อไม่ให้มี request เข้ามาค้างในระบบ

sudo service nginx stop

แล้วตรวจสอบ error

sudo journalctl -f -u mariadb.service --since=today
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─mariadb_custom.conf, migrated-from-my.cnf-settings.conf
     Active: activating (auto-restart) (Result: resources) since Tue 2026-07-07 06:55:31 +07;>
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
      Tasks: 40 (limit: 251281)
     Memory: 20.3G (peak: 25.9G swap: 781.1M swap peak: 797.6M)
        CPU: 1d 15h 15min 2.877s
sudo dmesg -T | grep -i -E 'oom|kill|mariadb'

ไม่พบอะไร

จาก error message ดูเหมือน

Looking at your status output, your server is using massive amounts of memory (20.3G currently active, 25.9G peak). This almost always means MariaDB is crashing due to the Linux Out-Of-Memory (OOM) killer.

กิน memory มากเกินจนค้าง zombi เลยสั่ง kill (17732) ซะ

sudo service mariadb stop
ps aux | grep mariadb
sudo kill -9 xxxxx

Reset mariadb error ก่อน แล้วค่อยสั่ง start ใหม่

sudo systemctl reset-failed mariadb.service
sudo systemctl daemon-reload
sudo systemctl start mariadb.service
sudo systemctl status mariadb.service

หลังจากนั้นก็ตรวจสอบและซ่อมแซมตารางที่พัง

sudo mariadb-check --all-databases --auto-repair

อย่าลืมเปิด nginx กลับมาด้วย

sudo service nginx start

จบ

ปล. กรณีนี้ การซ่อมแซมอัตโนมัติไม่สำเร็จ ต้องเข้าไปซ่อมเองที่ phpmyadmin

โดย Little Bear on 5 มิ.ย. 69 17:00

  1. เปิดเว็บ www.3bbddns.com
  2. Sign in ด้วยหมายเลขเน็ตบ้าน (ขึ้นต้นด้วย 888) และ เบอร์โทรที่ลงทะเบียนไว้
  3. ป้อน OTP
  4. ตั้งสถานะของพอร์ทที่ต้องการให้ Enable
  5. ตั้งค่าที่ Router
  6. Forward rule/Port Mapping Configuration
  7. Internal Host = IP ภายใน
  8. Internal port number = หมายเลข port ของ IP ภายในที่คอยรับ
  9. External port number = หมายเลข port ที่กำหนดไว้ที่ 3bb

โดย Little Bear on 28 พ.ค. 69 15:02

#Create camera service

  • Create file /etc/systems/system/camera.service
[Unit]
Description=Flood Camera FTP Scan
# Requires=mysqld.service memcached.service
After=network.target

[Service]
User=username
Group=groupname
Type=simple
TimeoutSec=0
PIDFile=/var/run/php_camera_scan.pid
WorkingDirectory=/folder/to/working
ExecStart=/usr/local/php72/bin/php -f /folder/to/file.php  2>&1 > /folder/to/store/log/file.log
KillMode=mixed

Restart=on-failure
RestartSec=42s

[Install]
WantedBy=default.target

#Run service

systemctl start camera
systemctl stop camera
systemctl restart camera
โดย Little Bear on 9 พ.ค. 69 17:54

Server มี RAM 32GB nginx + php 8.3

ลองตั้งค่า config ในไฟล์ /etc/mysql/my.cmf

[mysqld]
# ตั้งค่าขนาดที่แนะนำ
innodb_buffer_pool_size = 16G

# แบ่ง Buffer Pool เป็นส่วนย่อยเพื่อลดการแย่งทรัพยากร (แนะนำ 1GB ต่อ 1 Instance)
innodb_buffer_pool_instances = 16

# (ถ้ามี) ตั้งค่าขีดจำกัดล่างให้ระบบยืดหยุ่น
innodb_buffer_pool_size_auto_min = 8G
innodb_buffer_pool_size_auto_shrink = ON

ลองปรับขนาดแบบ Dynamic

sql
SET GLOBAL innodb_buffer_pool_size = 20G;

ปล. เคยลองแล้วไม่ได้ผล เขาบอกว่า ระบบจะค่อยๆ ปรับขนาดใน Background โดยแบ่งเป็นส่วนๆ (Chunks) จนครบตามที่คุณสั่ง

ลองตรวจสอบด้วยคำสั่ง

SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_%';
SELECT CEILING(Total_InnoDB_Bytes*1.6/POWER(1024,3)) RIBPS FROM
(SELECT SUM(data_length+index_length) Total_InnoDB_Bytes
FROM information_schema.tables WHERE engine='InnoDB') A;
SELECT (PagesData*PageSize)/POWER(1024,3) DataGB FROM
(SELECT variable_value PagesData
FROM information_schema.global_status
WHERE variable_name='Innodb_buffer_pool_pages_data') A,
(SELECT variable_value PageSize
FROM information_schema.global_status
WHERE variable_name='Innodb_page_size') B;
โดย Little Bear on 25 ธ.ค. 68 17:28

sudo crontab -e
@reboot sleep 30 && /usr/bin/curl "https://example.com/api/system/issue/add?type=Server+Reboot&url=https://softganz.com&date=$(date +%Y-%m-%dT%H:%M:%S)&agent=crontab&referer=boot"

โดย Little Bear on 13 ส.ค. 68 10:06

Create new app

flutter create --org com.yourdomain appname

Change app version

File: pubspec.yaml

version: 1.0.00+1

Create app icon

Add dependencie in file pubspec.yaml

dependencies:
...
flutterlaunchericons: ^0.14.4
And add
flutterlaunchericons:
 imagepath: "assets/icons/logo512.png"
  android: true
  ios: true
  removealphaios: true

Then run command in terminal

# dart run flutterlaunchericons:main

เอาคำว่า "DEBUG" ของเธอคืนไป

ใส่ไว้ใน MaterialApp

debugShowCheckedModeBanner: false

Change AndroidManifest.xml

File: android/app/src/main/AndroidManifest.xml

Change from

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

To

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    >

Add permission

File: android/app/src/main/AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESSNETWORKSTATE" />
    <uses-permission android:name="android.permission.WRITEEXTERNALSTORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESSFINELOCATION" />
    <uses-permission android:name="android.permission.ACCESSCOARSELOCATION" />
    <uses-feature android:name="android.hardware.camera" />

Change app label

File: android/app/src/main/AndroidManifest.xml

        android:label="My App"

InAppWebView

Add InAppWebView provider

        <provider
            android:name="com.pichillilorenzo.flutterinappwebviewandroid.InAppWebViewFileProvider"
            android:authorities="${applicationId}.flutterinappwebviewandroid.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILEPROVIDERPATHS"
                android:resource="@xml/provider_paths" />
        </provider>

Flutter command

Clean

flutter clean

Get

flutter pub get

Run release

flutter run --release

Add dependencies แล้ว แต่ import package ไม่ได้

flutter packages get
Close project and re-open project

Build app for Play Store

Generate JKS file : ถ้ายังไม่มีการสร้างไฟล์ .jks ให้สร้างขึ้นมาก่อน

keytool -genkey -v -keystore /Users/name/appname.jks -keyalg RSA -keysize 2048 -validity 10000 -alias release
ดูข้อมูลในไฟล์ .jks
keytool -v -list -keystore appname.jks
ดูข้อมูลในไฟล์ .apk
keytool -printcert -jarfile appname.apk

#กำหนดการ keystore ไว้ใน app สร้างไฟล์ [project]/android/key.properties แล้ว copy code ด้านล่างไปใส่

storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=upload
storeFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>

คำเตือน เก็บรักษาไฟล์ key.properties ไว้ให้ดี อย่างส่งขึ้น git เด็ดขาด

กำหนดค่าเพื่อ signing ใน gradle

1.แก้ไขไฟล์ [project]/android/app/build.gradle.kts

import java.util.Properties
import java.io.FileInputStream
val keyProperties = Properties().apply {
    val file = rootProject.file("key.properties")
    if (file.exists()) {
        load(FileInputStream(file))
    }
}

android { ... }

2.หา buildTypes

   buildTypes {
       release {
           // TODO: Add your own signing config for the release build.
           // Signing with the debug keys for now,
           // so flutter run --release works.
           signingConfig signingConfigs.debug
       }
   }
แทนที่ด้วย
    signingConfigs {
        create("release") {
            keyAlias = keyProperties["keyAlias"] as String
            keyPassword = keyProperties["keyPassword"] as String
            storeFile = keyProperties["storeFile"]?.let { file(it) }
            storePassword = keyProperties["storePassword"] as String
        }
        // You can also create other signing configs like "debug" if needed
    }
    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("release")
            // signingConfig signingConfigs.release
        }
    }

Build

flutter build appbundle

ผลลัพท์ของการ build จะอยู่ที่

build/app/outputs/bundle/release/app-release.aab

ติดขั้นตอนอัพโหลดขึ้น play store

"Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again. Your App Bundle is expected to be signed with the certificate with fingerprint"

ลองหาทางแก้ไข ก็ไม่หาย แต่พอลองอัพหลายครั้ง ก็ยังขึ้น error แต่ปุ่มให้ SAVE สามารถใช้งานได้ ก็เลยผ่าน

ลองอัพ version ใหม่ ปรากฎว่า ไม่ขึ้น error

App Permission

การจัดการ App Permission

หัวข้ออื่น

ที่มา

ที่มา:

โดย Little Bear on 23 ก.ค. 68 08:56

Backup to remote server

Connect remove server via folder

sshfs username@example.com:/folder localfolder

Backup with rsync

rsync -trv /folder/src/ /folder/dest/

Backup with copy

cp -R /folder/src /folder/dest &

โดย Little Bear on 26 เม.ย. 68 14:29

Shortcut

  • Command palette : Cmd ⌘ + P
  • Warp text : Option ⌥ + Z
  • Undo: Cmd ⌘ + Z
  • Redo: Cmd ⌘ + Shift ⇧ + Z
  • Bookmark next: Cmd ⌘ + Option ⌥ + L
  • Bookmark previous: Cmd ⌘ + Option ⌥ + J
  • Bookmark toggle: Cmd ⌘ + Option ⌥ + K

Settings

  • Text wrapping by default -> "editor.wordWrap": "on"
  • Access the json file with the settings by typing CTRL + SHIFT + P, then typing 'open default settings (JSON)'

How can I customize the space-to-tab conversion factor in VS Code?

Code → Preferences → Settings

// The number of spaces a tab is equal to. This setting is overridden
// based on the file contents when editor.detectIndentation is true.
"editor.tabSize": 2,

// Insert spaces when pressing Tab. This setting is overriden // based on the file contents when editor.detectIndentation is true. "editor.insertSpaces": false,

// When opening a file, editor.tabSize and editor.insertSpaces // will be detected based on the file contents. Set to false to keep // the values you've explicitly set, above. "editor.detectIndentation": false

ที่มา How can I customize the tab-to-space conversion factor in VS Code?

Setting ให้ ตำแหน่ง cursor ยังคงอยู่ที่เดิมเมื่อ vscode refocus

โดยการ disable the setting window:click through inactive หรือ window.clickThroughInactive to false

ที่มา [Can you stop VS Code from moving the cursor when you tap to refocus a window?](https://stackoverflow.com/questions/61789575/can-you-stop-vs-code-from-moving-the-cursor-when-you-tap-to-refocus-a-window)

โดย Little Bear on 23 ก.พ. 68 13:59


View

ตรวจสอบ OS version

cat /etc/os-release

ขั้นตอน 1: Update เวอร์ชั่นปัจจุบันของ Ubuntu

***

sudo apt update && apt upgrade -y

ขั้นตอน 2: เตรียมสำหรับการ upgrade:

***

sudo apt install update-manager-core

ขั้นตอน 3: Run the Upgrade:

***

sudo do-release-upgrade

***

ขั้นตอน 4: Post-Upgrade Cleanup:

***

sudo apt autoremove && apt clean

ขั้นตอน 5: ตรวจสอบผลการอัพเกรด: ***

cat /etc/os-release

***

หากเกิดความผิดพลาด สามารถเปลี่ยน sources แล้ว update

First, ensure that all the contents of /etc/apt/sources.list and /etc/apt/sources.list.d/ubuntu.sources contain the word noble instead of jammy. If it contains jammy, replace that with noble.

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's/jammy/noble/g' /etc/apt/sources.list
sudo sed -i 's/jammy/noble/g' /etc/apt/sources.list.d/ubuntu.sources
sudo apt update
sudo apt full-upgrade

หลังจาก upgrade แล้ว start apache ไม่ได้ เนื่องจากมีการเปลี่ยน php version ให้สร้างลิงก์ไฟล์ของ apache config ใหม่

cd /etc/apache2/mods-enable
ln -s php8.1.conf ../mods-avaliable/php8.1.conf
ln -s php8.1.load ../mods-avaliable/php8.1.load

แล้ว restart apache

systemctl restart apache2

Upgrade MariaDB

apt upgrade mariadb-server
apt install mariadb-server
623 items(1/63) 2 3 4 5 Next » Last »|