Please help create systemd unit
Hello!
I'm using Ubuntu 18.04.4 LTS
I want to create systemd unit which will run script on disk mount.
Here is what I'm trying to do:
- I've created a script:
!/bin/bash
/usr/bin/yandex-disk-indicator
and made it executible. It works fine when I run it through terminal. It starts and runs till I close term.
I named it yaIndStart and placed it to /usr/local/bin
2. I've created systemd service named yaIndStart.service and placed it into /etc/systemd/system
3. Enabled service: sudo systemctl enable yaIndStart.service
4. Started service: sudo systemctl start yaIndStart.service but there is an error: "Job for yaIndStart.service failed because the control process exited with error code.
See "systemctl status yaIndStart.service" and "journalctl -xe" for details."
Some outputs:
sudo systemctl start yaIndStart.service output: "● yaIndStart.service - starts Yandex Disk Indicator when /media/kamensky/Data is
Loaded: loaded (/etc/systemd/system/yaIndStart.service; enabled; vendor prese
Active: failed (Result: exit-code) since Fri 2020-04-24 10:16:01 MSK; 24s ago
Process: 13280 ExecStart=/usr/local/bin/yaIndStart (code=exited, status=139)
Main PID: 13280 (code=exited, status=139)
апр 24 10:15:58 kamenskyhome systemd[1]: Starting starts Yandex Disk Indicator w
апр 24 10:15:58 kamenskyhome yaIndStart[13280]: Unable to init server: Could not
апр 24 10:15:58 kamenskyhome yaIndStart[13280]: Unable to init server: Could not
апр 24 10:16:01 kamenskyhome yaIndStart[13280]: Ошибка сегментирования (core dum
апр 24 10:16:01 kamenskyhome systemd[1]: yaIndStart.service: Main process exited
апр 24 10:16:01 kamenskyhome systemd[1]: yaIndStart.service: Failed with result
апр 24 10:16:01 kamenskyhome systemd[1]: Failed to start starts Yandex Disk Indi
lines 1-13/13 (END)...skipping...
● yaIndStart.service - starts Yandex Disk Indicator when /media/kamensky/Data is mounted
Loaded: loaded (/etc/systemd/system/yaIndStart.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-04-24 10:16:01 MSK; 24s ago
Process: 13280 ExecStart=/usr/local/bin/yaIndStart (code=exited, status=139)
Main PID: 13280 (code=exited, status=139)
апр 24 10:15:58 kamenskyhome systemd[1]: Starting starts Yandex Disk Indicator when /media/kamensky/Data is mounted...
апр 24 10:15:58 kamenskyhome yaIndStart[13280]: Unable to init server: Could not connect: Connection refused
апр 24 10:15:58 kamenskyhome yaIndStart[13280]: Unable to init server: Could not connect: Connection refused
апр 24 10:16:01 kamenskyhome yaIndStart[13280]: Ошибка сегментирования (core dumped)
апр 24 10:16:01 kamenskyhome systemd[1]: yaIndStart.service: Main process exited, code=exited, status=139/n/a
апр 24 10:16:01 kamenskyhome systemd[1]: yaIndStart.service: Failed with result 'exit-code'.
апр 24 10:16:01 kamenskyhome systemd[1]: Failed to start starts Yandex Disk Indicator when /media/kamensky/Data is mounted."
and journalctl -xe output:
"апр 24 10:15:59 kamenskyhome systemd[1]: Starting Process error reports when automatic reporting is enabled...
-- Subject: Начинается запуск юнита apport-autoreport.service
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- Начат процесс запуска юнита apport-autoreport.service.
апр 24 10:15:59 kamenskyhome whoopsie-upload-all[13295]: /var/crash/_usr_bin_nautilus.1000.crash already marked for upload, skipping
апр 24 10:15:59 kamenskyhome whoopsie-upload-all[13295]: /var/crash/_usr_bin_yandex-disk-indicator.1000.crash already marked for upload, skipping
апр 24 10:15:59 kamenskyhome whoopsie-upload-all[13295]: All reports processed
апр 24 10:15:59 kamenskyhome systemd[1]: Started Process error reports when automatic reporting is enabled.
-- Subject: Запуск юнита apport-autoreport.service завершен
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- Процесс запуска юнита apport-autoreport.service был завершен.
-- Результат: RESULT.
апр 24 10:16:01 kamenskyhome yaIndStart[13280]: Ошибка сегментирования (core dumped)
апр 24 10:16:01 kamenskyhome runuser[13281]: pam_unix(runuser-l:session): session closed for user kamensky
апр 24 10:16:01 kamenskyhome systemd[1]: yaIndStart.service: Main process exited, code=exited, status=139/n/a
апр 24 10:16:01 kamenskyhome systemd[1]: yaIndStart.service: Failed with result 'exit-code'.
апр 24 10:16:01 kamenskyhome systemd[1]: Failed to start starts Yandex Disk Indicator when /media/kamensky/Data is mounted.
-- Subject: Ошибка юнита yaIndStart.service
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- Произошел сбой юнита yaIndStart.service.
-- Результат: RESULT.
апр 24 10:16:01 kamenskyhome sudo[13277]: pam_unix(sudo:session): session closed for user root
апр 24 10:16:01 kamenskyhome systemd[1]: Starting Process error reports when automatic reporting is enabled...
-- Subject: Начинается запуск юнита apport-autoreport.service
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- Начат процесс запуска юнита apport-autoreport.service.
апр 24 10:16:01 kamenskyhome whoopsie-upload-all[13299]: /var/crash/_usr_bin_nautilus.1000.crash already marked for upload, skipping
апр 24 10:16:01 kamenskyhome whoopsie-upload-all[13299]: /var/crash/_usr_bin_yandex-disk-indicator.1000.crash already marked for upload, skipping
апр 24 10:16:01 kamenskyhome whoopsie-upload-all[13299]: All reports processed
апр 24 10:16:01 kamenskyhome systemd[1]: Started Process error reports when automatic reporting is enabled.
-- Subject: Запуск юнита apport-autoreport.service завершен
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- Процесс запуска юнита apport-autoreport.service был завершен.
-- Результат: RESULT.
апр 24 10:16:25 kamenskyhome sudo[13311]: kamensky : TTY=pts/0 ; PWD=/home/kamensky ; USER=root ; COMMAND=/bin/systemctl status yaIndStart.service
апр 24 10:16:25 kamenskyhome sudo[13311]: pam_unix(sudo:session): session opened for user root by (uid=0)
апр 24 10:17:01 kamenskyhome CRON[13322]: pam_unix(cron:session): session opened for user root by (uid=0)
апр 24 10:17:01 kamenskyhome CRON[13323]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
апр 24 10:17:01 kamenskyhome CRON[13322]: pam_unix(cron:session): session closed for user root
апр 24 10:17:45 kamenskyhome sudo[13311]: pam_unix(sudo:session): session closed for user root"
I know that's something I'm doing wrong-) Does anyone have an idea what exactly?
Please help-)
Comments
-
Please post your script. Impossible to ascertain what is wrong if we don't know what is in the script, because all the messages are telling you is that executing it failed Something which works at the command line is not guaranteed to work when it is run disconnected from a terminal; like where does the output go etc. Of what privilege level does it need etc.
0 -
Thanx for helping me-)
I've posted my script (actually I didn't found any instruments to highlight that ti is script),
but it is just: "#!/bin/bash /usr/bin/yandex-disk-indicator" for nykind of reason symbol "#" is not shown properly.0 -
Where do you expect to see the output? I think this is a graphical utility and you are trying to run it as a boot script. If you want something to run on your desktop systemd is not the way to do it, you do it with "autostart" configuration in gnome, as a startup program. Systemd and systemctl is for starting background services and daemons. So you are probably getting failure because there is no display to connect with. (SOrry I don't know yandex-disk-indicator, but it seems to be a GUI)
0 -
I can understand what are you talking about-) But this is a program to control cloud service. And it has an auto-start option, but at the time of start the disk drive, that contain path for synchronization is not mounted yet. So I decided to write systemd unit. There is an output of this "graphical utility" if it's needed:
"kamensky@kamenskyhome:~$ yandex-disk-indicator -l10
2020-04-24 19:16:10,944 INFO yandex-disk-indicator v.1.11.0
2020-04-24 19:16:10,944 DEBUG Logging level: 10
2020-04-24 19:16:10,947 DEBUG Config value read as: autostart = False
2020-04-24 19:16:10,947 DEBUG Config value read as: notifications = True
2020-04-24 19:16:10,947 DEBUG Config value read as: theme = False
2020-04-24 19:16:10,947 DEBUG Config value read as: fmextensions = True
2020-04-24 19:16:10,947 DEBUG Config value read as: daemons = /home/kamensky/.config/yandex-disk/config.cfg
2020-04-24 19:16:10,947 INFO Config read: /home/kamensky/.config/yd-tools/yandex-disk-indicator.conf
2020-04-24 19:16:11,010 DEBUG Config value read as: proxy = False
2020-04-24 19:16:11,010 DEBUG Config value read as: dir = /media/kamensky/Data/BackUpCloud
2020-04-24 19:16:11,010 DEBUG Config value read as: auth = /home/kamensky/.config/yandex-disk/passwd
2020-04-24 19:16:11,011 INFO Config read: /home/kamensky/.config/yandex-disk/config.cfg
2020-04-24 19:16:11,100 INFO Daemon is already started
2020-04-24 19:16:11,327 DEBUG Event raised by Timer
2020-04-24 19:16:11,327 INFO Change event: stat,size,last
2020-04-24 19:16:11,331 DEBUG Sub-menu 'Last synchronized' has 10 items
2020-04-24 19:16:11,332 INFO Status: unknown -> idle
"0 -
Hi @maxim221 ,
Is Yandex open source? If so, where can I find it, so I can take a look to it? I ask because it's not in the default Ubuntu repos.
Regards,
Luis.0 -
Yes. This part of product (Linux only) is opensource. Here is a gitHub link: https://github.com/slytomcat/yandex-disk-indicator
0 -
I've changed my script to:
"
!/usr/bin/python
import os
os.system("/usr/bin/yandex-disk-indicator")
"I was looking through yandex gitHub repo and managed to get that yandex indicator command waits for some kind of "python command" so I've changed bash to python in my script. "sudo systemctl start yaIndStart.service" working fine now, but I think that somthing still wrong with my systemd unit, because yandex still does not start.
"
kamensky@kamenskyhome:~$ sudo systemctl status yaIndStart.service
● yaIndStart.service - starts Yandex Disk Indicator when /media/kamensky/Data is mounted
Loaded: loaded (/etc/systemd/system/yaIndStart.service; enabled; vendor preset: enabled)
Active: active (exited) since Sat 2020-04-25 10:40:27 MSK; 2min 3s ago
Process: 863 ExecStart=/usr/local/bin/yaIndStart (code=exited, status=0/SUCCESS)
Main PID: 863 (code=exited, status=0/SUCCESS)апр 25 10:40:26 kamenskyhome systemd[1]: Starting starts Yandex Disk Indicator when /media/kamensky/Data is mounted...
апр 25 10:40:26 kamenskyhome yaIndStart[863]: Unable to init server: Could not connect: Connection refused
апр 25 10:40:26 kamenskyhome yaIndStart[863]: Unable to init server: Не удалось подключиться к: Connection refused
апр 25 10:40:27 kamenskyhome yaIndStart[863]: Traceback (most recent call last):
апр 25 10:40:27 kamenskyhome yaIndStart[863]: File "/usr/bin/yandex-disk-indicator", line 1308, in
апр 25 10:40:27 kamenskyhome yaIndStart[863]: configPath = pathJoin(getenv("HOME"), '.config', appHomeName)
апр 25 10:40:27 kamenskyhome yaIndStart[863]: File "/usr/lib/python3.6/posixpath.py", line 80, in join
апр 25 10:40:27 kamenskyhome yaIndStart[863]: a = os.fspath(a)
апр 25 10:40:27 kamenskyhome yaIndStart[863]: TypeError: expected str, bytes or os.PathLike object, not NoneType
апр 25 10:40:27 kamenskyhome systemd[1]: Started starts Yandex Disk Indicator when /media/kamensky/Data is mounted.
"But everything is ok if I run this script in terminal. I'm just typing : "yaIndStart" and it runs until I close term..
0 -
I'm sorry but neither of us is familiar with this program. Please pick a standard utility to start systemd with and we can help. As best I can tell you can get much if you cannot connect to a terminal. At least make your systemd job redirect output to a file that you can look at later to see what happens. Everything I read about this indicates it sets up a gui or something on your panel, which is impossible to do with systemd as a user has to be logged in for it to show and systemd runs before any user logs in.
1 -
thank U for help-)
0 -
But this is weird. TeamViewer, for example has it's systemd autostart service and it works fine..
0 -
I've made it another way-)
Modifying mount options of the disk solved my problem I've added "/dev/disk/by-id/wwn-0x50014ee2ae19e944 /mnt/wwn-0x50014ee2ae19e944 auto nosuid,nodev,nofail,x-gvfs-show 0 0" to my /etc/fstab where "wwn-0x50014ee2ae19e944" is an Id of my disk, known by "ls -la /dev/disk/by-id/" command. Thnx again.1 -
It's great to know you solved it!
Keep learning and enjoy it.
Regards,
Luis.0
Categories
- All Categories
- 167 LFX Mentorship
- 219 LFX Mentorship: Linux Kernel
- 795 Linux Foundation IT Professional Programs
- 355 Cloud Engineer IT Professional Program
- 179 Advanced Cloud Engineer IT Professional Program
- 82 DevOps Engineer IT Professional Program
- 127 Cloud Native Developer IT Professional Program
- 112 Express Training Courses
- 112 Express Courses - Discussion Forum
- 6.2K Training Courses
- 48 LFC110 Class Forum - Discontinued
- 17 LFC131 Class Forum
- 35 LFD102 Class Forum
- 227 LFD103 Class Forum
- 14 LFD110 Class Forum
- 39 LFD121 Class Forum
- 15 LFD133 Class Forum
- 7 LFD134 Class Forum
- 17 LFD137 Class Forum
- 63 LFD201 Class Forum
- 3 LFD210 Class Forum
- 5 LFD210-CN Class Forum
- 2 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum - Discontinued
- 1 LFD233 Class Forum
- 2 LFD237 Class Forum
- 23 LFD254 Class Forum
- 697 LFD259 Class Forum
- 109 LFD272 Class Forum
- 3 LFD272-JP クラス フォーラム
- 10 LFD273 Class Forum
- 152 LFS101 Class Forum
- 1 LFS111 Class Forum
- 1 LFS112 Class Forum
- 1 LFS116 Class Forum
- 1 LFS118 Class Forum
- LFS120 Class Forum
- 7 LFS142 Class Forum
- 7 LFS144 Class Forum
- 3 LFS145 Class Forum
- 1 LFS146 Class Forum
- 3 LFS147 Class Forum
- 1 LFS148 Class Forum
- 15 LFS151 Class Forum
- 1 LFS157 Class Forum
- 33 LFS158 Class Forum
- 8 LFS162 Class Forum
- 1 LFS166 Class Forum
- 1 LFS167 Class Forum
- 3 LFS170 Class Forum
- 2 LFS171 Class Forum
- 1 LFS178 Class Forum
- 1 LFS180 Class Forum
- 1 LFS182 Class Forum
- 1 LFS183 Class Forum
- 29 LFS200 Class Forum
- 736 LFS201 Class Forum - Discontinued
- 2 LFS201-JP クラス フォーラム
- 14 LFS203 Class Forum
- 102 LFS207 Class Forum
- 1 LFS207-DE-Klassenforum
- 1 LFS207-JP クラス フォーラム
- 301 LFS211 Class Forum
- 55 LFS216 Class Forum
- 48 LFS241 Class Forum
- 42 LFS242 Class Forum
- 37 LFS243 Class Forum
- 15 LFS244 Class Forum
- LFS245 Class Forum
- LFS246 Class Forum
- 50 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- LFS251 Class Forum
- 154 LFS253 Class Forum
- LFS254 Class Forum
- LFS255 Class Forum
- 5 LFS256 Class Forum
- 1 LFS257 Class Forum
- 1.3K LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 111 LFS260 Class Forum
- 159 LFS261 Class Forum
- 41 LFS262 Class Forum
- 82 LFS263 Class Forum - Discontinued
- 15 LFS264 Class Forum - Discontinued
- 11 LFS266 Class Forum - Discontinued
- 20 LFS267 Class Forum
- 24 LFS268 Class Forum
- 29 LFS269 Class Forum
- 1 LFS270 Class Forum
- 199 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- LFS274 Class Forum
- 3 LFS281 Class Forum
- 9 LFW111 Class Forum
- 261 LFW211 Class Forum
- 182 LFW212 Class Forum
- 13 SKF100 Class Forum
- 1 SKF200 Class Forum
- 1 SKF201 Class Forum
- 782 Hardware
- 198 Drivers
- 68 I/O Devices
- 37 Monitors
- 96 Multimedia
- 174 Networking
- 91 Printers & Scanners
- 83 Storage
- 743 Linux Distributions
- 80 Debian
- 67 Fedora
- 15 Linux Mint
- 13 Mageia
- 23 openSUSE
- 143 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 348 Ubuntu
- 461 Linux System Administration
- 39 Cloud Computing
- 70 Command Line/Scripting
- Github systems admin projects
- 90 Linux Security
- 77 Network Management
- 101 System Management
- 46 Web Management
- 64 Mobile Computing
- 17 Android
- 34 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 371 Off Topic
- 114 Introductions
- 174 Small Talk
- 19 Study Material
- 507 Programming and Development
- 285 Kernel Development
- 204 Software Development
- 1.8K Software
- 211 Applications
- 180 Command Line
- 3 Compiling/Installing
- 405 Games
- 309 Installation
- 97 All In Program
- 97 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)