You are not logged in.
Pages: 1
Hi,
Been using Arch for just over a week now moving from Ubuntu and loving it. Achieved so much more on Arch in this short time until this evening.
I am trying to run a shell script at startup. I added the service file under /etc/systemd/system/myapp.service
With the following content:
[Unit]
Description=Notification
[Service]
ExecStart=/usr/bin/myscript
[Install]
WantedBy=multi-user.target
As it is I can run "systemctl restart myapp.service" and the script execute flawlessly however on reboot it does nothing and I get this error when I run systemctl status myapp.service:
systemctl status myapp.service
myapp.service - Notification
Loaded: loaded (/etc/systemd/system/myapp.service; enabled)
Active: failed (Result: exit-code) since Thu 1970-01-01 10:00:08 EST; 14s ago
Process: 116 ExecStart=/usr/bin/myscript (code=exited, status=6)
Other info:
Script starts with #!/bin/sh
Script permissions 755
Tried adding After=network.target under unit.
Tried Type=oneshot and forking
O yes /var/log/messages.log | grep myapp
Sep 6 14:25:56 alarm systemd[1]: [/etc/systemd/system/myapp.service:1] Unknown section 'unit'. Ignoring.
Sep 6 14:25:56 alarm systemd[1]: [/etc/systemd/system/myapp.service:2] Assignment outside of section. Ignoring.
Jan 1 01:00:11 alarm systemd[1]: myapp.service: main process exited, code=exited, status=6/NOTCONFIGURED
Jan 1 01:00:11 alarm systemd[1]: Unit myapp.service entered failed state.
Jan 1 01:00:11 alarm [ 3.243318] systemd[1]: [/etc/systemd/system/myapp.service:1] Unknown section 'unit'. Ignoring.
Jan 1 01:00:11 alarm [ 3.243490] systemd[1]: [/etc/systemd/system/myapp.service:2] Assignment outside of section. Ignoring.
Only thing I dont get is the date difference? I have set the timezone correctly..
Any suggestions?
thanks
Last edited by blueteq (2013-09-10 10:01:11)
Offline
I think that unless you give more info on what the script actually does, it is pretty hard to tell you why this does or doesn't work. It doesn't do any good to tell use that you tried forking and oneshot and simple if we have no idea what the nature of your script is.
Also, you need to use code tags for things like code and code output. See the BBCode link on the bottom of the page for help, and then please go back and fix your post.
Offline
Thanks for the reply, it was 1:30 am... not thinking straight.
The script is a push notification service to tell me the system have restarted.
This is the content
#!/bin/sh
curl -s \
-F "token=abc123" \
-F "user=user123" \
-F "message=hello world" \
https://api.pushover.net/1/messages.json
As mentioned thought I needed to wait for the network, but I have another script starting on the same run level connecting to a google api which works.
Could it be curl timing out?
Offline
Hmmm.... Your problem stems from a misunderstanding on how systemd works: It starts all services in parallel unless otherwise stated. In this case your script requires that network services be up and ready. Add:
After=network.targetto the [Unit] section of your service file. Your script should work ṕroperly then.
Last edited by vorbote (2013-09-08 01:30:22)
I break things and put them back together for fun and sometimes profit, because it is the only way to learn.
Offline
systemctl status myapp.service
myapp.service - Notification
Loaded: loaded (/etc/systemd/system/myapp.service; enabled)
Active: failed (Result: exit-code) since Thu 1970-01-01 10:00:08 EST; 14s ago
Process: 116 ExecStart=/usr/bin/myscript (code=exited, status=6)Note the exit code "status" provided.
EXIT CODES
...
6 Couldn't resolve host. The given remote host was not resolved.
How do you connect to the internet, and what is your network.target?
Last edited by Trilby (2013-09-08 02:14:45)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks both vorbote and Trilby for the replies.
I have tried network.target with no success, as Trilby points out to the Exit codes in the man file it makes sense the service works when system is completely booted.
Machine is directly connected via standard ADSL modem, no proxy.
Trilby when you ask, what is my network.target, what do you mean? What is the run level?
Offline
No, just what is it that this service is "After="? You can specify network.target, but an actual active connection and the network target can be disassociated (systemd can "think" network.target has been reached, but the connection is not yet active). So really I was curious how you connected.
If you are connected directly via a model, do you use dhcpcd.service?
If so, this is likely the issue. I believe dhcpcd services show as reaching "network.target" while the connection is still being made. You may have luck looking for service files for tools like offline-imap as they also need an active network connection.
As a first step, I'd add network.target to the Requires field as well as the After field.
Last edited by Trilby (2013-09-08 04:40:49)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
@trilby,
I have another service also running at boot, chromium connecting to a Google API and that works ok, unless it has a refresh built in to retry.
Reading through the curl exit codes now, I added a timeout on the curl command and the error code has changed to 02.
Process: 248 ExecStart=/usr/bin/pushover (code=exited, status=2)
Offline
The --retry-delay added to the curl command now returns exit code 60, with result: certificate is not yet valid.
Does this mean that there is another service like open-ssl that needs to start?
__UPDATE__
For some reason the CA Certs stopped working when I updated CURL. So added the -k option to override the failure. (not good but will fix on new install)
Last edited by blueteq (2013-09-08 07:13:05)
Offline
Think I have fixed it, well would like to know what I have done is the correct way of doing it.
This is the working push.service file:
[unit]
Description=Push Notification on Power Failure
[Service]
Type=forking
ExecStart=/usr/bin/pushover
RestartSec=35
Restart=on-failure
[Install]
WantedBy=multi-user.target
Adding the RestartSec=35 and Restart on Failure did the trick, as even with After=network.target it still would not work.
Is my assumption correct the script is executed prematurely and therefore failed, by adding the Restart after 35 Seconds it ensured that all dependancies started?
How would I check what these are, so I can rather make it work with After=? Or is this OK?
Offline
Reaching the network.target does not necessarily mean that an active connection has been reached. For example, if you use wicd or netctl-auto, it will report the stating of the service as successful after the daemon itself has started, but starting the daemon simply means that it is ready to start scanning for wireless networks and then connect.
If you want to be absolutely sure that there is a network connection before the service starts, you should use NetworkManager.service. That will also pull in the NetworkManager-wait-online.service which will not complete until a full connection has been reached. At that point the startup will have reached the network-online.target. So you should order the service after that instead. In reality, you should order it after that anyway, no matter what netowrk connection service you use, as that is a built in target to systemd.
Even though you have the RestartSec=35 and Restart=on-failure (which is a sane thing to do IMO), it is probably a good idea to order it After=netowrk-online.target anyway, as that will cause the service to start a bit later and at least attempt to order itself correctly. That way it will also ensure that the service is stopped before the network is taken down as well, hopefully ensuring a clean disconnect as well.
Offline
2 things. First, I am glad that you have found a solution of some sort but I do think it rather rude to ignore the request to edit your posts to use code tags. See https://wiki.archlinux.org/index.php/Fo … s_and_Code. Also, note that there is an "EDIT" button so you can add further information to a post rather than repeatedly bumping your own thread.
Second, there is something screwy with your system clock and that is why you are getting the certificate "not yet valid" error - at that point, the system believes it is so far in the past that the certificate it is offered is not yet valid. You should fix this unless you are using something like a RaspberryPi which doesn't have a system clock in the relevant sense - I don't know what the solution is in that case.
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
... unless you are using something like a RaspberryPi which doesn't have a system clock in the relevant sense - I don't know what the solution is in that case.
I imagine an ntpd service (or the relevant equivalent) could be added under After= and Requires= to ensure the clock is set before this is run.
This would, if fact, have the convenient side effect that an active connection would have to be established. Network->NTPD sync->curl push thingy.
Last edited by Trilby (2013-09-09 01:16:02)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for detailed explanation WonderWoofy, and Trilby it is a Raspberry Pi, and I did disable to NTPD service to test something. After enabling it again certs started working again, also learned the Pi don't have a RTC...
crf, apologies for the tardy posts, as I said it was late and I was and at the end of my rope.
Only reason I used EDIT was to say I have fixed the issue and how I did it. Not to bump my post.
All and all my project is a huge success, thanks to the help I found here
Thanks
Offline
Pages: 1