Wiki » History » Revision 10
« Previous |
Revision 10/12
(diff)
| Next »
keiji ono, 04/14/2026 10:08 AM
REPL起動 jlファイルを開いた状態で Shift+Enter または、"julia"と入れる
REPL終了 exit()を入れる
bashからの実行
jlファイル先頭に 「#!/usr/local/bin/julia」を記述しファイルのchmodをして実行権限を与えてから
./test.jl
python,php風だな
REPLからの実行
include("path to test.jl")
この場合、「#!/usr/....」はいらない
REPLで"pkg"プロントにするには"]"をタイプ。出るには"^C"で。
REPLでjlファイルをコンパイルするには
include("file name")
一度コンパイルに成功するとそれがキャッシュにずっとあるので困る。以前はworkspace()というコマンドがあったみたいだが今は廃止されている。なので、replを再起動するしかないみたい。
2023/4/25現在
repl起動でコンパイルされるが、repl起動後 include(..)で再コンパイルするとサクッと置き換えられるのでreplの再起動は必要ないみたい。
https://sinhrks.hatenablog.com/entry/2015/12/23/003321
- Genieはこっちを見る
https://genieframework.com/docs/?
Genieのroute設定を削除するのはチュートリアルは古いので下記を実行する
julia>routes()
4-element Vector{Genie.Router.Route}:
[POST] /posttest1 => #31 | :post_posttest1
[GET] /test1 => #11 | :get_test1
[GET] /hello => #9 | :get_hello
[GET] / => #7 | :get
julia>Router.delete!(:post_posttest1) ←delete!の引数がチュートリアルと違うから要注意
Genieアプリの起動とストップ¶
起動
>cd (app dir) ex. cd Watchtonight
>bin/repl or julia
>up() ←shプロンプトでbin/serverでもサーバ起動はするが、Watchtonightサンプルの様に設定を読み込んだりする分にはup()でないといけないみたい
ストップ
><ctrl+d> (windows/linux)
><cmd+d> (macos)
Genieで起動するサーバの設定は./config/env/*.jlだが、変更したらイニシャライズが必要なので以下を再実行する必要がある。←down()/up()だけでは反映されない。
serverのhost,portはenv配下を変えても反映されない。
routes.jlの最終行に以下を指定するといいらしい。
up(port,server) ex. up(8000,"0.0.0.0")
別のやり方
https://genieframework.com/docs/genie/tutorials/Loading-Genie-Apps.html
juliaプロンプトでアプリの場所にcd("...")で移動する
pkgプロンプトにして "activate ."を実行する
juliaプロンプトに戻って "using Genie"を実行する
次に "Genie.loadapp()"を実行する
最後に"up()"でサーバが起動する
APIKEYやpassword等は、.config/secrets.jlに書く。ここはgitignoreだから だそうだ。ここに記載されたデータはアプリケーション名でアクセスできるそうだ。 ex. MyGenieApp.pass とかかな?
https://genieframework.com/docs/genie/tutorials/The-Secrets-File.html
- Genie Tips: How to get the serverresponse on Genie
https://stackoverflow.com/questions/68127425/how-to-collect-http-response-status-using-genie-jl-in-julia
julia> using HTTP
julia> response = HTTP.get("http://127.0.0.1:8000/try")
HTTP.Messages.Response:
"""
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: Genie/1.18.1/Julia/1.6.1
Transfer-Encoding: chunked
{"message":"Welcome"}"""
julia> response.status
200
開発環境のもろもろ¶
v3.0リリース時の開発環境のDBアクセス方法
-postgresql
sudo -u postgres psql -d <db name>
ex. Sudo -u postgres psql -d template1
backupで"pg_dump: error: ソケット"/var/run/postgresql/.s.PGSQL.5432"のサーバーへの接続に失敗しました"と出るときはpsqlでやってみよう。
sudo -u postgres pg_dump -d postgres > pgbackup0414.dump
uninstall
install packageの確認
dpkg l | grep postgres*
動いていたら止める
sudo service postgresql stop
ファイルと設定を完全に削除する
sudo apt --purge remove postgresql postgresql
-mysql
mysql -u user -p<password> <db name>
ex. mysql -u user -puserpasswd mysql
-redis
redis-cli
^mongodb
mongosh
PostgreSQL * sudo -u postrges psql
version確認方法
sudo apt info postgresql
またはpsqlで接続後、下記を実行
select version();
現状(2023/11/13)の開発マシンでは
PostgreSQL 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
ubuntu22ではsocketが/var/run/postgres配下に作成される。libPQ.jlからは/tmp配下にあることが期待されているようなので、postgresql.confを変更する必要がある。
/etc/postgresql/14/main/postgresql.conf
- 2022/10/11 changed here from /var/run/postgresql -> /tmp
#unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
unix_socket_directories = '/tmp' # comma-separated list of directories
pg_ivmのインストールのために、postgresの各.hファイルが必要になるが、postgresのソース場所をライブラリリンク設定するのがめんどくさいときは、postgres-serverをインストールすると自動的に入るからいい感じ。
その後、pg_ivmをmakeすればいい
sudo apt install postgresql-server-dev-16
make USE_PGXS=1
sudo make USE_PGXS=1 install
pg_ivmインストール後の設定は下記参照
https://qiita.com/nuko_yokohama/items/0ae59f5d797bc79dcc06
onoke@onoke-OptiPlex-990:~$ su - postgres
パスワード:
postgres@onoke-OptiPlex-990:~$ whoami
postgres
postgres@onoke-OptiPlex-990:~$ which createdb
/usr/bin/createdb
postgres@onoke-OptiPlex-990:~$ createdb ivm
postgres@onoke-OptiPlex-990:~$ psql ivm -c "create extension pg_ivm"
CREATE EXTENSION
postgres@onoke-OptiPlex-990:~$ psql ivm -c "\dx pg_ivm"
インストール済みの拡張一覧
名前 | バージョン | スキーマ | 説明
--------+------------+------------+--------------------------------------------
pg_ivm | 1.7 | pg_catalog | incremental view maintenance on PostgreSQL
mysql
root pw: aterui0
start/stop: sudo systemctl start(stop) mysql
デフォルトではutf8mb4になっていて「補助文字」も扱える
mysql> show variables like "chara%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8mb3 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
killはpid指定で
on Mac¶
postgres/mysql/redisはbrewでstart/stopする。
>brew services start/stop/restart <postgres/mysql/redis/mongodb>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
下記のリストから該当するものを入れる e.g. mysql@8.4
>brew services info --all
ono-macbook-pro:Jetelina onokeiji$ brew services info --all
mongodb-community (homebrew.mxcl.mongodb-community)
Running: ✘
Loaded: ✔
Schedulable: ✘
mysql@8.4 (homebrew.mxcl.mysql@8.4)
Running: ✔
Loaded: ✔
Schedulable: ✘
User: onokeiji
PID: 666
postgresql@14 (homebrew.mxcl.postgresql@14)
Running: ✔
Loaded: ✔
Schedulable: ✘
User: onokeiji
PID: 7285
redis (homebrew.mxcl.redis)
Running: ✘
Loaded: ✘
Schedulable: ✘
各DB起動方法まとめ Ubuntu編¶
sudo systemctl start/stop/status postgresql/mysql/redis/mongod
Updated by keiji ono 3 months ago · 12 revisions