![Systemd 서비스는 시작 시 네트워크에서 데이터를 가져오는 데 사용됩니다.](https://linux55.com/image/144840/Systemd%20%EC%84%9C%EB%B9%84%EC%8A%A4%EB%8A%94%20%EC%8B%9C%EC%9E%91%20%EC%8B%9C%20%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC%EC%97%90%EC%84%9C%20%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%A5%BC%20%EA%B0%80%EC%A0%B8%EC%98%A4%EB%8A%94%20%EB%8D%B0%20%EC%82%AC%EC%9A%A9%EB%90%A9%EB%8B%88%EB%8B%A4..png)
/usr/share/wallpapers
랩톱을 다시 시작할 때마다 unsplash에서 임의의 사진을 얻고 싶습니다 .
이 서비스를 작성하려는 첫 번째 시도는 다음과 같습니다.
[Unit]
Description=Fetch random picture from unsplash
After=network-online.target
[Service]
User=root
Type=idle
ExecStart=/home/nicolas/.local/bin/fetch_unsplash_1920x1080
[Install]
WantedBy=network-online.target
활성화하고 재부팅했는데 다음과 같은 이유로 실패했습니다.
déc. 19 13:21:24 localhost.localdomain systemd[1]: Started Fetch random picture from unsplash.
déc. 19 13:21:24 localhost.localdomain systemd[1728]: fetch_unsplash.service: Failed to execute command: Permission denied
déc. 19 13:21:24 localhost.localdomain systemd[1728]: fetch_unsplash.service: Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
déc. 19 13:21:24 localhost.localdomain systemd[1]: fetch_unsplash.service: Main process exited, code=exited, status=203/EXEC
déc. 19 13:21:24 localhost.localdomain systemd[1]: fetch_unsplash.service: Failed with result 'exit-code'.
~
스크립트 경로가 정확하고 실행 권한이 있습니다.
코드(및 향후 개선을 위한 기반)는 다음과 같습니다.
#!/usr/bin/bash
location="$1"
if [ -z "$location" ]
then
location="/usr/share/wallpapers"
fi
name="random_unsplash_1920x1080.jpg"
wget -q "https://picsum.photos/1920/1080/?random" --output-document "$location/$name"
그렇다면 작동하지 않는 것은 무엇입니까?
이는 또한 두 가지 질문을 불러일으킵니다. 서비스에 쓰기 권한을 어떻게 부여합니까 /usr/share/wallpapers
? 노트북이 실제로 인터넷에 연결되어 있을 때만 서비스를 시작하려면 어떻게 해야 하나요?(이렇게 하는 것이 맞나요?)