다음과 같이 일부 파일에 환경 변수를 설정했습니다 /etc/profile.d/mercure.sh
.
export MERCURE_PUBLISHER_JWT_KEY=$(cat /home/stephane/mercure/publisher.key.pub)
export MERCURE_PUBLISHER_JWT_ALG=RS256
export MERCURE_SUBSCRIBER_JWT_KEY=$(cat /home/stephane/mercure/subscriber.key.pub)
export MERCURE_PUBLISHER_JWT_ALG=RS256
export SERVER_NAME=localhost:3000
다음 명령을 실행하려면 이 정보가 필요합니다.머큐어 센터):
MERCURE_PUBLISHER_JWT_KEY=$MERCURE_PUBLISHER_JWT_KEY MERCURE_SUBSCRIBER_JWT_KEY=$MERCURE_SUBSCRIBER_JWT_KEY SERVER_NAME=$SERVER_NAME /usr/bin/mercure run
아래 설명과 같이 서비스로 실행할 mercure.service
파일을 생성하고 싶습니다.mercure
여기
[Unit]
Description=Mercure.Rocks service
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=33
[Service]
Type=simple
WorkingDirectory=/tmp
EnvironmentFile=/etc/profile.d/mercure.sh
ExecStart=MERCURE_PUBLISHER_JWT_KEY=$MERCURE_PUBLISHER_JWT_KEY MERCURE_SUBSCRIBER_JWT_KEY=$MERCURE_SUBSCRIBER_JWT_KEY SERVER_NAME=$SERVER_NAME /usr/bin/mercure run --config /home/stephane/mercure/Caddyfile
StandardOutput=file:/var/log/nginx/mercure.log
StandardError=file:/var/log/nginx/mercure.log
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targe
처음에는 다음과 같은 오류가 발생했습니다.
$ sudo systemctl status mercure
● mercure.service - Mercure.Rocks service
Loaded: loaded (/etc/systemd/system/mercure.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2024-01-03 15:26:49 CET; 1s ago
Process: 33752 ExecStart=MERCURE_PUBLISHER_JWT_KEY=$MERCURE_PUBLISHER_JWT_KEY MERCURE_SUBSCRIBER_JWT_KEY=$MERCURE_SUBSCRIBER_JWT_KEY SERVER_NAME=$SERVER_NAME /usr/bin/mercure run --config /home/stephane/mer>
Main PID: 33752 (code=exited, status=203/EXEC)
CPU: 824us
systemd[1]: Stopped Mercure.Rocks service.
systemd[1]: mercure.service: Ignoring invalid environment assignment 'export MERCURE_PUBLISHER_JWT_KEY=$(cat /home/stephane/mercure/publisher.key.pub)': /etc/profile.d/mercure.sh
systemd[1]: mercure.service: Ignoring invalid environment assignment 'export MERCURE_PUBLISHER_JWT_ALG=RS256': /etc/profile.d/mercure.sh
systemd[1]: mercure.service: Ignoring invalid environment assignment 'export MERCURE_SUBSCRIBER_JWT_KEY=$(cat /home/stephane/mercure/subscriber.key.pub)': /etc/profile.d/mercure.sh
systemd[1]: mercure.service: Ignoring invalid environment assignment 'export SERVER_NAME=localhost:3000 #mercure.astro-otter.space': /etc/profile.d/mercure.sh
systemd[1]: Started Mercure.Rocks service.
systemd[1]: mercure.service: Main process exited, code=exited, status=203/EXEC
systemd[1]: mercure.service: Failed with result 'exit-code'.
내 라인에서 환경 변수를 사용하는 방법을 정말로 이해하지 못합니다 ExecStart
. 누군가 설명하거나 예를 보여줄 수 있습니까?
답변1
.NET 파일 없이 더 간단한 환경 파일을 사용해 보세요 export
.
ExecStart /bin/bash -c "...."
다음과 같은 변수를 사용하고 싶다면$MERCURE_PUBLISHER_JWT_KEY
답변2
@frédéric-loyer 및 @AlexP의 답변의 도움으로 환경 변수를 설정 /etc/environment
하고 mercure.service
파일을 편집했습니다.
[Unit]
Description=Mercure.Rocks service
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=33
[Service]
Type=simple
WorkingDirectory=/tmp
EnvironmentFile=-/etc/environment
ExecStart=/usr/bin/bash -c "MERCURE_PUBLISHER_JWT_KEY=$MERCURE_PUBLISHER_JWT_KEY MERCURE_SUBSCRIBER_JWT_KEY=$MERCURE_SUBSCRIBER_JWT_KEY SERVER_NAME=$SERVER_NAME /usr/bin/mercure run --config /var/www/mercure/Cad
dyfile"
StandardOutput=file:/var/log/nginx/mercure.log
StandardError=file:/var/log/nginx/mercure.log
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
괜찮은 것 같습니다:
$ sudo systemctl status mercure
● mercure.service - Mercure.Rocks service
Loaded: loaded (/etc/systemd/system/mercure.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-01-04 10:15:04 CET; 3min 52s ago
Main PID: 57957 (mercure)
Tasks: 6 (limit: 2163)
Memory: 8.8M
CPU: 80ms
CGroup: /system.slice/mercure.service
└─57957 /usr/bin/mercure run --config /var/www/mercure/Caddyfile
Jan 04 10:15:04 vps773218 systemd[1]: Started Mercure.Rocks service.
감사해요.