/srv/irclogs.ubuntu.com/2008/02/22/#upstart.txt

keesjHi11:19
Keybukhey11:19
keesjI am playing with upstart. I am trying to implement a state machine for my system11:22
keesjI wonder if it makes sence :). the big idea would be to emit events from userland or the kernel and handle upon them in upstart11:23
keesjI have a 3 gui apps that will run (not at the same time)11:24
keesjI would like to be able to emit "high" level events "start_mass-storage-app" and translate that into  a few command (insmods perhaps) and starting a gui11:27
keesjcan I emit such event from within a job11:27
keesjsimply saying.. can I emit events from withing a jobs 11:28
Keybuksure11:36
keesjby calling initctl ? 11:38
Keybukright11:40
keesjthere is no "emit" command"11:41
Keybukthere is11:46
Keybukinitctl emit11:46
keesjthanks12:12
keesjI installed upstart in a different directory... I need to prefix the initctl command :(12:12
Keybukyou can make an "emit" command by just symlinking to initctl :p12:12
Keybukright12:12
Keybukfixing that is on the TODO12:13
keesjthat's nice12:13
keesjand would there be a way to store the current states so I can ask it again later? 12:21
Keybukhow do you mean?12:22
keesjjust like runlevels work ( that you can ask the current runlevel)12:23
Keybukstill not 100% following12:23
keesjI would like to keep some variable to implement my state12:23
keesjif (in_mass_storage) and usb unplugged -> rmmod ...12:24
keesjin_mass_storage would be a state12:24
keesjin the sample scripts "they" do         set $(runlevel --set 1 || true)12:26
keesjto determine if an event gets handled based on the previous runlevel (this is sample code named rc1)12:27
Keybukright, I'm kinda trying to get to that point12:28
Keybukwhere upstart has states that are true or false12:28
keesjyou are one of the developers, cool12:28
Keybukheh, the upstart developer12:29
keesjyo!12:29
keesjI am currently testing by using a qemu (I first tried a chroot ) but the apparently was not the best way to do things12:30
KeybukI just have it installed by default12:30
Keybukit replaces sysvinit well enough12:31
Keybukyou can carry on running the old init scripts while playing/developing12:31
keesjI am playing with it for mamona so it is an embedded platform (under arm)12:32
keesjdo you happen to know this package? http://smc.sourceforge.net/ (state machine compiler)12:33
KeybukI don't, no12:39
keesjI used it a lot to create state machines. but basicaly you need "previous_state" + event to implement this 12:41
Keybukright12:42
Keybukdepends what you want to do, really12:42
keesjthe "quick" hack would be to misues the initctl to tell init to change it's own "environement"12:43
keesjthanks for your time btw (I really apreaciate it)12:44
Keybukright, but I'm not sure I fully understand what you want to achieve12:44
keesjhmm . perhaps I am just thinking the wrong way around. let me try to give a simple example12:47
keesjmy system can have twoo states "video playback" and "mass storage". 12:51
keesjif somebody presses the power button while in mass storage I don't like that so I would like to ignore a "power" event when in storage mode. 12:52
keesjI was thinking in the line of creating a "button" event handler that listend to power_on power_off event12:53
keesjother events would be something like usb_connected (being a good reason to switch to mass storage)12:54
keesjI think I am taling about level events13:00
Keybukwhat other kinds of decision would you make based on these states though/13:00
keesjwhell I have a few of those event flying in (usb state changes, button presses, system update event) I was also thinking of using this state when going in "suspend" mode13:04
keesjso that when I wakeup I know what program to start again13:04
Keybukwhen suspending why do you need to stop programs?13:05
keesjgood questions :p13:06
keesjcurrenty I had to do it because I don't get events when in suspend , so if the device is in video mode , I suspend , and plug it to a computer , I miss the "connected" event13:09
keesj(just like udev meesd to cache the events generated by the kernel , I guess this is not the scop of upstart :p13:09
keesjI am getting there !13:13
Keybuknot entirely sure yet what the scope of upstart is ;)13:14
keesjhaha13:16
keesjthe code looks very clean13:17
keesjare you at fosdem?14:12
Keybukno14:20
KeybukI've never been to one of those14:23
Keybukhttp://upstart.ubuntu.com/wiki/RemoveEventArguments14:37
keesjI can be nice :op14:37
KeybukAny objection?  no?  good!  :o)14:37
keesjhaha14:39
keesjit14:39
keesjI really just should al be programmed in lua14:41
Keybukwhy?14:42
keesjI see plenty discussion about creating, "combined events" or other other structs that would be possible if upstart used a scripting language for the events definitions14:44
keesjbut the current aproach is also pretty clean i guess14:44
keesj>>from (tty-added or cua-added) and foo<< does that get interpreted every time an event would come?14:46
Keybukthe string? no14:52
Keybukit's compiled into a match tree in memory14:52
keesjhmm that you can not replace by lua :)14:53
Keybukwhat would lua gain though?14:53
keesjin this case nothing. but just like the current script  command you could script the behaviour (if an event is consummed by an handler)14:56
keesjmy system looks a little like the stoplight (the left image) http://smc.sourceforge.net/Images/SmcEx4_Stoplight.png I get the same type of events (like a timeout ). I see very whell how to perform the "start,turn light etc" . 15:04
keesjyou get the same "message" but want to perform something different(if you want me to stop just say so  , I am really trying to find a awy to do it)15:05
keesjI have put the different events in an event_handler that performs the few functions  15:06
keesjso I can not emit "switch_from_a_to_b"15:06
Keybukhmm15:08
Keybukcurrently Upstart's event matching is more functional than procedural15:08
Keybukie. you describe the state in which the job is running15:09
Keybukinside the job itself, you have a shell script, so it's procedural15:09
keesjYes , I Have the feeling I really am missing the point :p15:09
KeybukI'm not sure I've got the point ;)15:09
keesjAM I trying to misue the system?15:09
keesjmissue15:09
KeybukI'm not quite sure what you're trying to do yet15:09
keesjin a perfect work I would like to say "emit go_into_mass_storage" where ever you come from15:11
Keybukyou wouldn't use an event like that15:12
KeybukI'd define mass_storage as a state/job15:12
Keybukso "start mass_storage"15:12
keesjyes I have this part http://paste-it.net/659515:14
keesjso do I need to create a userland progress saying "emit stop_mass_storage" "emit start_video"15:15
keesjwith just the start/stop the system looks like /etc/init.d/mass_storage [start|stop]15:17
keesjor would start mass_storage stop video?15:18
keesjthe backwards compatible scripts use wmtp to "know" what the current runlevel is15:19
keesjI am getting there ... /initctl list15:29
keesjshows a list of active tasks, I can only have one state active at the time.....15:29
Keybukso you'd make your states start and stop each other?15:30
Keybukor be started and stopped by the same events15:30
keesjI will listen for event use the initctl to know the current state and react as supposed15:31
keesjI currently implemented it a separate jobs that are triggered by events (the switching between states) 15:32
keesjSo I guess the second option15:33
keesjperhaps I might even use the list to do sanity checks15:34
keesjI will try to hack a version and try to post it to the list15:53
Keybukshiny16:01
keesjI hope it wil work. (that there are no race cases...) 16:05
keesjit requires a state to keep running apparently a jobs that is started and exits is in a "stop" state again16:06
Keybuk(gdb) p *((EventOperator *)job->start_on->node->left)16:14
Keybuk$5 = {node = {parent = 0x662720, left = 0x0, right = 0x0}, type = EVENT_MATCH, 16:14
Keybuk  value = 0, name = 0x662670 "wibble=foo bar", env = 0x0, event = 0x0, 16:14
Keybuk  blocked = 0}16:14
Keybuk(gdb) p *((EventOperator *)job->start_on->node->right)16:14
Keybuk$6 = {node = {parent = 0x662720, left = 0x0, right = 0x0}, type = EVENT_MATCH, 16:14
Keybuk  value = 0, name = 0x6628a0 "wobble=foo bar", env = 0x0, event = 0x0, 16:14
Keybuk  blocked = 0}16:14
Keybuk(tangent:16:14
Keybuk damn I was on good form when I wrote this, I predicted I'd need something a year down the line)16:14
Keybukthat was from16:14
Keybuk"wibble=foo bar" or wobble="foo bar"16:15
Keybukso it handles quoting sensibly16:15
keesjcan I get the event name inside my scripts?16:21
keesjUPSTART_EVENT...16:22
Keybukright16:22
Keybuk$UPSTART_EVENTS in trunk16:22
keesjweek-end here. thanks a lot for the help!16:33
Keybukenjoy16:33
keesjthanks16:33
=== ion___ is now known as ion_

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!