Systemd service for fetching data from the web at startup
I would like to fetch a random picture from unsplash in /usr/share/wallpapers
each time I reboot my laptop.
I wrote this service as a first try:
[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
I enabled it, reboot and I see it fails because:
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'.
~
The path for the script is correct and the script has execution permission.
Here is code (it's also a base for future improvements):
#!/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"
So what does not work?
Also this raises two problems for me: how to give permission to the service for writing in /usr/share/wallpapers
? And how to get the service start only when the laptop is truly connected to internet (am I doing it right in this service)?
permissions systemd systemd-networkd
add a comment |
I would like to fetch a random picture from unsplash in /usr/share/wallpapers
each time I reboot my laptop.
I wrote this service as a first try:
[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
I enabled it, reboot and I see it fails because:
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'.
~
The path for the script is correct and the script has execution permission.
Here is code (it's also a base for future improvements):
#!/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"
So what does not work?
Also this raises two problems for me: how to give permission to the service for writing in /usr/share/wallpapers
? And how to get the service start only when the laptop is truly connected to internet (am I doing it right in this service)?
permissions systemd systemd-networkd
Can you show the permissions for that script, because systemd disagrees with you:Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
. Also, is your /home filesystem mounted with thenoexec
flag? Check the filesystem you're on withdf /home/nicolas/.local/bin/fetch_unsplash_1920x1080
followed bymount | grep ... that filesystem
– Jeff Schaller
Dec 19 '18 at 17:37
The script has the permission-rwxr-xr-x
, the filesystem where the script is located is not mounted withnoexec
. Also the location where the script is trying to write is not on the same partition and it has the same mount options.
– Nicolas Scotto Di Perto
Dec 20 '18 at 17:38
My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given theAfter=network-online.target
, but thought I'd mention it, just in case.
– Jeff Schaller
Dec 20 '18 at 17:45
add a comment |
I would like to fetch a random picture from unsplash in /usr/share/wallpapers
each time I reboot my laptop.
I wrote this service as a first try:
[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
I enabled it, reboot and I see it fails because:
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'.
~
The path for the script is correct and the script has execution permission.
Here is code (it's also a base for future improvements):
#!/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"
So what does not work?
Also this raises two problems for me: how to give permission to the service for writing in /usr/share/wallpapers
? And how to get the service start only when the laptop is truly connected to internet (am I doing it right in this service)?
permissions systemd systemd-networkd
I would like to fetch a random picture from unsplash in /usr/share/wallpapers
each time I reboot my laptop.
I wrote this service as a first try:
[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
I enabled it, reboot and I see it fails because:
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'.
~
The path for the script is correct and the script has execution permission.
Here is code (it's also a base for future improvements):
#!/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"
So what does not work?
Also this raises two problems for me: how to give permission to the service for writing in /usr/share/wallpapers
? And how to get the service start only when the laptop is truly connected to internet (am I doing it right in this service)?
permissions systemd systemd-networkd
permissions systemd systemd-networkd
edited Dec 19 '18 at 15:22
SouravGhosh
493311
493311
asked Dec 19 '18 at 12:44
Nicolas Scotto Di Perto
236211
236211
Can you show the permissions for that script, because systemd disagrees with you:Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
. Also, is your /home filesystem mounted with thenoexec
flag? Check the filesystem you're on withdf /home/nicolas/.local/bin/fetch_unsplash_1920x1080
followed bymount | grep ... that filesystem
– Jeff Schaller
Dec 19 '18 at 17:37
The script has the permission-rwxr-xr-x
, the filesystem where the script is located is not mounted withnoexec
. Also the location where the script is trying to write is not on the same partition and it has the same mount options.
– Nicolas Scotto Di Perto
Dec 20 '18 at 17:38
My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given theAfter=network-online.target
, but thought I'd mention it, just in case.
– Jeff Schaller
Dec 20 '18 at 17:45
add a comment |
Can you show the permissions for that script, because systemd disagrees with you:Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
. Also, is your /home filesystem mounted with thenoexec
flag? Check the filesystem you're on withdf /home/nicolas/.local/bin/fetch_unsplash_1920x1080
followed bymount | grep ... that filesystem
– Jeff Schaller
Dec 19 '18 at 17:37
The script has the permission-rwxr-xr-x
, the filesystem where the script is located is not mounted withnoexec
. Also the location where the script is trying to write is not on the same partition and it has the same mount options.
– Nicolas Scotto Di Perto
Dec 20 '18 at 17:38
My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given theAfter=network-online.target
, but thought I'd mention it, just in case.
– Jeff Schaller
Dec 20 '18 at 17:45
Can you show the permissions for that script, because systemd disagrees with you:
Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
. Also, is your /home filesystem mounted with the noexec
flag? Check the filesystem you're on with df /home/nicolas/.local/bin/fetch_unsplash_1920x1080
followed by mount | grep ... that filesystem
– Jeff Schaller
Dec 19 '18 at 17:37
Can you show the permissions for that script, because systemd disagrees with you:
Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
. Also, is your /home filesystem mounted with the noexec
flag? Check the filesystem you're on with df /home/nicolas/.local/bin/fetch_unsplash_1920x1080
followed by mount | grep ... that filesystem
– Jeff Schaller
Dec 19 '18 at 17:37
The script has the permission
-rwxr-xr-x
, the filesystem where the script is located is not mounted with noexec
. Also the location where the script is trying to write is not on the same partition and it has the same mount options.– Nicolas Scotto Di Perto
Dec 20 '18 at 17:38
The script has the permission
-rwxr-xr-x
, the filesystem where the script is located is not mounted with noexec
. Also the location where the script is trying to write is not on the same partition and it has the same mount options.– Nicolas Scotto Di Perto
Dec 20 '18 at 17:38
My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given the
After=network-online.target
, but thought I'd mention it, just in case.– Jeff Schaller
Dec 20 '18 at 17:45
My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given the
After=network-online.target
, but thought I'd mention it, just in case.– Jeff Schaller
Dec 20 '18 at 17:45
add a comment |
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489902%2fsystemd-service-for-fetching-data-from-the-web-at-startup%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489902%2fsystemd-service-for-fetching-data-from-the-web-at-startup%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you show the permissions for that script, because systemd disagrees with you:
Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied
. Also, is your /home filesystem mounted with thenoexec
flag? Check the filesystem you're on withdf /home/nicolas/.local/bin/fetch_unsplash_1920x1080
followed bymount | grep ... that filesystem
– Jeff Schaller
Dec 19 '18 at 17:37
The script has the permission
-rwxr-xr-x
, the filesystem where the script is located is not mounted withnoexec
. Also the location where the script is trying to write is not on the same partition and it has the same mount options.– Nicolas Scotto Di Perto
Dec 20 '18 at 17:38
My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given the
After=network-online.target
, but thought I'd mention it, just in case.– Jeff Schaller
Dec 20 '18 at 17:45