Archive for the ‘Serverの構築と運用覚書き’ Category



本ブログ(WordPress)記事を SNS Blueskyに自動的に投稿

Wednesday, March 26th, 2025

このブログ上に新規作成したポスト記事を、X(旧Twitter)に加えて、米新興SNSのBlueskyにも自動投稿できるようにした。Bluesky apiが公開され、PHPでの投稿ができそうなのでTwitterへの投稿機能を拡張した。

このところ、イーロン・マスクがXを私物化し、横暴な態度をとっていることから、Xの利用者がBlueskyへ乗り換えるが進んでいるようだ。日経電子版(3/11 配信)の記事「米SNSのBluesky、利用者4カ月で2倍 Xから乗り換え」もよると、利用者が急速に伸び3300万人にも達したとのことだ。
このブログ記事の要約をX同様にBlueskyにも投稿できるようにすることも多少の意味があるのでは考えた。
(続きを読む)



radiko の録音用 shell scriptの見直し

Friday, March 7th, 2025

今年の1/20以降、radikoの録音ができなくなっていた。

障害発生の原因を調査したところ、原因がradikoの録音用 shell scriptのなかのstreaming urlの設定部分が変更されていることがわかった。

なお、認証部については、これまでと変化していない。

更新後のshell script の sourceは以下:

#!/bin/bash

LANG=ja_JP.utf8

pid=$$
date=`date '+%Y-%m-%d-%H:%M'`

outdir="."

if [ $# -le 1 ]; then
  echo "usage : $0 channel_name duration(minuites) [outputdir] [prefix]"
  exit 1
fi

if [ $# -ge 2 ]; then
  channel=$1
  DURATION=`expr $2 \* 60`
fi
if [ $# -ge 3 ]; then
  outdir=$3
fi
PREFIX=${channel}
if [ $# -ge 4 ]; then
  PREFIX=$4
fi

####
# Define authorize key value (from http://radiko.jp/apps/js/playerCommon.js)
RADIKO_AUTHKEY_VALUE="bcd151073c03b352e1ef2fd66c32209da9ca0afa"


if [ -f auth1_fms_${pid} ]; then
  rm -f auth1_fms_${pid}
fi

#
# access auth1_fms
#
curl -s \
     --header "pragma: no-cache" \
     --header "X-Radiko-App: pc_html5" \
     --header "X-Radiko-App-Version: 0.0.1" \
     --header "X-Radiko-User: test-stream" \
     --header "X-Radiko-Device: pc" \
     --dump-header auth1_fms_${pid} \
     -o /dev/null \
     https://radiko.jp/v2/api/auth1

if [ $? -ne 0 ]; then
  echo "failed auth1 process"
  exit 1
fi

#
# get partial key
#
authtoken=`perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)' auth1_fms_${pid}`
offset=`perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)' auth1_fms_${pid}`
length=`perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)' auth1_fms_${pid}`
partialkey=`echo "${RADIKO_AUTHKEY_VALUE}" | dd bs=1 "skip=${offset}" "count=${length}" 2> /dev/null | base64`

echo "partialkey: $partialkey"

rm -f auth1_fms_${pid}

if [ -f auth2_fms_${pid} ]; then  
  rm -f auth2_fms_${pid}
fi

#
# access auth2_fms
#
curl -s \
     --header "pragma: no-cache" \
     --header "X-Radiko-User: test-stream" \
     --header "X-Radiko-Device: pc" \
     --header "X-Radiko-AuthToken: ${authtoken}" \
     --header "X-Radiko-PartialKey: ${partialkey}" \
     -o auth2_fms_${pid} \
     https://radiko.jp/v2/api/auth2

if [ $? -ne 0 -o ! -f auth2_fms_${pid} ]; then
  echo "failed auth2 process"
  exit 1
fi

echo "authentication success"

areaid=`perl -ne 'print $1 if(/^([^,]+),/i)' auth2_fms_${pid}`
echo "areaid: $areaid"

rm -f auth2_fms_${pid}

#
# get stream-url
#

if [ -f ${channel}.xml ]; then
  rm -f ${channel}.xml
fi

curl -s "https://radiko.jp/v2/station/stream_smh_multi/${channel}.xml" -o ${channel}.xml
stream_url=`xmllint --xpath "/urls/url[@areafree='1'][2]/playlist_create_url/text()" ${channel}.xml`
#
echo "stream_url: $stream_url"

rm -f ${channel}.xml

#
# ffmpeg
#
ffmpeg \
  -loglevel error \
  -fflags +discardcorrupt \
  -headers "X-Radiko-Authtoken: ${authtoken}" \
  -i "${stream_url}" \
  -acodec copy \
  -vn \
  -bsf:a aac_adtstoasc \
  -y \
  -t ${DURATION} \
  "/tmp/${channel}_${date}.m4a"

ffmpeg -i "/tmp/${channel}_${date}.m4a" -acodec libmp3lame -ab 128k "${outdir}/${PREFIX}_${date}.mp3"
if [ $? = 0 ]; then
  rm -f "/tmp/${channel}_${date}.m4a"
fi

 



JupyterLabへのJavascript(node.js)kernelの追加について

Friday, December 27th, 2024

JupyterLabでJavascript(node.js)kernelを追加する際、どうもnodejsのversionによってはうまくいかないように思えた。

以下、解決する手続きがわかったような気がするのでメモしておいた。

前提として、Anaconda(version 24.1.2)を使用し、このうえでJupyterLabをインストールしている。
(続きを読む)



Almalinux を更新 ver.9.5

Thursday, December 26th, 2024

先月11月末にAlmalinux 9.5がReleaseされたので、ver. 9.4 から ver. 9.5 に更新しておいた。

今回の更新、major updateでないので、dnf によるupdate で行った。

更新は以下のコマンドで行った:

[root@server02 ~]#  dnf update -y

前回の更新作業同様、systemをrebootしたのちOSの状態を確認:

[root@Server02 ~]# cat /etc/os-release
NAME="AlmaLinux"
VERSION="9.5 (Teal Serval)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.5"
PLATFORM_ID="platform:el9"
PRETTY_NAME="AlmaLinux 9.5 (Teal Serval)"
ANSI_COLOR="0;34"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
ALMALINUX_MANTISBT_PROJECT_VERSION="9.5"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.5"
SUPPORT_END=2032-06-01

なお、前回のupdate作業に引き続いてLinux Kernelのversionを最新版に更新しておいたが、今回の更新作業では今回ReleaseされたAlmaLinux9.5で更新されたものをそのまま維持している。

kernelのversionは以下:

[root@Server02 ~]# uname -sr
Linux 5.14.0-503.16.1.el9_5.x86_64

 



LetsEncrypt SSL 証明書の更新(2024/12/13 実施)

Friday, December 13th, 2024

LetsEccrypt SSl の有効期限が近付いたので更新した。

以下、更新時のLogを掲載:

[root@Server02 ~]# certbot certonly --manual
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): *.yamasnet.com
Renewing an existing certificate for *.yamasnet.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.yamasnet.com.

with the following value:

k2rEXXymL_zXYT8v4yHy5rp7PsuaNHwMA-8hwGsTrs8

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.yamasnet.com.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/yamasnet.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/yamasnet.com/privkey.pem
This certificate expires on 2025-03-13.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

httpdを更新し、証明書を反映:

[root@Server02 ~]# systemctl restart httpd

証明書の確認

[root@Server02 ~]# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: yamasnet.com
    Serial Number: 33ce8d1a61454ca241a3e8b712fbff56475
    Key Type: ECDSA
    Domains: *.yamasnet.com
    Expiry Date: 2025-03-13 04:08:56+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/yamasnet.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/yamasnet.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -