顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2018年3月21日 星期三

[Systemd] After reboot, ngrok & ctlscript.sh will be started

python script

import os
import sys
import time

def main():
    time.sleep(10)
    cmd = "/home/freeman/webs/redmine-3.3.0-1/ctlscript.sh start &"
    os.system(cmd)
    cmd1 = "/usr/bin/screen -dm /home/freeman/APP/ngrok/ngrok http 8080" 
    os.system(cmd1)

if __name__ == '__main__':
    main()

systemd script
$ cat /etc/systemd/system/myscript.service 
[Unit]
Description=My script

[Service]
User=freeman
Group=freeman
Type=forking
ExecStart=/usr/bin/python3 /home/freeman/a.py

[Install]
WantedBy=multi-user.target

Because ctlscript.sh must execute by normal user not root.
So specifi user and group.

Type=forking is description as following.

The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main daemon process.

Reference:

2018年3月20日 星期二

2018年3月14日 星期三

2018年1月17日 星期三

2017年11月14日 星期二

2017年11月13日 星期一

2017年11月9日 星期四

[Virtualbox kernel module][Archlinux] How to compile virtualbox kernle module

Download linux-headers-4.13.9-1-x86_64.pkg.tar.xz

Decompress the package
tar xvf linux-headers-4.13.9-1-x86_64.pkg.tar.xz -C linux-headers
cd linux-headers/usr/lib/modules/4.13.9-1-ARCH/build

Copy the linux source code to corresponding folder.
sudo cp * /lib/modules/4.13.9-1-ARCH/build/ -Rf


Download vbox-kernel-module - vbox-kernel-module-src-5.2.0.tar.xz

Decompress the package
tar xvf vbox-kernel-module-src-5.2.0.tar.xz -C /tmp
cd /tmp/
make
sudo make install

Make install will copy to following folder
/lib/modules/4.13.9-1-ARCH/misc

According to following hyperlink will understand how to mount kernel module after reboot.
[Virtualbox][Archlinux] Upgrade vboxdrv.ko after upgrade Linux kernel
echo vboxdrv >> /etc/modules-load.d/virtualbox.conf &&\
echo vboxnetadp >> /etc/modules-load.d/virtualbox.conf &&\
echo vboxnetflt >> /etc/modules-load.d/virtualbox.conf &&\
echo vboxpci >> /etc/modules-load.d/virtualbox.conf


Vagrant

[VirtualBox][Vagrant] How to install and use vagrant

2017年11月8日 星期三

[Python] Python virtual environment lib path

Method 1:

Download RPi.GPIO 0.6.3

tar xvf RPi.GPIO-0.6.3.tar.gz

cd RPi.GPIO-0.6.3

Start to build the C code
python3 setup build

cd RPi.GPIO-0.6.3/build/lib.linux-armv7l-3.4

Copy RPi module to virtual environment of python
cp RPi /home/pi/env/lib/python3.4/site-packages (which env is virtual environment)


Method 2:

source ~/env/bin/activate

Download RPi.GPIO 0.6.3

tar xvf RPi.GPIO-0.6.3.tar.gz

cd RPi.GPIO-0.6.3

Start to build the C code and install binary and library file into the virtual environment of python path.
python3 setup install

Reference:

2017年11月7日 星期二

2017年9月22日 星期五

2017年9月12日 星期二

[Routing][Concept] Routing command

When type ip rule will show like following ``` # ip rule show 0: from all lookup local 32766: from all lookup main 32767: from all lookup default ``` I draw picture like following ``` +-------------------------------------+ | ip rule | | +------------+ | | | | | | | local | | | | | | | +------------+ | | | | +------------+ | | | | | | | main | | | | | | | +------------+ | +-------------------------------------+ ``` ip route show table main = ip route show = route -n ``` [happy@localhost tftp]$ ip route show table main default via 192.168.0.1 dev wlp3s0 default via 192.168.1.1 dev enp4s0 default via 192.168.0.1 dev wlp3s0 src 192.168.0.101 metric 302 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 192.168.0.0/24 dev wlp3s0 proto kernel scope link src 192.168.0.101 metric 302 192.168.1.0/24 dev enp4s0 proto kernel scope link src 192.168.1.2 192.168.100.0/24 dev enp0s20u13 proto kernel scope link src 192.168.100.20 linkdown [happy@localhost tftp]$ ip route show default via 192.168.0.1 dev wlp3s0 default via 192.168.1.1 dev enp4s0 default via 192.168.0.1 dev wlp3s0 src 192.168.0.101 metric 302 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 192.168.0.0/24 dev wlp3s0 proto kernel scope link src 192.168.0.101 metric 302 192.168.1.0/24 dev enp4s0 proto kernel scope link src 192.168.1.2 192.168.100.0/24 dev enp0s20u13 proto kernel scope link src 192.168.100.20 linkdown [happy@localhost tftp]$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 wlp3s0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 enp4s0 0.0.0.0 192.168.0.1 0.0.0.0 UG 302 0 0 wlp3s0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 192.168.0.0 0.0.0.0 255.255.255.0 U 302 0 0 wlp3s0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 enp4s0 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s20u13 ```

2017年9月3日 星期日

[Linux][Archlinux] How to use bochs to simulate linux-0.12

Install bochs
pacman -S bochs

Download two file from oldlinux
1. bootimage-0.12-20040306
2. rootimage-0.12-20040306

Change permission about two file.
chmod 777 bootimage-0.12-20040306
chmod 777 rootimage-0.12-20040306

Create configuration file(boch.bxrc) under some folder which two file locate.

boch.bxrc

megs:32
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
floppya: 1_44=/tmp/test/bootimage-0.12-20040306, status=inserted
floppyb: 1_44=/tmp/test/rootimage-0.12-20040306, status=inserted
boot: a
log: bochsout.txt
mouse: enabled=0

now start bochs to simulate linux0.12
# bochs

Step 1

------------------------------
Bochs Configuration: Main Menu
------------------------------

This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate.  Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found.  When you are satisfied with the configuration, go
ahead and start the simulation.

You can also start bochs with the -q option to skip these menus.

1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now

Please choose one: [2] 

Step 2

What is the configuration file name?
To cancel, type 'none'. [none] boch.bxrc

Step 3

This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate.  Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found.  When you are satisfied with the configuration, go
ahead and start the simulation.

You can also start bochs with the -q option to skip these menus.

1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now

Please choose one: [6] 

Step 4

Please choose one: [6] 
00000000000i[      ] installing x module as the Bochs GUI
00000000000i[      ] using log file bochsout.txt
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
<bochs:1> help

Step 5

<bochs:1> help
h|help - show list of debugger commands
h|help command - show short command description
-*- Debugger control -*-
    help, q|quit|exit, set, instrument, show, trace, trace-reg,
    trace-mem, u|disasm, ldsym, slist
-*- Execution control -*-
    c|cont|continue, s|step, p|n|next, modebp, vmexitbp
-*- Breakpoint management -*-
    vb|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,
    bpe, bpd, d|del|delete, watch, unwatch
-*- CPU and memory contents -*-
    x, xp, setpmem, writemem, crc, info,
    r|reg|regs|registers, fp|fpu, mmx, sse, sreg, dreg, creg,
    page, set, ptime, print-stack, ?|calc
-*- Working with bochs param tree -*-
    show "param", restore
<bochs:2> c (press c)

Another screen will show following message.
Then click “CONFIG” to set floppy A to another image

root floppy and press ENTER

Please type “1” to change the image of floppy A.

-----------------------
Bochs Runtime Options
-----------------------
1. Floppy disk 0: /tmp/bootimage-0.12-20040306, inserted
2. Floppy disk 1: /tmp/rootimage-0.12-20040306, inserted
3.
4.
5.
6.
7.
8.
9. Continue simulation
10. Quit now

Please choose one: [9] 1

Please type like following showing.

-----------------------
First Floppy Drive
-----------------------
Enter new filename, or 'none' for no disk: [/tmp/bootimage-0.12-20040306] /tmp/rootimage-0.12-20040306

Skill following settings.
Now show screen like below, then press enter to continue simulation.

-----------------------
Bochs Runtime Options
-----------------------
1. Floppy disk 0: /tmp/bootimage-0.12-20040306, inserted
2. Floppy disk 1: /tmp/rootimage-0.12-20040306, inserted
3.
4.
5.
6.
7.
8.
9. Continue simulation
10. Quit now

Please choose one: [9] 

The screen will show following message that mean we set all environment settings is working now.

[/usr/root]#

2017年7月21日 星期五

2017年7月20日 星期四

[Redmine][bitnami] How to quick install redmine

Download bitnami - redmine from bitnami - redmine

Change the permission of bitnami-redmine-3.4.2-0-linux-x64-installer.run
chmod 755 bitnami-redmine-3.4.2-0-linux-x64-installer.run

Install bitnami redmine
./bitnami-redmine-3.4.2-0-linux-x64-installer.run --disable_glibcxx_version_check 1


INSTALL SQLITE3 GEM FOR RUBY
/home/happy/webs/redmine-work1/ruby/bin/gem install sqlite3-ruby

Jump to redmine folder
cd /home/happy/webs/redmine-work1/apps/redmine/htdocs
Install the dependencies specified in your Gemfile
Please stay at above folder example, and type following command.
Please modify the string of "/home/happy/webs/redmine-work1" to your real command folder.
/home/happy/webs/redmine-work1/ruby/bin/bundle install --no-deployment

Start to configure the environment settings.
cd /home/happy/webs/redmine-work1/apps/redmine/htdocs
CONFIGURE DATABASE
echo “production:” > config/database.yml &&\
echo ” adapter: sqlite3” >> config/database.yml &&\
echo ” database: db/redmine.sqlite3” >> config/database.yml

POPULATE DATABASE
cd /home/happy/webs/redmine-work1/apps/redmine/htdocs
/home/happy/webs/redmine-work1/ruby/bin/rake db:migrate RAILS_ENV=”production”
/home/happy/webs/redmine-work1/ruby/bin/rake redmine:load_default_data RAILS_ENV=”production”

Create secret_token
cd /home/happy/webs/redmine-work1/apps/redmine/htdocs
echo “production:” > config/secrets.yml &&\
echo ” secret_key_base: $(/home/happy/webs/redmine-work1/ruby/bin/rake secret)” >> config/secrets.yml

Restart the server
cd /home/happy/webs/redmine-work1
bash ctlscript.sh restart

Reference:


How to Modify the port of mysql

Modify the port of mysql
vim ./apache2/conf/bitnami/bitnami.conf +35
modify all 8443 to other port number

Modify the port of http
vim ./apache2/conf/bitnami/bitnami.conf +35
modify all 8081 to other port number

Question:
$ gem install sqlite3
ERROR: Could not find a valid gem ‘sqlite3’ (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=error: certificate verify failed (https://api.rubygems.org/latest_specs.4.8.gz)

Answer:
$ gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources

$gem sources -a http://rubygems.org/
https://rubygems.org is recommended for security over http://rubygems.org/

Ref:

2017年7月19日 星期三

[Review Board] How to install review board quickly

Download bitnami-reviewboard-2.5.13.1-0-linux-x64-installer.run
Change this package permission.

Start to execute the package and install to user’s specific folder.
./bitnami-reviewboard-2.5.13.1-0-linux-x64-installer.run --disable_glibcxx_version_check 1

During installation will need to create superuser account and password.

Connect to http://127.0.0.1:8081/reviewboard/admin/, and create a repository.
If dont know the repository path, please type "git remote show origin".



Reference:

2017年7月12日 星期三

[docker] Build up Linux kernel research environment by using docker/qemu

Download

    $ git clone https://github.com/tinyclub/cloud-lab.git
    $ cd cloud-lab && tools/docker/choose linux-lab

Install

    $ tools/docker/pull        # Pull from docker hub
    or
    $ tools/docker/build       # Build from source

Run

    $ tools/docker/run        # Start to run
[Happy@localhost cloud-lab]$ sudo tools/docker/rm
[sudo] password for Happy: 
LOG: Current Lab is linux-lab
LOG: Running ' docker rm -f linux-lab-27586 '
linux-lab-27586
[Happy@localhost cloud-lab]$ sudo tools/docker/run
LOG: Current Lab is linux-lab
LOG: Wait for lab launching...
LOG: Container ID: 89fadc31d6ae Container Name: linux-lab-28086
LOG: User: ubuntu Password: e9nU1doA7nhtsUA VNC Password: 1tC2ya4RCMRrXXA
LOG: Current Lab is linux-lab
LOG: No chromium-browser found, use firefox instead.
Please login http://localhost:6080/vnc.html?token=2dcb0b51f6f2a6a6800bc33a93dfc210&password=1tC2ya4RCMRrXXA&autoconnect=0&encrypt=0

Connect to Docker by ssh

ssh 172.17.0.3 -l ubuntu

Connect to simulation board

    $ cd /labs/linux-lab
    $ make boot

Get Source Code

    $ make source -j3             # Download linux-stable, qemu 和 buildroot

Reference:

2017年7月6日 星期四

[Linux][Knowledge] pkg-config

Edit following script, and save as test.pc

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${exec_prefix}/include

Name: libpng
Description: Loads and saves PNG files
Version: 1.2.8
Libs: -L${libdir} -lpng12 -lz
Cflags: -I${includedir}/libpng12



Type following command will show like below.

[happy@localhost 1]$ pkg-config --variable=prefix a.pc
/usr/local

[freeman@localhost 1]$ pkg-config --cflags a.pc
-I/usr/local/include/libpng12

[freeman@localhost 1]$ pkg-config --libs a.pc 
-L/usr/local/lib -lpng12 -lz



Reference:

2017年6月24日 星期六

[Arduino][ncurses-5.9] Compile ncurses-5.9 by using gcc-5

Download package
ncurses-5.9.tar.gz


Decompress package, and configure it.
./configure –prefix=/opt –with-shared –without-normal –without-debug –without-cxx-binding CC=/usr/bin/gcc-5


Patch into current file.
./script/build failure with GCC 5.1.0


Create patch file
modules/ncurses - fix complation on gcc 5.1


Save following file into a.patch
--- a/ncurses/base/MKlib_gen.sh
+++ b/ncurses/base/MKlib_gen.sh
@@ -474,11 +474,22 @@ sed -n -f $ED1 \
    -e 's/gen_$//' \
    -e 's/  / /g' >>$TMP

+cat >$ED1 <<EOF
+s/  / /g
+s/^ //
+s/ $//
+s/P_NCURSES_BOOL/NCURSES_BOOL/g
+EOF
+
+# A patch discussed here:
+#  https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
+# introduces spurious #line markers.  Work around that by ignoring the system's
+# attempt to define "bool" and using our own symbol here.
+sed -e 's/bool/P_NCURSES_BOOL/g' $TMP > $ED2
+cat $ED2 >$TMP
+
 $preprocessor $TMP 2>/dev/null \
-| sed \
-   -e 's/  / /g' \
-   -e 's/^ //' \
-   -e 's/_Bool/NCURSES_BOOL/g' \
+| sed -f $ED1 \
 | $AWK -f $AW2 \
 | sed -f $ED3 \
 | sed \
Under the folder of ncurses-5.9
patch -p1 < a.patch


Start to compile and install
make && make install


link file into /usr/lib/
sudo ln -s /opt/lib/libncurses.so /usr/lib/libncurses.so.5
sudo ln -s /opt/lib/libncurses.so /usr/lib/libtinfo.so.5


Reference: