Could not resolve host: content.dropboxapi.com when to upload file at shutdown

Clash Royale CLAN TAG#URR8PPP up vote
3
down vote
favorite
I want to upload a file to my dropbox when my pc is shutting down.
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=network.target shutdown.target reboot.target
Requires=network-online.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
And the upload.sh script.
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
bash upload.sh can executed successfully,and test.txt file uploaded into my dropbox.
sudo systemctl enable upload service
To reboot my pc.
sudo journalctl -u upload
Apr 13 23:58:52 localhost systemd[1]: Started upload files into dropbox.
Apr 13 23:58:52 localhost systemd[1]: Starting upload files into dropbox...
Apr 13 23:58:52 localhost bash[117]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 13 23:58:52 localhost bash[117]: Dload Upload Total Spent Left Speed
Apr 13 23:58:52 localhost bash[117]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: content.dropboxapi.com; Un
Apr 13 23:58:52 localhost systemd[1]: upload.service: main process exited, code=exited, status=6/NOTCONFIGURED
Apr 13 23:58:52 localhost systemd[1]: Unit upload.service entered failed state.
Apr 13 23:58:52 localhost systemd[1]: upload.service failed.
Some DNS error Could not resolve host: content.dropboxapi.com result in upload.service failed.
I have added Requires=network-online.target in upload.service,how to make DNS parser resolve the host at my pc's shutdowning time?
shutdown systemd dropbox
add a comment |Â
up vote
3
down vote
favorite
I want to upload a file to my dropbox when my pc is shutting down.
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=network.target shutdown.target reboot.target
Requires=network-online.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
And the upload.sh script.
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
bash upload.sh can executed successfully,and test.txt file uploaded into my dropbox.
sudo systemctl enable upload service
To reboot my pc.
sudo journalctl -u upload
Apr 13 23:58:52 localhost systemd[1]: Started upload files into dropbox.
Apr 13 23:58:52 localhost systemd[1]: Starting upload files into dropbox...
Apr 13 23:58:52 localhost bash[117]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 13 23:58:52 localhost bash[117]: Dload Upload Total Spent Left Speed
Apr 13 23:58:52 localhost bash[117]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: content.dropboxapi.com; Un
Apr 13 23:58:52 localhost systemd[1]: upload.service: main process exited, code=exited, status=6/NOTCONFIGURED
Apr 13 23:58:52 localhost systemd[1]: Unit upload.service entered failed state.
Apr 13 23:58:52 localhost systemd[1]: upload.service failed.
Some DNS error Could not resolve host: content.dropboxapi.com result in upload.service failed.
I have added Requires=network-online.target in upload.service,how to make DNS parser resolve the host at my pc's shutdowning time?
shutdown systemd dropbox
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I want to upload a file to my dropbox when my pc is shutting down.
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=network.target shutdown.target reboot.target
Requires=network-online.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
And the upload.sh script.
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
bash upload.sh can executed successfully,and test.txt file uploaded into my dropbox.
sudo systemctl enable upload service
To reboot my pc.
sudo journalctl -u upload
Apr 13 23:58:52 localhost systemd[1]: Started upload files into dropbox.
Apr 13 23:58:52 localhost systemd[1]: Starting upload files into dropbox...
Apr 13 23:58:52 localhost bash[117]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 13 23:58:52 localhost bash[117]: Dload Upload Total Spent Left Speed
Apr 13 23:58:52 localhost bash[117]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: content.dropboxapi.com; Un
Apr 13 23:58:52 localhost systemd[1]: upload.service: main process exited, code=exited, status=6/NOTCONFIGURED
Apr 13 23:58:52 localhost systemd[1]: Unit upload.service entered failed state.
Apr 13 23:58:52 localhost systemd[1]: upload.service failed.
Some DNS error Could not resolve host: content.dropboxapi.com result in upload.service failed.
I have added Requires=network-online.target in upload.service,how to make DNS parser resolve the host at my pc's shutdowning time?
shutdown systemd dropbox
I want to upload a file to my dropbox when my pc is shutting down.
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=network.target shutdown.target reboot.target
Requires=network-online.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
And the upload.sh script.
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
bash upload.sh can executed successfully,and test.txt file uploaded into my dropbox.
sudo systemctl enable upload service
To reboot my pc.
sudo journalctl -u upload
Apr 13 23:58:52 localhost systemd[1]: Started upload files into dropbox.
Apr 13 23:58:52 localhost systemd[1]: Starting upload files into dropbox...
Apr 13 23:58:52 localhost bash[117]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 13 23:58:52 localhost bash[117]: Dload Upload Total Spent Left Speed
Apr 13 23:58:52 localhost bash[117]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: content.dropboxapi.com; Un
Apr 13 23:58:52 localhost systemd[1]: upload.service: main process exited, code=exited, status=6/NOTCONFIGURED
Apr 13 23:58:52 localhost systemd[1]: Unit upload.service entered failed state.
Apr 13 23:58:52 localhost systemd[1]: upload.service failed.
Some DNS error Could not resolve host: content.dropboxapi.com result in upload.service failed.
I have added Requires=network-online.target in upload.service,how to make DNS parser resolve the host at my pc's shutdowning time?
shutdown systemd dropbox
shutdown systemd dropbox
edited Apr 20 at 11:59
goedt
527
527
asked Apr 14 at 7:08
it_is_a_literature
50425
50425
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
method 1: /etc/systemd/system/upload.service
1.1 /etc/systemd/system/upload.service
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
1.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
1.3 sudo systemctl enable upload service
method 2: /lib/systemd/system-shutdown/upload.service
2.1 /lib/systemd/system-shutdown/upload.service
sudo vim /lib/systemd/system-shutdown/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
2.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
2.3 sudo systemctl enable /lib/systemd/system-shutdown/upload.service
add a comment |Â
up vote
0
down vote
The best way to run a program or script while the system is going down is by using the ExecStop= of the unit to run such program. The ExecStart= can either be a dummy script (such as /bin/true) or, in recent versions of systemd, it can even be omitted.
Regarding dependencies, you want to place your unit after the services you need, such as network-online.target and perhaps systemd-resolved.service if you're using it for DNS resolution. The reason for that is that systems are stopped at shutdown time in the reverse order in which they are started. So by ordering your service after the dependencies, it means your ExecStop= script will be run before the dependencies are stopped.
Something like this should work:
[Unit]
Description=upload files into dropbox
After=network.target systemd-resolved.service
Requires=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Enable the unit as usual (the --now argument also starts it):
$ sudo systemctl enable --now upload.service
And it will perform the upload when stopped, which you can test with:
$ sudo systemctl stop upload.service
This was recently discussed in the systemd-devel mailing list.
add a comment |Â
up vote
0
down vote
Execstop and Execstart reversed
According to this Unix & Linux answer: How to run a script with systemd right before shutdown, your Execstop and Execstart are reversed.
The lines:
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
Should read:
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
The answer goes on to mention to restart services. So after creating the file, make sure to systemctl daemon-reload and systemctl enable yourservice --now
Alternate method not working
The before=, requires=, etc. can be confusing at times. You can put your script in /usr/lib/systemd/system-shutdown/ directory instead. It will be run immediately upon shutdown. See: https://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemd
The /usr prefix may be different on some systems, ie just start directory name with /lib.
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
@it_is_a_literature I revised the answer and addedsystemdmethod based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to havestartandstopreversed??
â WinEunuuchs2Unix
Apr 22 at 18:34
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
method 1: /etc/systemd/system/upload.service
1.1 /etc/systemd/system/upload.service
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
1.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
1.3 sudo systemctl enable upload service
method 2: /lib/systemd/system-shutdown/upload.service
2.1 /lib/systemd/system-shutdown/upload.service
sudo vim /lib/systemd/system-shutdown/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
2.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
2.3 sudo systemctl enable /lib/systemd/system-shutdown/upload.service
add a comment |Â
up vote
1
down vote
accepted
method 1: /etc/systemd/system/upload.service
1.1 /etc/systemd/system/upload.service
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
1.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
1.3 sudo systemctl enable upload service
method 2: /lib/systemd/system-shutdown/upload.service
2.1 /lib/systemd/system-shutdown/upload.service
sudo vim /lib/systemd/system-shutdown/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
2.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
2.3 sudo systemctl enable /lib/systemd/system-shutdown/upload.service
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
method 1: /etc/systemd/system/upload.service
1.1 /etc/systemd/system/upload.service
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
1.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
1.3 sudo systemctl enable upload service
method 2: /lib/systemd/system-shutdown/upload.service
2.1 /lib/systemd/system-shutdown/upload.service
sudo vim /lib/systemd/system-shutdown/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
2.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
2.3 sudo systemctl enable /lib/systemd/system-shutdown/upload.service
method 1: /etc/systemd/system/upload.service
1.1 /etc/systemd/system/upload.service
sudo vim /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
1.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
1.3 sudo systemctl enable upload service
method 2: /lib/systemd/system-shutdown/upload.service
2.1 /lib/systemd/system-shutdown/upload.service
sudo vim /lib/systemd/system-shutdown/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
2.2 vim /home/upload.sh
cd /home
curl -X POST https://content.dropboxapi.com/2/files/upload
--header "Authorization: Bearer xxxx"
--header "Dropbox-API-Arg: "path":"/test.txt","mode":".tag":"overwrite""
--header "Content-Type: application/octet-stream"
--data-binary @"test.txt"
2.3 sudo systemctl enable /lib/systemd/system-shutdown/upload.service
edited Apr 20 at 10:01
answered Apr 17 at 0:59
scrapy
2835
2835
add a comment |Â
add a comment |Â
up vote
0
down vote
The best way to run a program or script while the system is going down is by using the ExecStop= of the unit to run such program. The ExecStart= can either be a dummy script (such as /bin/true) or, in recent versions of systemd, it can even be omitted.
Regarding dependencies, you want to place your unit after the services you need, such as network-online.target and perhaps systemd-resolved.service if you're using it for DNS resolution. The reason for that is that systems are stopped at shutdown time in the reverse order in which they are started. So by ordering your service after the dependencies, it means your ExecStop= script will be run before the dependencies are stopped.
Something like this should work:
[Unit]
Description=upload files into dropbox
After=network.target systemd-resolved.service
Requires=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Enable the unit as usual (the --now argument also starts it):
$ sudo systemctl enable --now upload.service
And it will perform the upload when stopped, which you can test with:
$ sudo systemctl stop upload.service
This was recently discussed in the systemd-devel mailing list.
add a comment |Â
up vote
0
down vote
The best way to run a program or script while the system is going down is by using the ExecStop= of the unit to run such program. The ExecStart= can either be a dummy script (such as /bin/true) or, in recent versions of systemd, it can even be omitted.
Regarding dependencies, you want to place your unit after the services you need, such as network-online.target and perhaps systemd-resolved.service if you're using it for DNS resolution. The reason for that is that systems are stopped at shutdown time in the reverse order in which they are started. So by ordering your service after the dependencies, it means your ExecStop= script will be run before the dependencies are stopped.
Something like this should work:
[Unit]
Description=upload files into dropbox
After=network.target systemd-resolved.service
Requires=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Enable the unit as usual (the --now argument also starts it):
$ sudo systemctl enable --now upload.service
And it will perform the upload when stopped, which you can test with:
$ sudo systemctl stop upload.service
This was recently discussed in the systemd-devel mailing list.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The best way to run a program or script while the system is going down is by using the ExecStop= of the unit to run such program. The ExecStart= can either be a dummy script (such as /bin/true) or, in recent versions of systemd, it can even be omitted.
Regarding dependencies, you want to place your unit after the services you need, such as network-online.target and perhaps systemd-resolved.service if you're using it for DNS resolution. The reason for that is that systems are stopped at shutdown time in the reverse order in which they are started. So by ordering your service after the dependencies, it means your ExecStop= script will be run before the dependencies are stopped.
Something like this should work:
[Unit]
Description=upload files into dropbox
After=network.target systemd-resolved.service
Requires=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Enable the unit as usual (the --now argument also starts it):
$ sudo systemctl enable --now upload.service
And it will perform the upload when stopped, which you can test with:
$ sudo systemctl stop upload.service
This was recently discussed in the systemd-devel mailing list.
The best way to run a program or script while the system is going down is by using the ExecStop= of the unit to run such program. The ExecStart= can either be a dummy script (such as /bin/true) or, in recent versions of systemd, it can even be omitted.
Regarding dependencies, you want to place your unit after the services you need, such as network-online.target and perhaps systemd-resolved.service if you're using it for DNS resolution. The reason for that is that systems are stopped at shutdown time in the reverse order in which they are started. So by ordering your service after the dependencies, it means your ExecStop= script will be run before the dependencies are stopped.
Something like this should work:
[Unit]
Description=upload files into dropbox
After=network.target systemd-resolved.service
Requires=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Enable the unit as usual (the --now argument also starts it):
$ sudo systemctl enable --now upload.service
And it will perform the upload when stopped, which you can test with:
$ sudo systemctl stop upload.service
This was recently discussed in the systemd-devel mailing list.
answered Apr 17 at 5:57
Filipe Brandenburger
5867
5867
add a comment |Â
add a comment |Â
up vote
0
down vote
Execstop and Execstart reversed
According to this Unix & Linux answer: How to run a script with systemd right before shutdown, your Execstop and Execstart are reversed.
The lines:
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
Should read:
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
The answer goes on to mention to restart services. So after creating the file, make sure to systemctl daemon-reload and systemctl enable yourservice --now
Alternate method not working
The before=, requires=, etc. can be confusing at times. You can put your script in /usr/lib/systemd/system-shutdown/ directory instead. It will be run immediately upon shutdown. See: https://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemd
The /usr prefix may be different on some systems, ie just start directory name with /lib.
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
@it_is_a_literature I revised the answer and addedsystemdmethod based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to havestartandstopreversed??
â WinEunuuchs2Unix
Apr 22 at 18:34
add a comment |Â
up vote
0
down vote
Execstop and Execstart reversed
According to this Unix & Linux answer: How to run a script with systemd right before shutdown, your Execstop and Execstart are reversed.
The lines:
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
Should read:
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
The answer goes on to mention to restart services. So after creating the file, make sure to systemctl daemon-reload and systemctl enable yourservice --now
Alternate method not working
The before=, requires=, etc. can be confusing at times. You can put your script in /usr/lib/systemd/system-shutdown/ directory instead. It will be run immediately upon shutdown. See: https://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemd
The /usr prefix may be different on some systems, ie just start directory name with /lib.
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
@it_is_a_literature I revised the answer and addedsystemdmethod based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to havestartandstopreversed??
â WinEunuuchs2Unix
Apr 22 at 18:34
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Execstop and Execstart reversed
According to this Unix & Linux answer: How to run a script with systemd right before shutdown, your Execstop and Execstart are reversed.
The lines:
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
Should read:
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
The answer goes on to mention to restart services. So after creating the file, make sure to systemctl daemon-reload and systemctl enable yourservice --now
Alternate method not working
The before=, requires=, etc. can be confusing at times. You can put your script in /usr/lib/systemd/system-shutdown/ directory instead. It will be run immediately upon shutdown. See: https://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemd
The /usr prefix may be different on some systems, ie just start directory name with /lib.
Execstop and Execstart reversed
According to this Unix & Linux answer: How to run a script with systemd right before shutdown, your Execstop and Execstart are reversed.
The lines:
ExecStop=/bin/true
ExecStart=/bin/bash /home/upload.sh
Should read:
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
The answer goes on to mention to restart services. So after creating the file, make sure to systemctl daemon-reload and systemctl enable yourservice --now
Alternate method not working
The before=, requires=, etc. can be confusing at times. You can put your script in /usr/lib/systemd/system-shutdown/ directory instead. It will be run immediately upon shutdown. See: https://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemd
The /usr prefix may be different on some systems, ie just start directory name with /lib.
edited Apr 17 at 10:23
answered Apr 16 at 11:38
WinEunuuchs2Unix
35.8k759133
35.8k759133
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
@it_is_a_literature I revised the answer and addedsystemdmethod based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to havestartandstopreversed??
â WinEunuuchs2Unix
Apr 22 at 18:34
add a comment |Â
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
@it_is_a_literature I revised the answer and addedsystemdmethod based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to havestartandstopreversed??
â WinEunuuchs2Unix
Apr 22 at 18:34
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
Please try in your pc,the same error as before.
â it_is_a_literature
Apr 17 at 0:36
@it_is_a_literature I revised the answer and added
systemd method based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to have start and stop reversed??â WinEunuuchs2Unix
Apr 22 at 18:34
@it_is_a_literature I revised the answer and added
systemd method based on your question. The old answer was deprecated to "Alternate" section. Note the answer you accepted appears to have start and stop reversed??â WinEunuuchs2Unix
Apr 22 at 18:34
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1024886%2fcould-not-resolve-host-content-dropboxapi-com-when-to-upload-file-at-shutdown%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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