edit /etc/lsyncd.conf

default file setting

----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
-- 
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}

[vagrant@localhost ~]$ sudo vi /etc/lsyncd.conf

settings {
	logfile = "/var/log/lsyncd/lsyncd.log",
	statusFile = "/var/log/lsyncd/lsyncd.status"
}

sync {
	default.rsync,
	source = "/tmp/origin",
	target = "/tmp/target",
	rsync = {
		archive = true,
		compress = true
	},
	delete = false
}

[vagrant@localhost ~]$ mkdir -m 700 /var/log/lsyncd && chcon -R -u system_u “/var/log/lsyncd”
mkdir: ディレクトリ `/var/log/lsyncd’ を作成できません: ファイルが存在します
なにいいいいいいいいいいいいいいい

[vagrant@localhost ~]$ systemctl restart rsyslog
-bash: systemctl: コマンドが見つかりません
[vagrant@localhost ~]$ systemctl start lsyncd
-bash: systemctl: コマンドが見つかりません

なにいいいいいいいいいいいいいいいいいいいいいいいい

cp -ip ${file_name}

-i option: to confirm when overwriting is necessary
In contrast to the -f option, sometimes you want to check whether it will be overwritten. When dealing with important files, overwriting is a fatal injury.

$cp -i after original copy

“yes or no” confirmation will come out.

cp -i

In recent distributions this is the default as well. If it is not set it may be set with alias.

-p opiton(-parents): copy each directory structure
With the usual cp command, you can not copy in subdirectories. In that case, use the “-P” option.

Running without options in the example will normally just let file.txt go into the directory. Using the –parents option you will find that you can copy the directory structure as is.

[vagrant@localhost ~]$ cp -ip /etc/lsyncd.conf{,.org}
cp: cannot create regular file `/etc/lsyncd.conf.org’: 許可がありません
[vagrant@localhost ~]$ sudo cp -ip /etc/lsyncd.conf{,.org}

install Lsyncd on CentOS

Introduction of Extra Packages for Enterprise Linux (EPEL).

/etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[vagrant@localhost ~]$ sudo sed -i -e “s/enabled=1/enabled=0/” /etc/yum.repos.d/epel.repo

[vagrant@localhost ~]$ sudo yum –enablerepo=epel install lsyncd
読み込んだプラグイン:fastestmirror
インストール処理の設定をしています
Determining fastest mirrors
epel/metalink | 7.6 kB 00:00
* base: ftp-srv2.kddilabs.jp
* epel: mirror01.idc.hinet.net
* extras: ftp-srv2.kddilabs.jp
* remi-safe: ftp.riken.jp
* updates: ftp-srv2.kddilabs.jp
base | 3.7 kB 00:00
epel | 4.7 kB 00:00
epel/primary_db | 6.0 MB 00:12
extras | 3.4 kB 00:00
jenkins | 2.9 kB 00:00
jenkins/primary_db | 126 kB 00:01
mariadb | 2.9 kB 00:00
mysql-connectors-community | 2.5 kB 00:00
mysql-tools-community | 2.5 kB 00:00
mysql56-community | 2.5 kB 00:00
nginx | 2.9 kB 00:00
nodesource | 2.5 kB 00:00
remi-safe | 3.0 kB 00:00
remi-safe/primary_db | 1.2 MB 00:02
updates | 3.4 kB 00:00
依存性の解決をしています
–> トランザクションの確認を実行しています。
—> Package lsyncd.x86_64 0:2.1.5-0.el6 will be インストール
–> 依存性解決を終了しました。

依存性を解決しました

================================================================================
パッケージ アーキテクチャ バージョン リポジトリー 容量
================================================================================
インストールしています:
lsyncd x86_64 2.1.5-0.el6 epel 73 k

トランザクションの要約
================================================================================
インストール 1 パッケージ

総ダウンロード容量: 73 k
インストール済み容量: 205 k
これでいいですか? [y/N]y
パッケージをダウンロードしています:
lsyncd-2.1.5-0.el6.x86_64.rpm | 73 kB 00:00
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
インストールしています : lsyncd-2.1.5-0.el6.x86_64 1/1
Verifying : lsyncd-2.1.5-0.el6.x86_64 1/1

インストール:
lsyncd.x86_64 0:2.1.5-0.el6

完了しました!

ほう^^

lsyncd

Lyscd – Live Syncing (Mirror) Daemon uses inotify to detect that a change has been made to the directory to be monitored, and uses rsync etc. to synchronize that changed files.

You can set it to call another tool instead of rsync.

Since synchronization is done on a file basis, it is not suitable for duplicating databases and the like.

– Regarding file updates monitored by kernel inotify, use API to monitor updates.
– Implement rsync to the mirror destination rsyncd (default is to use rsync) when file update occurs, realizing directory mirroring in real time.
– In addition to the default rsync, it is possible to use DRDB, GlusterFS, BindFS, etc. as a synchronization method.

umask

Normally, if you create a 0 byte file by specifying “touch ${filename}” etc, the permission should be created as 644(rw-r–r-). If files or directories to be created are 666(rw-rw-rw-) or 777(rwxrwxrwx), all users can write and delete them.

In this way, “umask” controls the permissions of newly created files and directories.

[vagrant@localhost ~]$ umask
0002

時と場合によるが、やはりデフォルトは644で良いように思いますな。

headerとsidemenuは1ファイルにインクルード化

フロントは予め作っておきます。

#!/usr/bin/perl --

print "Content-type:text/html\n\n";
$title = "トップ";
open(FH, "../html/header.html");
while($header = <FH>){
	if($header =~ /title/){
			print "<title>$title</title>";
		} else {
			print $header;
		}
}
close(FH);

open(FH, "../html/side.html");
while($side = <FH>){
		print $side;
}
close(FH);

ほほーう、なるほどね。こうすれば、わざわざ1行ずつprint “html tag”; なんて面倒なことしなくていいですね。
Perlの苦手意識が先行していたが、少し楽しくなってきた^^

mainも追加します。

#!/usr/bin/perl --

print "Content-type:text/html\n\n";
$title = "トップ";
open(FH, "../html/header.html");
while($header = <FH>){
	if($header =~ /title/){
			print "<title>$title</title>";
		} else {
			print $header;
		}
}
close(FH);

open(FH, "../html/side.html");
while($side = <FH>){
		print $side;
}
close(FH);

open(FH, "../html/hoge.html");
while($main = <FH>){
		print $main;
}
close(FH);

ひょえーーー

Perlでtitleを変数にして差し込みたいんだが。。。

#!/usr/bin/perl --

print "Content-type:text/html\n\n";
$title = "ほげ";
open(FH, "../html/header.html");
while($data = <FH>){
	
	print "$data";
}
close(FH);

titleを予め$titleとすると、、、

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>$title</title>
	<link rel="stylesheet" type="text/css" href="asset/css/main.css" />
</head>
<header>
	<p><a href="index.html">Hpscript</a></p>
	<ul>
	    <li>ユーザーID:hogehoge</li>
	    <li>2019-03-01 18:26:35</li>
	</ul>
	<nav>
		<p>システム</p>
	</nav>
</header>

これだと、タイトルが$titleで出力されるんだなー

print "Content-type:text/html\n\n";
$title = "ほげ";
open(FH, "../html/header.html");
while($data = <FH>){
	if($data =~ /title/){
			print "<title>$title</title>";
		} else {
			print $data;
		}
}
close(FH);

完全に違う気がするけどー、一応タイトルは変数にしてタイトル以外はインクルードもできるっちゃできるなーーーーーーー^^

perl cgiでhtmlファイルを読み込む

まずcgi

#!/usr/bin/perl --

print "Content-type:text/html\n\n";
print <<END;
    <html>
    <head>
    <title>HTMLファイル読み込み</title>
    </head>
    <body>
END

open(FH, "../html/hoge.html");
while($data = <FH>){
	print "$data";
}
close(FH);

print <<END;
    <br>
    </body>
    </html>
END

hoge.html

<h1>hello</h1>
perl included<br>hoge

view

これ実装するのに1時間半かかったー
open(FH, “../html/hoge.html”); のところで、../hoge.html とかやってたわ。。
むむむ、これもしかして、Content-type:text/htmlだけ指定すれば、以下は全部読み込める??

cgiから、cssやjsなどassetを読み込むから、「..」で一度上に上がって、指定すればできますね。

<link rel="stylesheet" type="text/css" href="../asset/css/main.css" />

あ、なるほど、ここで、ヘッダー、メニューをインクルードすればいいのか。頭良すぎww

chmod -R 755 ${dir}

Internal Server Error

[vagrant@localhost acs]$ cd /var/www/cgi-bin
[vagrant@localhost cgi-bin]$ chmod -R 755 asset

あ”

Since the cgi-bin directory is recognized as in the normal apache@unix environment it is only “CGI program”, the server attempts to execute the CSS files as a obviously program it is the cause of the error.

There are several workaround options, but it is easy to move the CSS and JS files under htdoc/ directory (where index.html by default).

htmlディレクトリ配下に移動させます。

print "	<link rel=\"stylesheet\" type=\"text/css\" href=\"../html/asset/css/styles.css\" />";

htmlはいらない模様。。修正します。

print "	<link rel=\"stylesheet\" type=\"text/css\" href=\"../asset/css/styles.css\" />";

これでOK。なるほどー

perl cgiのインデント

そもそもperlは使わない、なんてことは触れないとして、
cgiでhtmlをタグを書く際に、半角スペース4つ分のインデントを開けるのか?という疑問が湧いてくる。
他のコードを見ると、インデントは開けずに書いているように見えるが。。果たして。。

#!/usr/bin/perl --
use strict;
use utf8;

print "Content-type:text/html\n\n";
print "<!DOCTYPE html>";
print "<html>";
print "<head>";
print "	<meta charset=\"UTF-8\">";
print "	<title>ログイン|入稿管理支援システム</title>";
print "	<link rel=\"stylesheet\" type=\"text/css\" href=\"asset/css/styles.css\" />";
print "</head>";
print "<header>";
print "	<p><a href=\"index.html\">Hpscript</a></p>";
print "	<nav>";
print "		<p>入稿管理支援システム</p>";
print "	</nav>";
print "</header>";
print "<body>";
print "    <div id=\"content\">";
print "	<h1>ログイン</h1>";
print "	<form action=\"cgi-bin/hoge.cgi\" method=\"post\">";
print "		<p>";
print "		    ユーザーID:<input type=\"text\" name=\"login_id\" size=\"30\">";
print "		</p>";
print "		<p>";
print "		    パスワード:<input type=\"text\" name=\"password\" size=\"30\">";
print "		</p>";
print "		<p>";
print "		    <input type=\"submit\" value=\"ログイン\">";
print "		</p>";
print "	</form>";
print "	</div>";
print "</body>";
print "</html>";

インデントを付けたからと言って見やすくなるわけでもないから、いらないようにも思える。。