Make HTTP call on system shutdown using systemd [CentOS 7]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I need to make a service/script that make a HTTP/POST call on system shutdown to informs a distant server that the system is going to stop.



I've tried to watch the runlevel but it looks like it is not working anymore on CentOS 7 as the runlevel is set to 3 all the time.



I've tried to make a service based on this post, I ended up with the following file :




my_service.service




[Unit]
Description=Service to execute on shutdown
After=network.target network-online.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/etc/path_to_my_script
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target


I've put the follwing line at the beggining of my script:
touch /etc/test_shutdown but the file is never created.
Do you have any idea about how to make this works ?
Thanks for your answers.







share|improve this question



















  • for a local filesystem test (or to otherwise ensure that the script can actually be loaded and run from the filesystem) you probably want to copy the freedesktop.org/software/systemd/man/systemd.mount.html dependencies so the appropriate filesystems are there
    – thrig
    May 29 at 17:16










  • I’m not sure if it will work, but try changing the WantedBy= to shutdown.target.
    – Lucas Werkmeister
    Jun 1 at 12:39














up vote
0
down vote

favorite












I need to make a service/script that make a HTTP/POST call on system shutdown to informs a distant server that the system is going to stop.



I've tried to watch the runlevel but it looks like it is not working anymore on CentOS 7 as the runlevel is set to 3 all the time.



I've tried to make a service based on this post, I ended up with the following file :




my_service.service




[Unit]
Description=Service to execute on shutdown
After=network.target network-online.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/etc/path_to_my_script
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target


I've put the follwing line at the beggining of my script:
touch /etc/test_shutdown but the file is never created.
Do you have any idea about how to make this works ?
Thanks for your answers.







share|improve this question



















  • for a local filesystem test (or to otherwise ensure that the script can actually be loaded and run from the filesystem) you probably want to copy the freedesktop.org/software/systemd/man/systemd.mount.html dependencies so the appropriate filesystems are there
    – thrig
    May 29 at 17:16










  • I’m not sure if it will work, but try changing the WantedBy= to shutdown.target.
    – Lucas Werkmeister
    Jun 1 at 12:39












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to make a service/script that make a HTTP/POST call on system shutdown to informs a distant server that the system is going to stop.



I've tried to watch the runlevel but it looks like it is not working anymore on CentOS 7 as the runlevel is set to 3 all the time.



I've tried to make a service based on this post, I ended up with the following file :




my_service.service




[Unit]
Description=Service to execute on shutdown
After=network.target network-online.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/etc/path_to_my_script
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target


I've put the follwing line at the beggining of my script:
touch /etc/test_shutdown but the file is never created.
Do you have any idea about how to make this works ?
Thanks for your answers.







share|improve this question











I need to make a service/script that make a HTTP/POST call on system shutdown to informs a distant server that the system is going to stop.



I've tried to watch the runlevel but it looks like it is not working anymore on CentOS 7 as the runlevel is set to 3 all the time.



I've tried to make a service based on this post, I ended up with the following file :




my_service.service




[Unit]
Description=Service to execute on shutdown
After=network.target network-online.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/etc/path_to_my_script
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target


I've put the follwing line at the beggining of my script:
touch /etc/test_shutdown but the file is never created.
Do you have any idea about how to make this works ?
Thanks for your answers.









share|improve this question










share|improve this question




share|improve this question









asked May 29 at 16:00









PopoLeDozo

1




1











  • for a local filesystem test (or to otherwise ensure that the script can actually be loaded and run from the filesystem) you probably want to copy the freedesktop.org/software/systemd/man/systemd.mount.html dependencies so the appropriate filesystems are there
    – thrig
    May 29 at 17:16










  • I’m not sure if it will work, but try changing the WantedBy= to shutdown.target.
    – Lucas Werkmeister
    Jun 1 at 12:39
















  • for a local filesystem test (or to otherwise ensure that the script can actually be loaded and run from the filesystem) you probably want to copy the freedesktop.org/software/systemd/man/systemd.mount.html dependencies so the appropriate filesystems are there
    – thrig
    May 29 at 17:16










  • I’m not sure if it will work, but try changing the WantedBy= to shutdown.target.
    – Lucas Werkmeister
    Jun 1 at 12:39















for a local filesystem test (or to otherwise ensure that the script can actually be loaded and run from the filesystem) you probably want to copy the freedesktop.org/software/systemd/man/systemd.mount.html dependencies so the appropriate filesystems are there
– thrig
May 29 at 17:16




for a local filesystem test (or to otherwise ensure that the script can actually be loaded and run from the filesystem) you probably want to copy the freedesktop.org/software/systemd/man/systemd.mount.html dependencies so the appropriate filesystems are there
– thrig
May 29 at 17:16












I’m not sure if it will work, but try changing the WantedBy= to shutdown.target.
– Lucas Werkmeister
Jun 1 at 12:39




I’m not sure if it will work, but try changing the WantedBy= to shutdown.target.
– Lucas Werkmeister
Jun 1 at 12:39















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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446734%2fmake-http-call-on-system-shutdown-using-systemd-centos-7%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446734%2fmake-http-call-on-system-shutdown-using-systemd-centos-7%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?